summaryrefslogtreecommitdiff
path: root/src/utilcode
diff options
context:
space:
mode:
authorSteve Harter <sharter@microsoft.com>2015-11-05 18:41:48 -0600
committerSteve Harter <sharter@microsoft.com>2015-11-17 10:57:16 -0600
commit4e06e4271162ac65a57719398e3b5572de9f5185 (patch)
tree1ca0a0122505a5d1eeca015267cbaa3a29456378 /src/utilcode
parent48617ae01367b2aad76938d101199cf369bead64 (diff)
downloadcoreclr-4e06e4271162ac65a57719398e3b5572de9f5185.tar.gz
coreclr-4e06e4271162ac65a57719398e3b5572de9f5185.tar.bz2
coreclr-4e06e4271162ac65a57719398e3b5572de9f5185.zip
Enable CLANG sanitizers for native debug builds
Diffstat (limited to 'src/utilcode')
-rw-r--r--src/utilcode/clrhost_nodependencies.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/utilcode/clrhost_nodependencies.cpp b/src/utilcode/clrhost_nodependencies.cpp
index 33f270ecb3..30000dc12d 100644
--- a/src/utilcode/clrhost_nodependencies.cpp
+++ b/src/utilcode/clrhost_nodependencies.cpp
@@ -17,6 +17,12 @@
#include "contract.h"
#include "tls.h"
+#if defined __llvm__
+# if defined(__has_feature) && __has_feature(address_sanitizer)
+# define HAS_ADDRESS_SANITIZER
+# endif
+#endif
+
#ifdef _DEBUG_IMPL
//
@@ -37,6 +43,10 @@ void DisableThrowCheck()
dbg_fDisableThrowCheck = TRUE;
}
+#ifdef HAS_ADDRESS_SANITIZER
+// use the functionality from address santizier (which does not throw exceptions)
+#else
+
#define CLRThrowsExceptionWorker() RealCLRThrowsExceptionWorker(__FUNCTION__, __FILE__, __LINE__)
static void RealCLRThrowsExceptionWorker(__in_z const char *szFunction,
@@ -53,6 +63,7 @@ static void RealCLRThrowsExceptionWorker(__in_z const char *szFunction,
CONTRACT_THROWSEX(szFunction, szFile, lineNum);
}
+#endif // HAS_ADDRESS_SANITIZER
#endif //_DEBUG_IMPL
#if defined(_DEBUG_IMPL) && defined(ENABLE_CONTRACTS_IMPL)
@@ -383,6 +394,10 @@ FastFreeInProcessHeapFunc __ClrFreeInProcessHeap = (FastFreeInProcessHeapFunc) C
const NoThrow nothrow = { 0 };
+#ifdef HAS_ADDRESS_SANITIZER
+// use standard heap functions for address santizier
+#else
+
#ifdef __llvm__
__attribute__((visibility("hidden")))
#endif
@@ -431,11 +446,17 @@ operator new[](size_t n)
return result;
};
+#endif // HAS_ADDRESS_SANITIZER
+
#ifdef __llvm__
__attribute__((visibility("hidden")))
#endif
void * __cdecl operator new(size_t n, const NoThrow&)
{
+#ifdef HAS_ADDRESS_SANITIZER
+ // use standard heap functions for address santizier (which doesn't provide for NoThrow)
+ void * result = operator new(n);
+#else
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
STATIC_CONTRACT_FAULT;
@@ -445,7 +466,8 @@ void * __cdecl operator new(size_t n, const NoThrow&)
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));
void * result = ClrAllocInProcessHeap(0, S_SIZE_T(n));
- TRASH_LASTERROR;
+#endif // HAS_ADDRESS_SANITIZER
+ TRASH_LASTERROR;
return result;
}
@@ -454,6 +476,10 @@ __attribute__((visibility("hidden")))
#endif
void * __cdecl operator new[](size_t n, const NoThrow&)
{
+#ifdef HAS_ADDRESS_SANITIZER
+ // use standard heap functions for address santizier (which doesn't provide for NoThrow)
+ void * result = operator new[](n);
+#else
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
STATIC_CONTRACT_FAULT;
@@ -463,10 +489,14 @@ void * __cdecl operator new[](size_t n, const NoThrow&)
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));
void * result = ClrAllocInProcessHeap(0, S_SIZE_T(n));
- TRASH_LASTERROR;
+#endif // HAS_ADDRESS_SANITIZER
+ TRASH_LASTERROR;
return result;
}
+#ifdef HAS_ADDRESS_SANITIZER
+// use standard heap functions for address santizier
+#else
#ifdef __llvm__
__attribute__((visibility("hidden")))
#endif
@@ -499,6 +529,9 @@ operator delete[](void *p) NOEXCEPT
TRASH_LASTERROR;
}
+#endif // HAS_ADDRESS_SANITIZER
+
+
/* ------------------------------------------------------------------------ *
* New operator overloading for the executable heap
* ------------------------------------------------------------------------ */