summaryrefslogtreecommitdiff
path: root/lib/hwasan/hwasan.cc
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2017-12-13 01:16:34 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2017-12-13 01:16:34 +0000
commit4f20a94a11e63df059a5d315b30b8ddf22b10959 (patch)
treefedb192a46c4ad676127f306cf0a0a7d49a9f825 /lib/hwasan/hwasan.cc
parente4c546028442192e48480ff2d3d9e29ecc62774d (diff)
downloadcompiler-rt-4f20a94a11e63df059a5d315b30b8ddf22b10959.tar.gz
[hwasan] Inline instrumentation & fixed shadow.
Summary: This brings CPU overhead on bzip2 down from 5.5x to 2x. Reviewers: kcc, alekseyshl Subscribers: kubamracek, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D41137 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320538 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan/hwasan.cc')
-rw-r--r--lib/hwasan/hwasan.cc36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/hwasan/hwasan.cc b/lib/hwasan/hwasan.cc
index 40012c130..fcc40eb90 100644
--- a/lib/hwasan/hwasan.cc
+++ b/lib/hwasan/hwasan.cc
@@ -238,10 +238,11 @@ void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
*p = x;
}
+template<unsigned X>
__attribute__((always_inline))
static void SigIll() {
#if defined(__aarch64__)
- asm("hlt #0x1\n\t");
+ asm("hlt %0\n\t" ::"n"(X));
#elif defined(__x86_64__) || defined(__i386__)
asm("ud2\n\t");
#else
@@ -251,15 +252,16 @@ static void SigIll() {
// __builtin_unreachable();
}
+template<bool IsStore, unsigned LogSize>
__attribute__((always_inline, nodebug))
static void CheckAddress(uptr p) {
tag_t ptr_tag = GetTagFromPointer(p);
uptr ptr_raw = p & ~kAddressTagMask;
tag_t mem_tag = *(tag_t *)MEM_TO_SHADOW(ptr_raw);
- if (ptr_tag != mem_tag)
- SigIll();
+ if (UNLIKELY(ptr_tag != mem_tag)) SigIll<0x100 + 0x10 * IsStore + LogSize>();
}
+template<bool IsStore>
__attribute__((always_inline, nodebug))
static void CheckAddressSized(uptr p, uptr sz) {
CHECK_NE(0, sz);
@@ -268,22 +270,22 @@ static void CheckAddressSized(uptr p, uptr sz) {
tag_t *shadow_first = (tag_t *)MEM_TO_SHADOW(ptr_raw);
tag_t *shadow_last = (tag_t *)MEM_TO_SHADOW(ptr_raw + sz - 1);
for (tag_t *t = shadow_first; t <= shadow_last; ++t)
- if (ptr_tag != *t) SigIll();
+ if (UNLIKELY(ptr_tag != *t)) SigIll<0x100 + 0x10 * IsStore + 0xf>();
}
-void __hwasan_load(uptr p, uptr sz) { CheckAddressSized(p, sz); }
-void __hwasan_load1(uptr p) { CheckAddress(p); }
-void __hwasan_load2(uptr p) { CheckAddress(p); }
-void __hwasan_load4(uptr p) { CheckAddress(p); }
-void __hwasan_load8(uptr p) { CheckAddress(p); }
-void __hwasan_load16(uptr p) { CheckAddress(p); }
-
-void __hwasan_store(uptr p, uptr sz) { CheckAddressSized(p, sz); }
-void __hwasan_store1(uptr p) { CheckAddress(p); }
-void __hwasan_store2(uptr p) { CheckAddress(p); }
-void __hwasan_store4(uptr p) { CheckAddress(p); }
-void __hwasan_store8(uptr p) { CheckAddress(p); }
-void __hwasan_store16(uptr p) { CheckAddress(p); }
+void __hwasan_load(uptr p, uptr sz) { CheckAddressSized<false>(p, sz); }
+void __hwasan_load1(uptr p) { CheckAddress<false, 0>(p); }
+void __hwasan_load2(uptr p) { CheckAddress<false, 1>(p); }
+void __hwasan_load4(uptr p) { CheckAddress<false, 2>(p); }
+void __hwasan_load8(uptr p) { CheckAddress<false, 3>(p); }
+void __hwasan_load16(uptr p) { CheckAddress<false, 4>(p); }
+
+void __hwasan_store(uptr p, uptr sz) { CheckAddressSized<true>(p, sz); }
+void __hwasan_store1(uptr p) { CheckAddress<true, 0>(p); }
+void __hwasan_store2(uptr p) { CheckAddress<true, 1>(p); }
+void __hwasan_store4(uptr p) { CheckAddress<true, 2>(p); }
+void __hwasan_store8(uptr p) { CheckAddress<true, 3>(p); }
+void __hwasan_store16(uptr p) { CheckAddress<true, 4>(p); }
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
extern "C" {