[llvm-commits] [compiler-rt] r173687 - [msan] A runtime call to support custom allocators.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jan 28 05:52:49 PST 2013


Author: eugenis
Date: Mon Jan 28 07:52:49 2013
New Revision: 173687

URL: http://llvm.org/viewvc/llvm-project?rev=173687&view=rev
Log:
[msan] A runtime call to support custom allocators.

Modified:
    compiler-rt/trunk/include/sanitizer/msan_interface.h
    compiler-rt/trunk/lib/msan/msan_interceptors.cc

Modified: compiler-rt/trunk/include/sanitizer/msan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/msan_interface.h?rev=173687&r1=173686&r2=173687&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/msan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/msan_interface.h Mon Jan 28 07:52:49 2013
@@ -117,6 +117,11 @@ const char *__msan_get_origin_descr_if_s
 SANITIZER_INTERFACE_ATTRIBUTE
 void __msan_partial_poison(void* data, void* shadow, uptr size);
 
+// Tell MSan about newly allocated memory (ex.: custom allocator).
+// Memory will be marked uninitialized, with origin at the call site.
+SANITIZER_INTERFACE_ATTRIBUTE
+void __msan_allocated_memory(void* data, uptr size);
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=173687&r1=173686&r2=173687&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Mon Jan 28 07:52:49 2013
@@ -20,6 +20,7 @@
 #include "msan_platform_limits_posix.h"
 #include "sanitizer_common/sanitizer_allocator.h"
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_stackdepot.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
 #include <stdarg.h>
@@ -710,6 +711,18 @@ INTERCEPTOR(void *, malloc, SIZE_T size)
   return MsanReallocate(&stack, 0, size, sizeof(u64), false);
 }
 
+void __msan_allocated_memory(void* data, uptr size) {
+  GET_MALLOC_STACK_TRACE;
+  if (flags()->poison_in_malloc)
+    __msan_poison(data, size);
+  if (__msan_get_track_origins()) {
+    u32 stack_id = StackDepotPut(stack.trace, stack.size);
+    CHECK(stack_id);
+    CHECK_EQ((stack_id >> 31), 0);  // Higher bit is occupied by stack origins.
+    __msan_set_origin(data, size, stack_id);
+  }
+}
+
 INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags,
             int fd, OFF_T offset) {
   ENSURE_MSAN_INITED();





More information about the llvm-commits mailing list