summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-06-09 09:21:44 +0000
committerAlexey Samsonov <samsonov@google.com>2012-06-09 09:21:44 +0000
commit718acdbd6427a2f2af3bb8da8220455066cae8ce (patch)
treee0f716b259e1efb06ec28511493effa7fddf4419 /lib/sanitizer_common/sanitizer_allocator.cc
parent98c8780c22685af63c57ce5312a9ed730ee3408d (diff)
[Sanitizer] Use __libc_malloc/__libc_free instead of malloc/free inside internal allocator on Linux (important for TSan)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158261 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_allocator.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator.cc b/lib/sanitizer_common/sanitizer_allocator.cc
index 4b85b43b7..b6134c68a 100644
--- a/lib/sanitizer_common/sanitizer_allocator.cc
+++ b/lib/sanitizer_common/sanitizer_allocator.cc
@@ -15,14 +15,23 @@
// FIXME: We should probably use more low-level allocator that would
// mmap some pages and split them into chunks to fulfill requests.
-#include <stdlib.h>
+#ifdef __linux__
+extern "C" void *__libc_malloc(__sanitizer::uptr size);
+extern "C" void __libc_free(void *ptr);
+# define LIBC_MALLOC __libc_malloc
+# define LIBC_FREE __libc_free
+#else // __linux__
+# include <stdlib.h>
+# define LIBC_MALLOC malloc
+# define LIBC_FREE free
+#endif // __linux__
namespace __sanitizer {
static const u64 kInternalAllocBlockMagic = 0x7A6CB03ABCEBC042ull;
void *InternalAlloc(uptr size) {
- void *p = malloc(size + sizeof(u64));
+ void *p = LIBC_MALLOC(size + sizeof(u64));
((u64*)p)[0] = kInternalAllocBlockMagic;
return (char*)p + sizeof(u64);
}
@@ -32,7 +41,7 @@ void InternalFree(void *addr) {
addr = (char*)addr - sizeof(u64);
CHECK_EQ(((u64*)addr)[0], kInternalAllocBlockMagic);
((u64*)addr)[0] = 0;
- free(addr);
+ LIBC_FREE(addr);
}
} // namespace __sanitizer