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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H |
10 | #define LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H |
11 | |
12 | #include "src/__support/macros/config.h" //LIBC_HAS_FEATURE |
13 | |
14 | //----------------------------------------------------------------------------- |
15 | // Functions to unpoison memory |
16 | //----------------------------------------------------------------------------- |
17 | |
18 | #if LIBC_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
19 | #define LIBC_HAS_ADDRESS_SANITIZER |
20 | #endif |
21 | |
22 | #if LIBC_HAS_FEATURE(memory_sanitizer) |
23 | #define LIBC_HAS_MEMORY_SANITIZER |
24 | #endif |
25 | |
26 | #if LIBC_HAS_FEATURE(undefined_behavior_sanitizer) |
27 | #define LIBC_HAS_UNDEFINED_BEHAVIOR_SANITIZER |
28 | #endif |
29 | |
30 | #if defined(LIBC_HAS_ADDRESS_SANITIZER) || \ |
31 | defined(LIBC_HAS_MEMORY_SANITIZER) || \ |
32 | defined(LIBC_HAS_UNDEFINED_BEHAVIOR_SANITIZER) |
33 | #define LIBC_HAS_SANITIZER |
34 | #endif |
35 | |
36 | #ifdef LIBC_HAS_MEMORY_SANITIZER |
37 | // Only perform MSAN unpoison in non-constexpr context. |
38 | #include <sanitizer/msan_interface.h> |
39 | #define MSAN_UNPOISON(addr, size) \ |
40 | do { \ |
41 | if (!__builtin_is_constant_evaluated()) \ |
42 | __msan_unpoison(addr, size); \ |
43 | } while (0) |
44 | #else |
45 | #define MSAN_UNPOISON(ptr, size) |
46 | #endif |
47 | |
48 | #ifdef LIBC_HAS_ADDRESS_SANITIZER |
49 | #include <sanitizer/asan_interface.h> |
50 | #define ASAN_POISON_MEMORY_REGION(addr, size) \ |
51 | __asan_poison_memory_region((addr), (size)) |
52 | #define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ |
53 | __asan_unpoison_memory_region((addr), (size)) |
54 | #else |
55 | #define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) |
56 | #define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) |
57 | #endif |
58 | |
59 | #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H |
60 | |