[compiler-rt] r216459 - [lsan] Implement the public allocator interface in standalone LSan.
Sergey Matveev
earthdok at google.com
Tue Aug 26 07:28:29 PDT 2014
Author: smatveev
Date: Tue Aug 26 09:28:28 2014
New Revision: 216459
URL: http://llvm.org/viewvc/llvm-project?rev=216459&view=rev
Log:
[lsan] Implement the public allocator interface in standalone LSan.
Modified:
compiler-rt/trunk/lib/lsan/lsan_allocator.cc
compiler-rt/trunk/lib/lsan/lsan_allocator.h
compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc
Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=216459&r1=216458&r2=216459&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Tue Aug 26 09:28:28 2014
@@ -15,6 +15,7 @@
#include "lsan_allocator.h"
#include "sanitizer_common/sanitizer_allocator.h"
+#include "sanitizer_common/sanitizer_allocator_interface.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
@@ -53,7 +54,7 @@ void AllocatorThreadFinish() {
allocator.SwallowCache(&cache);
}
-static ChunkMetadata *Metadata(void *p) {
+static ChunkMetadata *Metadata(const void *p) {
return reinterpret_cast<ChunkMetadata *>(allocator.GetMetaData(p));
}
@@ -87,10 +88,12 @@ void *Allocate(const StackTrace &stack,
if (cleared && allocator.FromPrimary(p))
memset(p, 0, size);
RegisterAllocation(stack, p, size);
+ if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(p, size);
return p;
}
void Deallocate(void *p) {
+ if (&__sanitizer_free_hook) __sanitizer_free_hook(p);
RegisterDeallocation(p);
allocator.Deallocate(&cache, p);
}
@@ -113,7 +116,7 @@ void GetAllocatorCacheRange(uptr *begin,
*end = *begin + sizeof(cache);
}
-uptr GetMallocUsableSize(void *p) {
+uptr GetMallocUsableSize(const void *p) {
ChunkMetadata *m = Metadata(p);
if (!m) return 0;
return m->requested_size;
@@ -200,3 +203,38 @@ IgnoreObjectResult IgnoreObjectLocked(co
}
}
} // namespace __lsan
+
+using namespace __lsan;
+
+extern "C" {
+SANITIZER_INTERFACE_ATTRIBUTE
+uptr __sanitizer_get_current_allocated_bytes() {
+ uptr stats[AllocatorStatCount];
+ allocator.GetStats(stats);
+ return stats[AllocatorStatAllocated];
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE
+uptr __sanitizer_get_heap_size() {
+ uptr stats[AllocatorStatCount];
+ allocator.GetStats(stats);
+ return stats[AllocatorStatMapped];
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE
+uptr __sanitizer_get_free_bytes() { return 0; }
+
+SANITIZER_INTERFACE_ATTRIBUTE
+uptr __sanitizer_get_unmapped_bytes() { return 0; }
+
+SANITIZER_INTERFACE_ATTRIBUTE
+uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
+
+SANITIZER_INTERFACE_ATTRIBUTE
+int __sanitizer_get_ownership(const void *p) { return Metadata(p) != 0; }
+
+SANITIZER_INTERFACE_ATTRIBUTE
+uptr __sanitizer_get_allocated_size(const void *p) {
+ return GetMallocUsableSize(p);
+}
+} // extern "C"
Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.h?rev=216459&r1=216458&r2=216459&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_allocator.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.h Tue Aug 26 09:28:28 2014
@@ -25,7 +25,7 @@ void *Allocate(const StackTrace &stack,
void Deallocate(void *p);
void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
uptr alignment);
-uptr GetMallocUsableSize(void *p);
+uptr GetMallocUsableSize(const void *p);
template<typename Callable>
void ForEachChunk(const Callable &callback);
Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc?rev=216459&r1=216458&r2=216459&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc Tue Aug 26 09:28:28 2014
@@ -1,7 +1,7 @@
// RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
-// Malloc/free hooks are not supported on Windows and doesn't work in LSan.
-// XFAIL: win32, lsan
+// Malloc/free hooks are not supported on Windows.
+// XFAIL: win32
#include <stdlib.h>
#include <unistd.h>
More information about the llvm-commits
mailing list