mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 17:43:57 +00:00
[sanitizer] Intercept mcheck and mprobe on Linux
This patch addresses https://github.com/google/sanitizers/issues/804. Users can use mcheck and mprobe functions to verify heap state so we should intercept them to avoid breakage of valid code. Differential Revision: https://reviews.llvm.org/D32589 llvm-svn: 302001
This commit is contained in:
parent
5511fc2eb3
commit
726701b0ed
@ -185,6 +185,20 @@ INTERCEPTOR(void, cfree, void *p) ALIAS(WRAPPER_NAME(free));
|
|||||||
#define LSAN_MAYBE_INTERCEPT_CFREE
|
#define LSAN_MAYBE_INTERCEPT_CFREE
|
||||||
#endif // SANITIZER_INTERCEPT_CFREE
|
#endif // SANITIZER_INTERCEPT_CFREE
|
||||||
|
|
||||||
|
#if SANITIZER_INTERCEPT_MCHECK_MPROBE
|
||||||
|
INTERCEPTOR(int, mcheck, void (*abortfunc)(int mstatus)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
INTERCEPTOR(int, mcheck_pedantic, void (*abortfunc)(int mstatus)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
INTERCEPTOR(int, mprobe, void *ptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif // SANITIZER_INTERCEPT_MCHECK_MPROBE
|
||||||
|
|
||||||
#define OPERATOR_NEW_BODY \
|
#define OPERATOR_NEW_BODY \
|
||||||
ENSURE_LSAN_INITED; \
|
ENSURE_LSAN_INITED; \
|
||||||
GET_STACK_TRACE_MALLOC; \
|
GET_STACK_TRACE_MALLOC; \
|
||||||
|
@ -6142,6 +6142,20 @@ INTERCEPTOR(int, getloadavg, double *loadavg, int nelem) {
|
|||||||
#define INIT_GETLOADAVG
|
#define INIT_GETLOADAVG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SANITIZER_INTERCEPT_MCHECK_MPROBE
|
||||||
|
INTERCEPTOR(int, mcheck, void (*abortfunc)(int mstatus)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
INTERCEPTOR(int, mcheck_pedantic, void (*abortfunc)(int mstatus)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
INTERCEPTOR(int, mprobe, void *ptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void InitializeCommonInterceptors() {
|
static void InitializeCommonInterceptors() {
|
||||||
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
|
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
|
||||||
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
|
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
|
||||||
|
@ -339,5 +339,6 @@
|
|||||||
#define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC)
|
#define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC)
|
||||||
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
|
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
|
||||||
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!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
|
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
|
||||||
|
42
compiler-rt/test/sanitizer_common/TestCases/Linux/mprobe.cc
Normal file
42
compiler-rt/test/sanitizer_common/TestCases/Linux/mprobe.cc
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// RUN: %clangxx %s -o %t && %run %t 2>&1 | FileCheck %s
|
||||||
|
// UNSUPPORTED: android
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 2)
|
||||||
|
#include <mcheck.h>
|
||||||
|
#else
|
||||||
|
#define MCHECK_OK 0
|
||||||
|
extern "C" int mcheck(void (*abortfunc)(int mstatus));
|
||||||
|
extern "C" int mcheck_pedantic(void (*abortfunc)(int mstatus));
|
||||||
|
extern "C" int mprobe(void *ptr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void check_heap() {
|
||||||
|
void *p = malloc(1000);
|
||||||
|
int res = mprobe(p);
|
||||||
|
if (res == MCHECK_OK)
|
||||||
|
printf("Success!\n");
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
void *p;
|
||||||
|
if (mcheck(NULL) != 0) {
|
||||||
|
fprintf(stderr, "mcheck() failed\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
check_heap();
|
||||||
|
// CHECK: Success!
|
||||||
|
|
||||||
|
if (mcheck_pedantic(NULL) != 0) {
|
||||||
|
fprintf(stderr, "mcheck_pedantic() failed\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
check_heap();
|
||||||
|
// CHECK: Success!
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user