summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2019-01-21 01:41:08 +0000
committerDan Liew <dan@su-root.co.uk>2019-01-21 01:41:08 +0000
commit5a3857c9b24f61721be0f09cb5650209390f0da4 (patch)
treec187a4374bdb35d44d782896057f50a1b70932c7 /compiler-rt
parent4dd0bf94871ffde083ef7becc861ca7c8bbc9bc2 (diff)
downloadbcm5719-llvm-5a3857c9b24f61721be0f09cb5650209390f0da4.tar.gz
bcm5719-llvm-5a3857c9b24f61721be0f09cb5650209390f0da4.zip
On Darwin add allocator address and size fields to
`sanitizer_malloc_introspection_t` and initialize them to zero. We allow sanitizer implementations to perform different initialization by defining `COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT` to be `1` and providing an implementation of `mi_extra_init(...)`. We use these changes in future patches to implement malloc zone enumeration. rdar://problem/45284065 llvm-svn: 351712
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/asan/asan_malloc_mac.cc1
-rw-r--r--compiler-rt/lib/lsan/lsan_malloc_mac.cc1
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc25
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cc1
4 files changed, 28 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/asan_malloc_mac.cc b/compiler-rt/lib/asan/asan_malloc_mac.cc
index 00529624184..faa6c62dfce 100644
--- a/compiler-rt/lib/asan/asan_malloc_mac.cc
+++ b/compiler-rt/lib/asan/asan_malloc_mac.cc
@@ -58,6 +58,7 @@ using namespace __asan;
ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
#define COMMON_MALLOC_NAMESPACE __asan
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
+#define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0
#include "sanitizer_common/sanitizer_malloc_mac.inc"
diff --git a/compiler-rt/lib/lsan/lsan_malloc_mac.cc b/compiler-rt/lib/lsan/lsan_malloc_mac.cc
index 1d997bac735..34447b4b39f 100644
--- a/compiler-rt/lib/lsan/lsan_malloc_mac.cc
+++ b/compiler-rt/lib/lsan/lsan_malloc_mac.cc
@@ -52,6 +52,7 @@ using namespace __lsan;
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
#define COMMON_MALLOC_NAMESPACE __lsan
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
+#define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0
#include "sanitizer_common/sanitizer_malloc_mac.inc"
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc b/compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc
index 344daac07ae..3f3581eeb48 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc
@@ -39,6 +39,8 @@ struct sanitizer_malloc_introspection_t : public malloc_introspection_t {
// Used to track changes to the allocator that will affect
// zone enumeration.
u64 allocator_enumeration_version;
+ uptr allocator_ptr;
+ uptr allocator_size;
};
u64 GetMallocZoneAllocatorEnumerationVersion() {
@@ -303,6 +305,26 @@ kern_return_t mi_enumerator(task_t task, void *, unsigned type_mask,
}
#endif
+#ifndef COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT
+#error "COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT must be defined"
+#endif
+static_assert((COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT) == 0 ||
+ (COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT) == 1,
+ "COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT must be 0 or 1");
+#if COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT
+// Forward declare and expect the implementation to provided by
+// includer.
+void mi_extra_init(
+ sanitizer_malloc_introspection_t *mi);
+#else
+void mi_extra_init(
+ sanitizer_malloc_introspection_t *mi) {
+ // Just zero initialize the fields.
+ mi->allocator_ptr = 0;
+ mi->allocator_size = 0;
+}
+#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.
return size;
@@ -361,6 +383,9 @@ void InitMallocZoneFields() {
sanitizer_zone_introspection.allocator_enumeration_version =
GetMallocZoneAllocatorEnumerationVersion();
+ // Perform any sanitizer specific initialization.
+ mi_extra_init(&sanitizer_zone_introspection);
+
internal_memset(&sanitizer_zone, 0, sizeof(malloc_zone_t));
// Use version 6 for OSX >= 10.6.
diff --git a/compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cc
index 26bb856ca5c..9b32399fd13 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cc
@@ -64,6 +64,7 @@ using namespace __tsan;
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
#define COMMON_MALLOC_NAMESPACE __tsan
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
+#define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0
#include "sanitizer_common/sanitizer_malloc_mac.inc"
OpenPOWER on IntegriCloud