[PATCH] D56993: Refactor `GetAsanChunk()` method so it can be used in an in-process and out-of-process context.
Dan Liew via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 20 17:53:24 PST 2019
delcypher created this revision.
delcypher added reviewers: kcc, vitalybuka, dvyukov, cryptoad, eugenis, george.karpenkov, yln, kubamracek.
Herald added a subscriber: Sanitizers.
delcypher added a parent revision: D56968: Refactor `AsanChunk` methods into code that supports both in-process and out-of-process examination of `AsanChunk`s..
Refactor `GetAsanChunk()` method so it can be used in an in-process and out-of-process context.
rdar://problem/45284065
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D56993
Files:
lib/asan/asan_allocator.cc
Index: lib/asan/asan_allocator.cc
===================================================================
--- lib/asan/asan_allocator.cc
+++ lib/asan/asan_allocator.cc
@@ -291,6 +291,35 @@
cf->allocator_release_to_os_interval_ms = release_to_os_interval_ms;
}
+// Returns a pointer to the `AsanChunk` in the target process.
+//
+// `alloc_beg` - Pointer to the beginning of the allocation in the target
+// process, i.e.
+// `allocator_view.GetBlockBegin(alloc_beg) == alloc_beg`.
+//
+// `allocator` - Pointer to the allocator in the local process.
+template <typename AddressSpaceView>
+static AsanChunk *GetAsanChunkInternal(uptr alloc_beg, uptr allocator) {
+ if (!alloc_beg)
+ return nullptr;
+ auto allocator_view =
+ reinterpret_cast<AsanAllocatorASVT<AddressSpaceView> *>(allocator);
+
+ if (!allocator_view->FromPrimary(reinterpret_cast<void *>(alloc_beg))) {
+ const uptr *meta = AddressSpaceView::Load(
+ reinterpret_cast<uptr *>(
+ allocator_view->GetMetaData(reinterpret_cast<void *>(alloc_beg))),
+ 2);
+ AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
+ return m;
+ }
+ const uptr *alloc_magic =
+ AddressSpaceView::Load(reinterpret_cast<uptr *>(alloc_beg), 2);
+ if (alloc_magic[0] == kAllocBegMagic)
+ return reinterpret_cast<AsanChunk *>(alloc_magic[1]);
+ return reinterpret_cast<AsanChunk *>(alloc_beg);
+}
+
struct Allocator {
static const uptr kMaxAllowedMallocSize =
FIRST_32_SECOND_64(3UL << 30, 1ULL << 40);
@@ -758,16 +787,8 @@
// Assumes alloc_beg == allocator.GetBlockBegin(alloc_beg).
AsanChunk *GetAsanChunk(void *alloc_beg) {
- if (!alloc_beg) return nullptr;
- if (!allocator.FromPrimary(alloc_beg)) {
- uptr *meta = reinterpret_cast<uptr *>(allocator.GetMetaData(alloc_beg));
- AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
- return m;
- }
- uptr *alloc_magic = reinterpret_cast<uptr *>(alloc_beg);
- if (alloc_magic[0] == kAllocBegMagic)
- return reinterpret_cast<AsanChunk *>(alloc_magic[1]);
- return reinterpret_cast<AsanChunk *>(alloc_beg);
+ return GetAsanChunkInternal<LocalAddressSpaceView>(
+ reinterpret_cast<uptr>(alloc_beg), reinterpret_cast<uptr>(&allocator));
}
AsanChunk *GetAsanChunkByAddr(uptr p) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56993.182734.patch
Type: text/x-patch
Size: 2327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190121/4a96e3c5/attachment.bin>
More information about the llvm-commits
mailing list