[PATCH] D27083: [sanitizer] Handle malloc_destroy_zone() on Darwin
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 11 13:49:11 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289375: [sanitizer] Handle malloc_destroy_zone() on Darwin (authored by kuba.brecka).
Changed prior to commit:
https://reviews.llvm.org/D27083?vs=80296&id=81032#toc
Repository:
rL LLVM
https://reviews.llvm.org/D27083
Files:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc
compiler-rt/trunk/test/asan/TestCases/Darwin/malloc_destroy_zone.cc
Index: compiler-rt/trunk/test/asan/TestCases/Darwin/malloc_destroy_zone.cc
===================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/malloc_destroy_zone.cc
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/malloc_destroy_zone.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_asan %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <malloc/malloc.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main() {
+ fprintf(stderr, "start\n");
+ malloc_zone_t *zone = malloc_create_zone(0, 0);
+ fprintf(stderr, "zone = %p\n", zone);
+ malloc_set_zone_name(zone, "myzone");
+ fprintf(stderr, "name changed\n");
+ malloc_destroy_zone(zone);
+ fprintf(stderr, "done\n");
+ return 0;
+}
+
+// CHECK: start
+// CHECK-NEXT: zone = 0x{{.*}}
+// CHECK-NEXT: name changed
+// CHECK-NEXT: done
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_malloc_mac.inc
@@ -46,9 +46,22 @@
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27083.81032.patch
Type: text/x-patch
Size: 1956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161211/cee60a61/attachment.bin>
More information about the llvm-commits
mailing list