summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_malloc_mac.inc
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2019-01-21 01:41:01 +0000
committerDan Liew <dan@su-root.co.uk>2019-01-21 01:41:01 +0000
commit5afabe80eb2232e364dbf6c709d56f8c42c69d17 (patch)
tree1d8b300a4d80915ba7d158f6b697a35f3e37aec2 /lib/sanitizer_common/sanitizer_malloc_mac.inc
parentcad2d7941c969ae16043735c02a0f8ebd556b51c (diff)
downloadcompiler-rt-5afabe80eb2232e364dbf6c709d56f8c42c69d17.tar.gz
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@351711 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_malloc_mac.inc')
-rw-r--r--lib/sanitizer_common/sanitizer_malloc_mac.inc23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/sanitizer_common/sanitizer_malloc_mac.inc b/lib/sanitizer_common/sanitizer_malloc_mac.inc
index d3b34caf5..344daac07 100644
--- a/lib/sanitizer_common/sanitizer_malloc_mac.inc
+++ b/lib/sanitizer_common/sanitizer_malloc_mac.inc
@@ -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.