summaryrefslogtreecommitdiff
path: root/lib/esan
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-06-03 19:40:08 +0000
committerDerek Bruening <bruening@google.com>2016-06-03 19:40:08 +0000
commit5910fcc58ab4ab0f1d4bfc8b1fca759a08a7b3e1 (patch)
tree6a619f0f26b0647ef7de1e38c9917a02774bb398 /lib/esan
parent89d91c32a0659a10822dd4364de2186bf4483470 (diff)
[esan] Specify which tool via a global variable
Summary: Adds a global variable to specify the tool, to support handling early interceptors that invoke instrumented code, thus requiring shadow memory to be initialized prior to __esan_init() being invoked. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D20974 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271714 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/esan')
-rw-r--r--lib/esan/esan.cpp32
-rw-r--r--lib/esan/esan.h2
-rw-r--r--lib/esan/esan_interface.cpp5
-rw-r--r--lib/esan/esan_interface_internal.h5
4 files changed, 24 insertions, 20 deletions
diff --git a/lib/esan/esan.cpp b/lib/esan/esan.cpp
index 4b5790bf3..ba852041d 100644
--- a/lib/esan/esan.cpp
+++ b/lib/esan/esan.cpp
@@ -30,7 +30,6 @@ extern void __cxa_atexit(void (*function)(void));
namespace __esan {
bool EsanIsInitialized;
-ToolType WhichTool;
ShadowMapping Mapping;
// Different tools use different scales within the same shadow mapping scheme.
@@ -65,22 +64,22 @@ static const uptr ShadowScale[] = {
void processRangeAccess(uptr PC, uptr Addr, int Size, bool IsWrite) {
VPrintf(3, "in esan::%s %p: %c %p %d\n", __FUNCTION__, PC,
IsWrite ? 'w' : 'r', Addr, Size);
- if (WhichTool == ESAN_CacheFrag) {
+ if (__esan_which_tool == ESAN_CacheFrag) {
// TODO(bruening): add shadow mapping and update shadow bits here.
// We'll move this to cache_frag.cpp once we have something.
- } else if (WhichTool == ESAN_WorkingSet) {
+ } else if (__esan_which_tool == ESAN_WorkingSet) {
processRangeAccessWorkingSet(PC, Addr, Size, IsWrite);
}
}
bool processSignal(int SigNum, void (*Handler)(int), void (**Result)(int)) {
- if (WhichTool == ESAN_WorkingSet)
+ if (__esan_which_tool == ESAN_WorkingSet)
return processWorkingSetSignal(SigNum, Handler, Result);
return true;
}
bool processSigaction(int SigNum, const void *Act, void *OldAct) {
- if (WhichTool == ESAN_WorkingSet)
+ if (__esan_which_tool == ESAN_WorkingSet)
return processWorkingSetSigaction(SigNum, Act, OldAct);
return true;
}
@@ -140,7 +139,7 @@ static void initializeShadow() {
DCHECK(verifyShadowScheme());
- Mapping.initialize(ShadowScale[WhichTool]);
+ Mapping.initialize(ShadowScale[__esan_which_tool]);
VPrintf(1, "Shadow scale=%d offset=%p\n", Mapping.Scale, Mapping.Offset);
@@ -150,7 +149,7 @@ static void initializeShadow() {
(ShadowEnd - ShadowStart) >> 30);
uptr Map;
- if (WhichTool == ESAN_WorkingSet) {
+ if (__esan_which_tool == ESAN_WorkingSet) {
// We want to identify all shadow pages that are touched so we start
// out inaccessible.
Map = (uptr)MmapFixedNoAccess(ShadowStart, ShadowEnd- ShadowStart,
@@ -176,10 +175,9 @@ static void initializeShadow() {
void initializeLibrary(ToolType Tool) {
// We assume there is only one thread during init.
if (EsanIsInitialized) {
- CHECK(Tool == WhichTool);
+ CHECK(Tool == __esan_which_tool);
return;
}
- WhichTool = Tool;
SanitizerToolName = "EfficiencySanitizer";
CacheBinaryName();
initializeFlags();
@@ -190,17 +188,17 @@ void initializeLibrary(ToolType Tool) {
::__cxa_atexit((void (*)())finalizeLibrary);
VPrintf(1, "in esan::%s\n", __FUNCTION__);
- if (WhichTool <= ESAN_None || WhichTool >= ESAN_Max) {
- Printf("ERROR: unknown tool %d requested\n", WhichTool);
+ if (__esan_which_tool <= ESAN_None || __esan_which_tool >= ESAN_Max) {
+ Printf("ERROR: unknown tool %d requested\n", __esan_which_tool);
Die();
}
initializeShadow();
initializeInterceptors();
- if (WhichTool == ESAN_CacheFrag) {
+ if (__esan_which_tool == ESAN_CacheFrag) {
initializeCacheFrag();
- } else if (WhichTool == ESAN_WorkingSet) {
+ } else if (__esan_which_tool == ESAN_WorkingSet) {
initializeWorkingSet();
}
@@ -209,9 +207,9 @@ void initializeLibrary(ToolType Tool) {
int finalizeLibrary() {
VPrintf(1, "in esan::%s\n", __FUNCTION__);
- if (WhichTool == ESAN_CacheFrag) {
+ if (__esan_which_tool == ESAN_CacheFrag) {
return finalizeCacheFrag();
- } else if (WhichTool == ESAN_WorkingSet) {
+ } else if (__esan_which_tool == ESAN_WorkingSet) {
return finalizeWorkingSet();
}
return 0;
@@ -219,7 +217,7 @@ int finalizeLibrary() {
void processCompilationUnitInit(void *Ptr) {
VPrintf(2, "in esan::%s\n", __FUNCTION__);
- if (WhichTool == ESAN_CacheFrag) {
+ if (__esan_which_tool == ESAN_CacheFrag) {
DCHECK(Ptr != nullptr);
processCacheFragCompilationUnitInit(Ptr);
} else {
@@ -231,7 +229,7 @@ void processCompilationUnitInit(void *Ptr) {
// For the main executable module, this is called after finalizeLibrary.
void processCompilationUnitExit(void *Ptr) {
VPrintf(2, "in esan::%s\n", __FUNCTION__);
- if (WhichTool == ESAN_CacheFrag) {
+ if (__esan_which_tool == ESAN_CacheFrag) {
DCHECK(Ptr != nullptr);
processCacheFragCompilationUnitExit(Ptr);
} else {
diff --git a/lib/esan/esan.h b/lib/esan/esan.h
index eb2e8b474..708c6549b 100644
--- a/lib/esan/esan.h
+++ b/lib/esan/esan.h
@@ -34,8 +34,6 @@ namespace __esan {
extern bool EsanIsInitialized;
-extern ToolType WhichTool;
-
void initializeLibrary(ToolType Tool);
int finalizeLibrary();
// Esan creates the variable per tool per compilation unit at compile time
diff --git a/lib/esan/esan_interface.cpp b/lib/esan/esan_interface.cpp
index 5b10f7f2e..f6ad3caa8 100644
--- a/lib/esan/esan_interface.cpp
+++ b/lib/esan/esan_interface.cpp
@@ -18,7 +18,10 @@
using namespace __esan; // NOLINT
void __esan_init(ToolType Tool, void *Ptr) {
- WhichTool = Tool;
+ if (Tool != __esan_which_tool) {
+ Printf("ERROR: tool mismatch: %d vs %d\n", Tool, __esan_which_tool);
+ Die();
+ }
initializeLibrary(Tool);
processCompilationUnitInit(Ptr);
}
diff --git a/lib/esan/esan_interface_internal.h b/lib/esan/esan_interface_internal.h
index 83e0433c7..3b915d03e 100644
--- a/lib/esan/esan_interface_internal.h
+++ b/lib/esan/esan_interface_internal.h
@@ -32,6 +32,11 @@ typedef enum Type : u32 {
ESAN_Max,
} ToolType;
+// To handle interceptors that invoke instrumented code prior to
+// __esan_init() being called, the instrumentation module creates this
+// global variable specifying the tool.
+extern ToolType __esan_which_tool;
+
// This function should be called at the very beginning of the process,
// before any instrumented code is executed and before any call to malloc.
SANITIZER_INTERFACE_ATTRIBUTE void __esan_init(ToolType Tool, void *Ptr);