summaryrefslogtreecommitdiff
path: root/lib/esan/esan_interceptors.cpp
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-06-03 22:30:10 +0000
committerDerek Bruening <bruening@google.com>2016-06-03 22:30:10 +0000
commit82434492a98309d71e14a505a2e2473521b1e9e2 (patch)
treed256d0e84fdff56bd5da5dbcc5d43365b18bee6c /lib/esan/esan_interceptors.cpp
parent1a0b98664125d401d49db90ded4a64dd44a633fb (diff)
[esan] Initialize runtime during early interceptors
Summary: Adds initialization of esan's runtime library during any early interceptors that are sometimes called prior to the official __esan_init() invocation (we see this with apps using tcmalloc). Adds handling of interceptors called during interceptor initialization. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D20976 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271744 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/esan/esan_interceptors.cpp')
-rw-r--r--lib/esan/esan_interceptors.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/esan/esan_interceptors.cpp b/lib/esan/esan_interceptors.cpp
index 35217f58f..15f09c48e 100644
--- a/lib/esan/esan_interceptors.cpp
+++ b/lib/esan/esan_interceptors.cpp
@@ -47,10 +47,15 @@ using namespace __esan; // NOLINT
#define COMMON_INTERCEPT_FUNCTION_VER(name, ver) \
INTERCEPT_FUNCTION_VER(name, ver)
+// We must initialize during early interceptors, to support tcmalloc.
+// This means that for some apps we fully initialize prior to
+// __esan_init() being called.
// We currently do not use ctx.
#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
do { \
if (UNLIKELY(COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)) { \
+ if (!UNLIKELY(EsanDuringInit)) \
+ initializeLibrary(__esan_which_tool); \
return REAL(func)(__VA_ARGS__); \
} \
ctx = nullptr; \
@@ -332,6 +337,8 @@ INTERCEPTOR(int, rmdir, char *path) {
INTERCEPTOR(void *, mmap, void *addr, SIZE_T sz, int prot, int flags,
int fd, OFF_T off) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, mmap, addr, sz, prot, flags, fd, off);
if (!fixMmapAddr(&addr, sz, flags))
return (void *)-1;
void *result = REAL(mmap)(addr, sz, prot, flags, fd, off);
@@ -341,6 +348,8 @@ INTERCEPTOR(void *, mmap, void *addr, SIZE_T sz, int prot, int flags,
#if SANITIZER_LINUX
INTERCEPTOR(void *, mmap64, void *addr, SIZE_T sz, int prot, int flags,
int fd, OFF64_T off) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, mmap64, addr, sz, prot, flags, fd, off);
if (!fixMmapAddr(&addr, sz, flags))
return (void *)-1;
void *result = REAL(mmap64)(addr, sz, prot, flags, fd, off);