1 //===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H
10 #define LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H
12 #include "src/__support/macros/config.h" //LIBC_HAS_FEATURE
14 //-----------------------------------------------------------------------------
15 // Properties to check the presence or absence or sanitizers
16 //-----------------------------------------------------------------------------
18 // MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
19 // a compiler instrumentation module and a run-time library. The
20 // MEMORY_SANITIZER macro is deprecated but we will continue to honor it for
22 #ifdef LIBC_HAVE_MEMORY_SANITIZER
23 #error "LIBC_HAVE_MEMORY_SANITIZER cannot be directly set."
24 #elif defined(MEMORY_SANITIZER) || defined(__SANITIZE_MEMORY__) || \
25 (LIBC_HAS_FEATURE(memory_sanitizer) && !defined(__native_client__))
26 #define LIBC_HAVE_MEMORY_SANITIZER
29 // AddressSanitizer (ASan) is a fast memory error detector. The
30 // ADDRESS_SANITIZER macro is deprecated but we will continue to honor it for
32 #ifdef LIBC_HAVE_ADDRESS_SANITIZER
33 #error "LIBC_HAVE_ADDRESS_SANITIZER cannot be directly set."
34 #elif defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__) || \
35 LIBC_HAS_FEATURE(address_sanitizer)
36 #define LIBC_HAVE_ADDRESS_SANITIZER
39 // HWAddressSanitizer (HWASan) is a fast, low memory overhead error detector.
40 #ifdef LIBC_HAVE_HWADDRESS_SANITIZER
41 #error "LIBC_HAVE_HWADDRESS_SANITIZER cannot be directly set."
42 #elif LIBC_HAS_FEATURE(hwaddress_sanitizer)
43 #define LIBC_HAVE_HWADDRESS_SANITIZER
46 //-----------------------------------------------------------------------------
47 // Functions to unpoison memory
48 //-----------------------------------------------------------------------------
50 #ifdef LIBC_HAVE_MEMORY_SANITIZER
51 #include <sanitizer/msan_interface.h>
52 #define MSAN_UNPOISON(addr, size) __msan_unpoison(addr, size)
54 #define MSAN_UNPOISON(ptr, size)
57 #ifdef LIBC_HAVE_ADDRESS_SANITIZER
58 #include <sanitizer/asan_interface.h>
59 #define ASAN_POISON_MEMORY_REGION(addr, size) \
60 __asan_poison_memory_region((addr), (size))
61 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
62 __asan_unpoison_memory_region((addr), (size))
64 #define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
65 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
68 #endif // LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H