From 212365130d84f9d3bf9e46b91f72987b01bfcd8e Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Thu, 27 May 2021 17:49:40 -0600 Subject: [PATCH] AK: Add platform macros to detect presence of AddressSanitizer The ASAN_[UN]POISON_MEMORY_REGION macros can be used to manually notify the AddressSanitizer runtime about the reachability of instrumented code accessing a memory region. This is most useful for manually managed heaps and arenas that do not go directly to malloc or alligned_alloc. --- AK/Platform.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/AK/Platform.h b/AK/Platform.h index 8842a201cd..4c1ef2d417 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -45,6 +45,20 @@ #endif #define NO_SANITIZE_ADDRESS [[gnu::no_sanitize_address]] +// GCC doesn't have __has_feature but clang does +#ifndef __has_feature +# define __has_feature(...) 0 +#endif + +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +# define HAS_ADDRESS_SANITIZER +# define ASAN_POISON_MEMORY_REGION(addr, size) __asan_poison_memory_region(addr, size) +# define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region(addr, size) +#else +# define ASAN_POISON_MEMORY_REGION(addr, size) +# define ASAN_UNPOISON_MEMORY_REGION(addr, size) +#endif + #ifndef __serenity__ # include # undef PAGE_SIZE