forked from OSchip/llvm-project
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 llvm-svn: 351711
This commit is contained in:
parent
9c178356e0
commit
4dd0bf9487
|
@ -57,6 +57,7 @@ using namespace __asan;
|
||||||
GET_STACK_TRACE_FREE; \
|
GET_STACK_TRACE_FREE; \
|
||||||
ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
|
ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
|
||||||
#define COMMON_MALLOC_NAMESPACE __asan
|
#define COMMON_MALLOC_NAMESPACE __asan
|
||||||
|
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
|
||||||
|
|
||||||
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ using namespace __lsan;
|
||||||
(void)zone_name; \
|
(void)zone_name; \
|
||||||
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
|
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
|
||||||
#define COMMON_MALLOC_NAMESPACE __lsan
|
#define COMMON_MALLOC_NAMESPACE __lsan
|
||||||
|
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
|
||||||
|
|
||||||
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
||||||
|
|
||||||
|
|
|
@ -280,13 +280,28 @@ void __sanitizer_mz_free_definite_size(
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
kern_return_t mi_enumerator(task_t task, void *,
|
#ifndef COMMON_MALLOC_HAS_ZONE_ENUMERATOR
|
||||||
unsigned type_mask, vm_address_t zone_address,
|
#error "COMMON_MALLOC_HAS_ZONE_ENUMERATOR must be defined"
|
||||||
memory_reader_t reader,
|
#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) {
|
vm_range_recorder_t recorder) {
|
||||||
// Should enumerate all the pointers we have. Seems like a lot of work.
|
// Not supported.
|
||||||
return KERN_FAILURE;
|
return KERN_FAILURE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
size_t mi_good_size(malloc_zone_t *zone, size_t size) {
|
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.
|
// I think it's always safe to return size, but we maybe could do better.
|
||||||
|
|
|
@ -63,6 +63,7 @@ using namespace __tsan;
|
||||||
(void)zone_name; \
|
(void)zone_name; \
|
||||||
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
|
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
|
||||||
#define COMMON_MALLOC_NAMESPACE __tsan
|
#define COMMON_MALLOC_NAMESPACE __tsan
|
||||||
|
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
|
||||||
|
|
||||||
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue