[compiler-rt] r204926 - [msan] Implement __msan_set_death_callback.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu Mar 27 07:04:59 PDT 2014
Author: eugenis
Date: Thu Mar 27 09:04:58 2014
New Revision: 204926
URL: http://llvm.org/viewvc/llvm-project?rev=204926&view=rev
Log:
[msan] Implement __msan_set_death_callback.
Added:
compiler-rt/trunk/test/msan/death-callback.cc (with props)
Modified:
compiler-rt/trunk/include/sanitizer/msan_interface.h
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/msan/msan.h
compiler-rt/trunk/lib/msan/msan_interface_internal.h
compiler-rt/trunk/lib/msan/msan_linux.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=204926&r1=204925&r2=204926&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/msan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/msan_interface.h Thu Mar 27 09:04:58 2014
@@ -89,6 +89,9 @@ extern "C" {
a string containing Msan runtime options. See msan_flags.h for details. */
const char* __msan_default_options();
+ // Sets the callback to be called right before death on error.
+ // Passing 0 will unset the callback.
+ void __msan_set_death_callback(void (*callback)(void));
/***********************************/
/* Allocator statistics interface. */
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=204926&r1=204925&r2=204926&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Thu Mar 27 09:04:58 2014
@@ -97,6 +97,8 @@ bool msan_init_is_running;
int msan_report_count = 0;
+void (*death_callback)(void);
+
// Array of stack origins.
// FIXME: make it resizable.
static const uptr kNumStackOriginDescrs = 1024 * 1024;
@@ -542,6 +544,10 @@ void __sanitizer_unaligned_store64(uu64
*p = x;
}
+void __msan_set_death_callback(void (*callback)(void)) {
+ death_callback = callback;
+}
+
void *__msan_wrap_indirect_call(void *target) {
return IndirectExternCall(target);
}
Modified: compiler-rt/trunk/lib/msan/msan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=204926&r1=204925&r2=204926&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.h (original)
+++ compiler-rt/trunk/lib/msan/msan.h Thu Mar 27 09:04:58 2014
@@ -121,6 +121,9 @@ class ScopedThreadLocalStateBackup {
private:
u64 va_arg_overflow_size_tls;
};
+
+extern void (*death_callback)(void);
+
} // namespace __msan
#define MSAN_MALLOC_HOOK(ptr, size) \
Modified: compiler-rt/trunk/lib/msan/msan_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=204926&r1=204925&r2=204926&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (original)
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Thu Mar 27 09:04:58 2014
@@ -177,6 +177,9 @@ void *__msan_wrap_indirect_call(void *ta
SANITIZER_INTERFACE_ATTRIBUTE
void __msan_set_indirect_call_wrapper(uptr wrapper);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+void __msan_set_death_callback(void (*callback)(void));
} // extern "C"
#endif // MSAN_INTERFACE_INTERNAL_H
Modified: compiler-rt/trunk/lib/msan/msan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_linux.cc?rev=204926&r1=204925&r2=204926&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_linux.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_linux.cc Thu Mar 27 09:04:58 2014
@@ -80,6 +80,8 @@ bool InitShadow(bool prot1, bool prot2,
}
void MsanDie() {
+ if (death_callback)
+ death_callback();
_exit(flags()->exit_code);
}
Added: compiler-rt/trunk/test/msan/death-callback.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/death-callback.cc?rev=204926&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/death-callback.cc (added)
+++ compiler-rt/trunk/test/msan/death-callback.cc Thu Mar 27 09:04:58 2014
@@ -0,0 +1,39 @@
+// RUN: %clangxx_msan -m64 -DERROR %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB
+// RUN: %clangxx_msan -m64 -DERROR -DMSANCB_SET %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CB
+// RUN: %clangxx_msan -m64 -DERROR -DMSANCB_SET -DMSANCB_CLEAR %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB
+// RUN: %clangxx_msan -m64 -DMSANCB_SET %s -o %t && %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB
+
+#include <sanitizer/msan_interface.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void cb(void) {
+ fprintf(stderr, "msan-death-callback\n");
+}
+
+int main(int argc, char **argv) {
+ int *volatile p = (int *)malloc(sizeof(int));
+ *p = 42;
+ free(p);
+
+#ifdef MSANCB_SET
+ __msan_set_death_callback(cb);
+#endif
+
+#ifdef MSANCB_CLEAR
+ __msan_set_death_callback(0);
+#endif
+
+#ifdef ERROR
+ if (*p)
+ exit(0);
+#endif
+ // CHECK-CB: msan-death-callback
+ // CHECK-NOCB-NOT: msan-death-callback
+ fprintf(stderr, "done\n");
+ return 0;
+}
Propchange: compiler-rt/trunk/test/msan/death-callback.cc
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the llvm-commits
mailing list