mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-28 12:30:22 +00:00
[msan] Implement __msan_set_death_callback.
llvm-svn: 204926
This commit is contained in:
parent
e6303d1224
commit
89602651e8
@ -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. */
|
||||
|
@ -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, u64 x) {
|
||||
*p = x;
|
||||
}
|
||||
|
||||
void __msan_set_death_callback(void (*callback)(void)) {
|
||||
death_callback = callback;
|
||||
}
|
||||
|
||||
void *__msan_wrap_indirect_call(void *target) {
|
||||
return IndirectExternCall(target);
|
||||
}
|
||||
|
@ -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) \
|
||||
|
@ -177,6 +177,9 @@ void *__msan_wrap_indirect_call(void *target);
|
||||
|
||||
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
|
||||
|
@ -80,6 +80,8 @@ bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) {
|
||||
}
|
||||
|
||||
void MsanDie() {
|
||||
if (death_callback)
|
||||
death_callback();
|
||||
_exit(flags()->exit_code);
|
||||
}
|
||||
|
||||
|
39
compiler-rt/test/msan/death-callback.cc
Normal file
39
compiler-rt/test/msan/death-callback.cc
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user