summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Moinvaziri <nathan@nathanm.com>2026-03-09 18:37:51 -0700
committerHans Kristian Rosbach <hk-github@circlestorm.org>2026-03-11 00:56:35 +0100
commitf252bbb63fd793f3883b574f3a3b74e0b49d5c5e (patch)
treecd4a09f4bd5d3f612e9ac0e8489e546cebe14d84
parent2f12c030c888608175e0b343ef0b30003fae4ac6 (diff)
downloadProject-Tick-f252bbb63fd793f3883b574f3a3b74e0b49d5c5e.tar.gz
Project-Tick-f252bbb63fd793f3883b574f3a3b74e0b49d5c5e.zip
Reorganize sanitizer header for readability
-rw-r--r--zsanitizer.h27
1 files changed, 15 insertions, 12 deletions
diff --git a/zsanitizer.h b/zsanitizer.h
index d77456d9da..f57c7b4292 100644
--- a/zsanitizer.h
+++ b/zsanitizer.h
@@ -5,14 +5,23 @@
#ifndef ZSANITIZER_H
#define ZSANITIZER_H
+/* Detect sanitizer availability */
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
# define Z_ADDRESS_SANITIZER 1
# endif
-#elif defined(__SANITIZE_ADDRESS__)
+# if __has_feature(memory_sanitizer)
+# define Z_MEMORY_SANITIZER 1
+# endif
+#elif defined(__SANITIZE_ADDRESS__) /* GCC supports ASAN only */
# define Z_ADDRESS_SANITIZER 1
#endif
+/* Include sanitizer headers */
+#ifdef Z_MEMORY_SANITIZER
+# include <sanitizer/msan_interface.h>
+#endif
+
/*
* __asan_loadN() and __asan_storeN() calls are inserted by compilers in order to check memory accesses.
* They can be called manually too, with the following caveats:
@@ -30,13 +39,7 @@ void __asan_storeN(void *, long);
# define __asan_storeN(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
#endif
-#if defined(__has_feature)
-# if __has_feature(memory_sanitizer)
-# define Z_MEMORY_SANITIZER 1
-# include <sanitizer/msan_interface.h>
-# endif
-#endif
-
+/* Handle intentional uninitialized memory access */
#ifndef Z_MEMORY_SANITIZER
# define __msan_check_mem_is_initialized(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
# define __msan_unpoison(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
@@ -51,10 +54,10 @@ void __asan_storeN(void *, long);
} while (0)
/* Notify sanitizer runtime about an upcoming write access. */
-#define instrument_write(a, size) do { \
- void *__a = (void *)(a); \
- long __size = size; \
- __asan_storeN(__a, __size); \
+#define instrument_write(a, size) do { \
+ void *__a = (void *)(a); \
+ long __size = size; \
+ __asan_storeN(__a, __size); \
} while (0)
/* Notify sanitizer runtime about an upcoming read/write access. */