summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>2019-08-28 19:40:06 (GMT)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>2019-08-28 20:36:51 (GMT)
commit3241d2ed919bc20b429617918f9e8e01836233ef (patch)
tree818238f243925fe799478ca792089917629ea969
parent5f55c46eb134472c908d2328e95c281062b957bb (diff)
downloadcoreclr-sandbox/ches01/integrate-libasansi_debug.zip
coreclr-sandbox/ches01/integrate-libasansi_debug.tar.gz
coreclr-sandbox/ches01/integrate-libasansi_debug.tar.bz2
Change-Id: I7099858ca6b631fc348763e63e463c8e0b1e63cc Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
-rw-r--r--src/vm/tizenasanenv.cpp106
1 files changed, 86 insertions, 20 deletions
diff --git a/src/vm/tizenasanenv.cpp b/src/vm/tizenasanenv.cpp
index e676779..8ed522d 100644
--- a/src/vm/tizenasanenv.cpp
+++ b/src/vm/tizenasanenv.cpp
@@ -49,15 +49,24 @@ struct AuxiliaryCalls {
extern "C" void __sanitizer_disable_interceptors();
extern "C" void __sanitizer_enable_interceptors();
+extern "C" bool __sanitizer_interceptors_are_enabled();
extern LPVOID tizenASanWrapper;
extern UINT32 tizenASanWrapperSize;
extern UINT32 tizenASanWrapperEntryOffset;
-static __thread StaticStack<LPVOID, 128> s_retaddrStack;
+
+struct ReturnInfo {
+ LPVOID addr;
+ bool isSanitized;
+};
+
+static __thread StaticStack<ReturnInfo, 128> s_retaddrStack;
static __thread int s_enableCounter;
+static __thread int s_disableCounter;
+/*
char* itoa(int i, char b[]){
char const digit[] = "0123456789";
char* p = b;
@@ -80,14 +89,18 @@ char* itoa(int i, char b[]){
return end;
}
-void log_msg(const char *msg, int counter)
+void log_msg(const char *msg, int e_counter, int d_counter)
{
char buf[512];
char *p = buf;
- memcpy(p, "#### ", 5); p += 5;
- p = itoa(counter, p);
+ memcpy(p, "#### e=", 5); p += 5;
+ p = itoa(e_counter, p);
+ memcpy(p, " ", 1); p += 1;
+
+ memcpy(p, "d=", 2); p += 2;
+ p = itoa(d_counter, p);
memcpy(p, " ", 1); p += 1;
memcpy(p, msg, strlen(msg) + 1); p += strlen(msg) + 1;
@@ -95,11 +108,10 @@ void log_msg(const char *msg, int counter)
write(1, buf, (unsigned long)p - (unsigned long)buf - 1);
}
-
-static void TryEnable()
+static void TryEnable(int enable, int disable)
{
log_msg("__ENABLE_PRE\n", s_enableCounter);
- if (s_enableCounter == 0) {
+ if (enable && s_enableCounter == 0) {
{
char msg[] = "#### DO_ENABLE PRE\n";
write(1, msg, sizeof(msg) - 1);
@@ -110,11 +122,12 @@ static void TryEnable()
write(1, msg, sizeof(msg) - 1);
}
}
- ++s_enableCounter;
+ s_enableCounter += enable;
+ s_disableCounter += disable;
log_msg("__ENABLE_POST\n", s_enableCounter);
}
-static void TryDisable()
+static void TryDisable(int enable, int disable)
{
log_msg("__DISABLE_PRE\n", s_enableCounter);
if (s_enableCounter == 1) {
@@ -128,9 +141,37 @@ static void TryDisable()
write(1, msg, sizeof(msg) - 1);
}
}
- --s_enableCounter;
+ s_enableCounter -= enable;
+ s_disableCounter -= disable;
log_msg("__DISABLE_POST\n", s_enableCounter);
}
+*/
+static void DoEnable()
+{
+ {
+ char msg[] = "#### DO_ENABLE PRE\n";
+ write(1, msg, sizeof(msg) - 1);
+ }
+ __sanitizer_enable_interceptors();
+ {
+ char msg[] = "#### DO_ENABLE POST\n";
+ write(1, msg, sizeof(msg) - 1);
+ }
+}
+
+static void DoDisable()
+{
+
+ {
+ char msg[] = "#### DO_DISABLE PRE\n";
+ write(1, msg, sizeof(msg) - 1);
+ }
+ __sanitizer_disable_interceptors();
+ {
+ char msg[] = "#### DO_DISABLE POST\n";
+ write(1, msg, sizeof(msg) - 1);
+ }
+}
namespace TizenASanEnv {
@@ -141,8 +182,16 @@ void PushAndDisableASan(LPVOID addr)
char msg[] = "#### PushDisable\n";
write(1, msg, sizeof(msg) - 1);
}
- TryDisable();
- s_retaddrStack.push(addr);
+ ReturnInfo retInfo = {
+ .addr = addr,
+ .isSanitized = __sanitizer_interceptors_are_enabled(),
+ };
+// TryDisable(0, 1);
+
+ if (retInfo.isSanitized)
+ DoDisable();
+
+ s_retaddrStack.push(retInfo);
}
LPVOID PopAndEnableASan()
@@ -151,12 +200,15 @@ LPVOID PopAndEnableASan()
char msg[] = "#### PopEnable\n";
write(1, msg, sizeof(msg) - 1);
}
- LPVOID addr = s_retaddrStack.top();
+ ReturnInfo retInfo = s_retaddrStack.top();
s_retaddrStack.pop();
- TryEnable();
+ if (retInfo.isSanitized)
+ DoEnable();
+// TryEnable(0, 1);
+
- return addr;
+ return retInfo.addr;
}
void PushAndEnableASan(LPVOID addr)
@@ -165,8 +217,17 @@ void PushAndEnableASan(LPVOID addr)
char msg[] = "#### PushEnable\n";
write(1, msg, sizeof(msg) - 1);
}
- s_retaddrStack.push(addr);
- TryEnable();
+
+ _ASSERTE(__sanitizer_interceptors_are_enabled() == false);
+
+ ReturnInfo retInfo = {
+ .addr = addr,
+ .isSanitized = false,
+ };
+
+ s_retaddrStack.push(retInfo);
+ DoEnable();
+// TryEnable(1, 0);
}
LPVOID PopAndDisableASan()
@@ -175,12 +236,17 @@ LPVOID PopAndDisableASan()
char msg[] = "#### PopDisable\n";
write(1, msg, sizeof(msg) - 1);
}
- TryDisable();
+ _ASSERTE(__sanitizer_interceptors_are_enabled() == true);
- LPVOID addr = s_retaddrStack.top();
+ ReturnInfo retInfo = s_retaddrStack.top();
s_retaddrStack.pop();
- return addr;
+ _ASSERTE(retInfo.isSanitized == false);
+ DoDisable();
+
+// TryDisable(1, 0);
+
+ return retInfo.addr;
}
LPVOID CreateWrapper(LPVOID target, void (*pushAddr)(LPVOID addr), LPVOID (*popAddr)())