Index: lib/lsan/lsan_interceptors.cc =================================================================== --- lib/lsan/lsan_interceptors.cc +++ lib/lsan/lsan_interceptors.cc @@ -185,6 +185,29 @@ #define LSAN_MAYBE_INTERCEPT_CFREE #endif // SANITIZER_INTERCEPT_CFREE +#if SANITIZER_INTERCEPT_MCHECK_MPROBE +enum mcheck_status { + MCHECK_DISABLED = -1, // Consistency checking is not turned on. + MCHECK_OK, // Block is fine. + MCHECK_FREE, // Block freed twice. + MCHECK_HEAD, // Memory before the block was clobbered. + MCHECK_TAIL // Memory after the block was clobbered. +}; + +INTERCEPTOR(int, mcheck, void (*abortfunc)(enum mcheck_status mstatus)) { + return 0; +} + +INTERCEPTOR(int, mprobe, void *ptr) { + return MCHECK_OK; +} +#define LSAN_MAYBE_INTERCEPT_MCHECK_MPROBE \ + INTERCEPT_FUNCTION(mcheck); \ + INTERCEPT_FUNCTION(mprobe); +#else +#define INIT_MCHECK_MPROBE +#endif // SANITIZER_INTERCEPT_MCHECK_MPROBE + #define OPERATOR_NEW_BODY \ ENSURE_LSAN_INITED; \ GET_STACK_TRACE_MALLOC; \ @@ -320,6 +343,7 @@ LSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE; LSAN_MAYBE_INTERCEPT_MALLINFO; LSAN_MAYBE_INTERCEPT_MALLOPT; + LSAN_MAYBE_INTERCEPT_MCHECK_MPROBE; INTERCEPT_FUNCTION(pthread_create); INTERCEPT_FUNCTION(pthread_join); Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -6142,6 +6142,29 @@ #define INIT_GETLOADAVG #endif +#if SANITIZER_INTERCEPT_MCHECK_MPROBE +enum mcheck_status { + MCHECK_DISABLED = -1, // Consistency checking is not turned on. + MCHECK_OK, // Block is fine. + MCHECK_FREE, // Block freed twice. + MCHECK_HEAD, // Memory before the block was clobbered. + MCHECK_TAIL // Memory after the block was clobbered. +}; + +INTERCEPTOR(int, mcheck, void (*abortfunc)(enum mcheck_status mstatus)) { + return 0; +} + +INTERCEPTOR(int, mprobe, void *ptr) { + return MCHECK_OK; +} +#define INIT_MCHECK_MPROBE \ + COMMON_INTERCEPT_FUNCTION(mcheck); \ + COMMON_INTERCEPT_FUNCTION(mprobe); +#else +#define INIT_MCHECK_MPROBE +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap(); @@ -6344,4 +6367,5 @@ INIT_UTMP; INIT_UTMPX; INIT_GETLOADAVG; + INIT_MCHECK_MPROBE; } Index: lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_interceptors.h +++ lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -339,5 +339,6 @@ #define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC) #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC) #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC) +#define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: test/sanitizer_common/TestCases/Linux/mprobe.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Linux/mprobe.cc @@ -0,0 +1,21 @@ +// RUN: %clangxx %s -o %t && %run %t 2>&1 | FileCheck %s +// UNSUPPORTED: android + +#include +#include +#include + +int main(int argc, char *argv[]) { + void *p; + if (mcheck(NULL) != 0) { + fprintf(stderr, "mcheck() failed\n"); + exit(EXIT_FAILURE); + } + p = malloc(1000); + int res = mprobe(p); + if (res == MCHECK_OK) + printf("Success!\n"); + // CHECK: Success! + free(p); + return 0; +}