[PATCH] D50330: [RFC] Implement out-of-process allocator enumeration for macOS

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 6 06:10:30 PDT 2018


delcypher created this revision.
delcypher added reviewers: kubamracek, kcc, dvyukov, vitalybuka, cryptoad, alekseyshl.
Herald added subscribers: Sanitizers, mgorny.

Start adding code to the allocators to allow their allocations to be
enumerated "out-of-process".

On macOS, the memory allocator system allows different allocator
implementations ("zones"), and each zone provides a
malloc/realloc/free-like interface. The allocator of sanitizers is
implemented as a zone on macOS. An optional, but important part of this
interface is "zone enumeration", which is what's behind several
debugging/profiling tools like `heap` (inspection of heap content, group
chunks by size and type), `vmmap` (besides other things shows heap
utilization and fragmentation), `leaks` (finds leaks, even on a
debugger-paused process), and some others. Zone enumeration was never
implemented for ASan and the other sanitizers, and therefore none of
these tools work on *Sanified processes.

This work is part of a multi patch series to implement a malloc zone
enumerator on macOS. Initially the malloc zone enumeration will be
implemented for ASanified processes, and support for other sanitizers
will be left as future work.

In order to implement this a first step is to allow the sanitizer
allocators to be enumerated out-of-process. This is what this
patch focuses on. Other necessary parts will be implemented in
later patches.

For allocator enumeration we follow LSan's existing API design but add
out-of-process variants of the functions. The `ForEachChunkOutOfProcess`
functions mirror their in-process counter parts. These functions
take a pointer to a `ProcessVMReaderContext` object.

The `ProcessVMReaderContext` class is an abstraction around Darwin's
interface for reading memory from a target process. Stub implementations
are provided for other platforms which allows the class to operate when
the target and analysis process are the same. This allows the
out-of-process enuemration code to be compiled and partially tested on
all platforms.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D50330

Files:
  lib/asan/asan_allocator.cc
  lib/lsan/lsan_common.h
  lib/sanitizer_common/CMakeLists.txt
  lib/sanitizer_common/sanitizer_allocator.h
  lib/sanitizer_common/sanitizer_allocator_combined.h
  lib/sanitizer_common/sanitizer_allocator_primary32.h
  lib/sanitizer_common/sanitizer_allocator_primary64.h
  lib/sanitizer_common/sanitizer_allocator_secondary.h
  lib/sanitizer_common/sanitizer_process_vm_reader.h
  lib/sanitizer_common/sanitizer_process_vm_reader_common.cc
  lib/sanitizer_common/sanitizer_process_vm_reader_mac.cc
  lib/sanitizer_common/sanitizer_process_vm_reader_stubs.cc
  lib/sanitizer_common/tests/sanitizer_allocator_test.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50330.159284.patch
Type: text/x-patch
Size: 26531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180806/e640c2e8/attachment.bin>


More information about the llvm-commits mailing list