[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / __support / macros / sanitizer.h
blobfb1f1440a34d44be558488f0c19cd596d45bc831
1 //===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//
2 //
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
6 //
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
21 // now.
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
27 #endif
29 // AddressSanitizer (ASan) is a fast memory error detector. The
30 // ADDRESS_SANITIZER macro is deprecated but we will continue to honor it for
31 // now.
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
37 #endif
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
44 #endif
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)
53 #else
54 #define MSAN_UNPOISON(ptr, size)
55 #endif
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))
63 #else
64 #define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
65 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
66 #endif
68 #endif // LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H