@@ -31,6 +31,30 @@ static void make_mem_good(void *p, size_t s) {
31
31
static void make_mem_bad (void * p , size_t s ) {
32
32
__asan_poison_memory_region (p , s );
33
33
}
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
+ }
34
58
#else
35
59
static void check_mem_is_good (void * p , size_t s ) {}
36
60
static void make_mem_good (void * p , size_t s ) {}
0 commit comments