Skip to content

Commit c636b18

Browse files
authored
[test][hwasan] Implement sanitizer_specific for HWASAN (#75280)
1 parent f397bdf commit c636b18

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compiler-rt/test/sanitizer_common/sanitizer_specific.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ static void make_mem_good(void *p, size_t s) {
3131
static void make_mem_bad(void *p, size_t s) {
3232
__asan_poison_memory_region(p, s);
3333
}
34+
#elif __has_feature(hwaddress_sanitizer)
35+
# include <sanitizer/hwasan_interface.h>
36+
# include <stdlib.h>
37+
static void check_mem_is_good(void *p, size_t s) {
38+
if (__hwasan_test_shadow(p, s) != -1)
39+
abort();
40+
}
41+
static void make_mem_good(void *p, size_t s) {
42+
__hwasan_tag_memory(p, __hwasan_get_tag_from_pointer(p), s);
43+
}
44+
static void make_mem_bad(void *p, size_t s) {
45+
uint8_t tag = ~__hwasan_get_tag_from_pointer(p);
46+
if (!tag) {
47+
// Nothing wrong with tag zero, but non-zero tags help to detect never
48+
// tagged memory.
49+
tag = 1;
50+
}
51+
__hwasan_tag_memory(p, tag, s);
52+
// With misaligned `p` or short granules we can't guarantee tag mismatch.
53+
if (__hwasan_test_shadow(p, s) != 0)
54+
abort();
55+
if (s > 1 && __hwasan_test_shadow(((char *)p) + s - 1, 1) != 0)
56+
abort();
57+
}
3458
#else
3559
static void check_mem_is_good(void *p, size_t s) {}
3660
static void make_mem_good(void *p, size_t s) {}

0 commit comments

Comments
 (0)