[compiler-rt] r351712 - On Darwin add allocator address and size fields to
Dan Liew via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 20 17:41:08 PST 2019
Author: delcypher
Date: Sun Jan 20 17:41:08 2019
New Revision: 351712
URL: http://llvm.org/viewvc/llvm-project?rev=351712&view=rev
Log:
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
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=351712&r1=351711&r2=351712&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:08 2019
@@ -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"
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=351712&r1=351711&r2=351712&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:08 2019
@@ -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"
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=351712&r1=351711&r2=351712&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:08 2019
@@ -39,6 +39,8 @@ struct sanitizer_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,
}
#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.
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=351712&r1=351711&r2=351712&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:08 2019
@@ -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"
More information about the llvm-commits
mailing list