[compiler-rt] c636b18 - [test][hwasan] Implement sanitizer_specific for HWASAN (#75280)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 14:39:40 PST 2023


Author: Vitaly Buka
Date: 2023-12-13T14:39:35-08:00
New Revision: c636b186bc0f8e11e804deb3edd0d72cb0fd157c

URL: https://github.com/llvm/llvm-project/commit/c636b186bc0f8e11e804deb3edd0d72cb0fd157c
DIFF: https://github.com/llvm/llvm-project/commit/c636b186bc0f8e11e804deb3edd0d72cb0fd157c.diff

LOG: [test][hwasan] Implement sanitizer_specific for HWASAN (#75280)

Added: 
    

Modified: 
    compiler-rt/test/sanitizer_common/sanitizer_specific.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
index 898899f00e3701..99a4dd98c614a1 100644
--- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h
+++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
@@ -31,6 +31,30 @@ static void make_mem_good(void *p, size_t s) {
 static void make_mem_bad(void *p, size_t s) {
   __asan_poison_memory_region(p, s);
 }
+#elif __has_feature(hwaddress_sanitizer)
+#  include <sanitizer/hwasan_interface.h>
+#  include <stdlib.h>
+static void check_mem_is_good(void *p, size_t s) {
+  if (__hwasan_test_shadow(p, s) != -1)
+    abort();
+}
+static void make_mem_good(void *p, size_t s) {
+  __hwasan_tag_memory(p, __hwasan_get_tag_from_pointer(p), s);
+}
+static void make_mem_bad(void *p, size_t s) {
+  uint8_t tag = ~__hwasan_get_tag_from_pointer(p);
+  if (!tag) {
+    // Nothing wrong with tag zero, but non-zero tags help to detect never
+    // tagged memory.
+    tag = 1;
+  }
+  __hwasan_tag_memory(p, tag, s);
+  // With misaligned `p` or short granules we can't guarantee tag mismatch.
+  if (__hwasan_test_shadow(p, s) != 0)
+    abort();
+  if (s > 1 && __hwasan_test_shadow(((char *)p) + s - 1, 1) != 0)
+    abort();
+}
 #else
 static void check_mem_is_good(void *p, size_t s) {}
 static void make_mem_good(void *p, size_t s) {}


        


More information about the llvm-commits mailing list