summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Kazmin <a.kazmin@partner.samsung.com>2020-05-14 16:57:25 +0300
committerAlexander Soldatov/AI Compiler Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>2020-06-04 15:04:39 +0300
commitd01d6ed6dd82d536268b00bd8fdbafa3791c3f04 (patch)
tree28a27f5fb6af4dc5491634c01feed2a5f9fabb58
parent35c49bf70ce4408fdef937fd0dfab795750a812a (diff)
downloadcoreclr-d01d6ed6dd82d536268b00bd8fdbafa3791c3f04.tar.gz
coreclr-d01d6ed6dd82d536268b00bd8fdbafa3791c3f04.tar.bz2
coreclr-d01d6ed6dd82d536268b00bd8fdbafa3791c3f04.zip
[Tizen] Enable ASan annotation of passing to native code buffers
Turn on ASan inteceptors while marshaling managed buffers to native code. We could not properly annotate already allocated on heap buffers, so we have to disable pinning of such objects. Current patch affects only pinning of native arrays.
-rw-r--r--src/pal/src/memory/local.cpp47
-rw-r--r--src/vm/ilmarshalers.cpp3
2 files changed, 47 insertions, 3 deletions
diff --git a/src/pal/src/memory/local.cpp b/src/pal/src/memory/local.cpp
index 3a0f40f8c4..44d9feb0c5 100644
--- a/src/pal/src/memory/local.cpp
+++ b/src/pal/src/memory/local.cpp
@@ -26,6 +26,14 @@ Revision History:
SET_DEFAULT_DEBUG_CHANNEL(MEM);
+#ifdef TIZEN_ASAN_ENVIRONMENT
+extern "C" {
+extern void __sanitizer_disable_interceptors() __attribute__ ((weak));
+extern void __sanitizer_enable_interceptors() __attribute__ ((weak));
+extern bool __sanitizer_interceptors_are_enabled() __attribute__ ((weak));
+}
+#endif
+
static
int
AllocFlagsToHeapAllocFlags (IN UINT AllocFlags,
@@ -70,7 +78,24 @@ LocalAlloc(
goto done;
}
- lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
+#ifdef TIZEN_ASAN_ENVIRONMENT
+ if (__sanitizer_interceptors_are_enabled != NULL)
+ {
+ bool san_enabled;
+ san_enabled = __sanitizer_interceptors_are_enabled();
+ if (!san_enabled) {
+ __sanitizer_enable_interceptors();
+ }
+ lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
+ if (!san_enabled) {
+ __sanitizer_disable_interceptors();
+ }
+ }
+ else
+#endif
+ {
+ lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
+ }
done:
LOGEXIT( "LocalAlloc returning %p.\n", lpRetVal );
@@ -128,7 +153,25 @@ LocalFree(
if ( hMem )
{
- bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
+#ifdef TIZEN_ASAN_ENVIRONMENT
+ if (__sanitizer_interceptors_are_enabled != NULL)
+ {
+ bool san_enabled;
+ san_enabled = __sanitizer_interceptors_are_enabled();
+ if (!san_enabled) {
+ __sanitizer_enable_interceptors();
+ }
+ bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
+ if (!san_enabled) {
+ __sanitizer_disable_interceptors();
+ }
+ }
+ else
+#endif
+ {
+ bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
+ }
+
}
else
{
diff --git a/src/vm/ilmarshalers.cpp b/src/vm/ilmarshalers.cpp
index a89aeaf2a1..9e7ee17484 100644
--- a/src/vm/ilmarshalers.cpp
+++ b/src/vm/ilmarshalers.cpp
@@ -3808,11 +3808,12 @@ void ILMngdMarshaler::EmitCallMngdMarshalerMethod(ILCodeStream* pslILEmit, Metho
bool ILNativeArrayMarshaler::UsePinnedArraySpecialCase()
{
+#ifndef TIZEN_ASAN_ENVIRONMENT
if (IsCLRToNative(m_dwMarshalFlags) && !IsByref(m_dwMarshalFlags) && (NULL != m_pargs->na.m_pArrayMT) && (NULL == OleVariant::GetMarshalerForVarType(m_pargs->na.m_vt, TRUE)))
{
return true;
}
-
+#endif
return false;
}