[compiler-rt] r264259 - [tsan] Use direct syscalls for internal_mmap and internal_munmap on OS X
Kuba Brecka via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 24 04:50:21 PDT 2016
Author: kuba.brecka
Date: Thu Mar 24 06:50:21 2016
New Revision: 264259
URL: http://llvm.org/viewvc/llvm-project?rev=264259&view=rev
Log:
[tsan] Use direct syscalls for internal_mmap and internal_munmap on OS X
On OS X, internal_mmap just uses mmap, which can invoke callbacks into libmalloc (e.g. when MallocStackLogging is enabled). This can subsequently call other intercepted functions, and this breaks our Darwin-specific ThreadState initialization. Let's use direct syscalls in internal_mmap and internal_munmap. Added a testcase.
Differential Revision: http://reviews.llvm.org/D18431
Added:
compiler-rt/trunk/test/tsan/Darwin/malloc-stack-logging.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=264259&r1=264258&r2=264259&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Thu Mar 24 06:50:21 2016
@@ -82,15 +82,20 @@ namespace __sanitizer {
#include "sanitizer_syscall_generic.inc"
+// Direct syscalls, don't call libmalloc hooks.
+extern "C" void *__mmap(void *addr, size_t len, int prot, int flags, int fildes,
+ off_t off);
+extern "C" int __munmap(void *, size_t);
+
// ---------------------- sanitizer_libc.h
uptr internal_mmap(void *addr, size_t length, int prot, int flags,
int fd, u64 offset) {
if (fd == -1) fd = VM_MAKE_TAG(VM_MEMORY_ANALYSIS_TOOL);
- return (uptr)mmap(addr, length, prot, flags, fd, offset);
+ return (uptr)__mmap(addr, length, prot, flags, fd, offset);
}
uptr internal_munmap(void *addr, uptr length) {
- return munmap(addr, length);
+ return __munmap(addr, length);
}
int internal_mprotect(void *addr, uptr length, int prot) {
Added: compiler-rt/trunk/test/tsan/Darwin/malloc-stack-logging.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/malloc-stack-logging.cc?rev=264259&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/malloc-stack-logging.cc (added)
+++ compiler-rt/trunk/test/tsan/Darwin/malloc-stack-logging.cc Thu Mar 24 06:50:21 2016
@@ -0,0 +1,19 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// RUN: MallocStackLogging=1 %run %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *foo(void *p) {
+ return NULL;
+}
+
+int main() {
+ pthread_t t;
+ pthread_create(&t, NULL, foo, NULL);
+ pthread_join(t, NULL);
+ fprintf(stderr, "Done.\n");
+ return 0;
+}
+
+// CHECK: Done.
More information about the llvm-commits
mailing list