[compiler-rt] r351711 - On Darwin allow for sanitizer malloc implementations to provide a zone
Dan Liew via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 20 17:41:01 PST 2019
Author: delcypher
Date: Sun Jan 20 17:41:01 2019
New Revision: 351711
URL: http://llvm.org/viewvc/llvm-project?rev=351711&view=rev
Log:
On Darwin allow for sanitizer malloc implementations to provide a zone
enumerator.
This is done by defining `COMMON_MALLOC_HAS_ZONE_ENUMERATOR` to `1` and
then by providing an implementation of the `mi_enumerator(...)` function.
If a custom implementation isn't desired the macro is set to `0` which
causes a stub version (that fails) to be used.
Currently all Darwin sanitizers that have malloc implementations define
this to be `0` so there is no functionality change.
rdar://problem/45284065
Modified:
compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
compiler-rt/trunk/lib/lsan/lsan_malloc_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc
compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc
Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=351711&r1=351710&r2=351711&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Sun Jan 20 17:41:01 2019
@@ -57,6 +57,7 @@ using namespace __asan;
GET_STACK_TRACE_FREE; \
ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
#define COMMON_MALLOC_NAMESPACE __asan
+#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
#include "sanitizer_common/sanitizer_malloc_mac.inc"
Modified: compiler-rt/trunk/lib/lsan/lsan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_malloc_mac.cc?rev=351711&r1=351710&r2=351711&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_malloc_mac.cc Sun Jan 20 17:41:01 2019
@@ -51,6 +51,7 @@ using namespace __lsan;
(void)zone_name; \
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
#define COMMON_MALLOC_NAMESPACE __lsan
+#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
#include "sanitizer_common/sanitizer_malloc_mac.inc"
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc?rev=351711&r1=351710&r2=351711&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc Sun Jan 20 17:41:01 2019
@@ -280,13 +280,28 @@ void __sanitizer_mz_free_definite_size(
}
#endif
-kern_return_t mi_enumerator(task_t task, void *,
- unsigned type_mask, vm_address_t zone_address,
- memory_reader_t reader,
+#ifndef COMMON_MALLOC_HAS_ZONE_ENUMERATOR
+#error "COMMON_MALLOC_HAS_ZONE_ENUMERATOR must be defined"
+#endif
+static_assert((COMMON_MALLOC_HAS_ZONE_ENUMERATOR) == 0 ||
+ (COMMON_MALLOC_HAS_ZONE_ENUMERATOR) == 1,
+ "COMMON_MALLOC_HAS_ZONE_ENUMERATOR must be 0 or 1");
+
+#if COMMON_MALLOC_HAS_ZONE_ENUMERATOR
+// Forward declare and expect the implementation to provided by
+// includer.
+kern_return_t mi_enumerator(task_t task, void *, unsigned type_mask,
+ vm_address_t zone_address, memory_reader_t reader,
+ vm_range_recorder_t recorder);
+#else
+// Provide stub implementation that fails.
+kern_return_t mi_enumerator(task_t task, void *, unsigned type_mask,
+ vm_address_t zone_address, memory_reader_t reader,
vm_range_recorder_t recorder) {
- // Should enumerate all the pointers we have. Seems like a lot of work.
+ // Not supported.
return KERN_FAILURE;
}
+#endif
size_t mi_good_size(malloc_zone_t *zone, size_t size) {
// I think it's always safe to return size, but we maybe could do better.
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc?rev=351711&r1=351710&r2=351711&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc Sun Jan 20 17:41:01 2019
@@ -63,6 +63,7 @@ using namespace __tsan;
(void)zone_name; \
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
#define COMMON_MALLOC_NAMESPACE __tsan
+#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
#include "sanitizer_common/sanitizer_malloc_mac.inc"
More information about the llvm-commits
mailing list