From 5910fcc58ab4ab0f1d4bfc8b1fca759a08a7b3e1 Mon Sep 17 00:00:00 2001 From: Derek Bruening Date: Fri, 3 Jun 2016 19:40:08 +0000 Subject: [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 --- lib/esan/esan.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'lib/esan/esan.cpp') 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 { -- cgit v1.2.3