summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_malloc_mac.inc
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2016-12-11 08:42:42 +0000
committerKuba Mracek <mracek@apple.com>2016-12-11 08:42:42 +0000
commitc5c177c46ef58a61f03ebc18e7cfd231db97ea1c (patch)
tree9148845bcc5064c7fd9f573c143a72f779fd633d /lib/sanitizer_common/sanitizer_malloc_mac.inc
parent4c944cba096f7a4d5033002ed46854e3b74d2cff (diff)
downloadcompiler-rt-c5c177c46ef58a61f03ebc18e7cfd231db97ea1c.tar.gz
[sanitizer] Handle malloc_destroy_zone() on Darwin
We currently have a interceptor for malloc_create_zone, which returns a new zone that redirects all the zone requests to our sanitizer zone. However, calling malloc_destroy_zone on that zone will cause libmalloc to print out some warning messages, because the zone is not registered in the list of zones. This patch handles this and adds a testcase for that. Differential Revision: https://reviews.llvm.org/D27083 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289375 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_malloc_mac.inc')
-rw-r--r--lib/sanitizer_common/sanitizer_malloc_mac.inc13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_malloc_mac.inc b/lib/sanitizer_common/sanitizer_malloc_mac.inc
index 149857c16..caf753ad2 100644
--- a/lib/sanitizer_common/sanitizer_malloc_mac.inc
+++ b/lib/sanitizer_common/sanitizer_malloc_mac.inc
@@ -46,9 +46,22 @@ INTERCEPTOR(malloc_zone_t *, malloc_create_zone,
// This matches the behavior of malloc_create_zone() on OSX 10.7 and higher.
mprotect(new_zone, allocated_size, PROT_READ);
}
+ // We're explicitly *NOT* registering the zone.
return new_zone;
}
+INTERCEPTOR(void, malloc_destroy_zone, malloc_zone_t *zone) {
+ COMMON_MALLOC_ENTER();
+ // We don't need to do anything here. We're not registering new zones, so we
+ // don't to unregister. Just un-mprotect and free() the zone.
+ if (GetMacosVersion() >= MACOS_VERSION_LION) {
+ uptr page_size = GetPageSizeCached();
+ uptr allocated_size = RoundUpTo(sizeof(sanitizer_zone), page_size);
+ mprotect(zone, allocated_size, PROT_READ | PROT_WRITE);
+ }
+ COMMON_MALLOC_FREE(zone);
+}
+
INTERCEPTOR(malloc_zone_t *, malloc_default_zone, void) {
COMMON_MALLOC_ENTER();
return &sanitizer_zone;