forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitizer.h
74 lines (64 loc) · 3.26 KB
/
sanitizer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H
#define LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H
#include "src/__support/macros/config.h" //LIBC_HAS_FEATURE
//-----------------------------------------------------------------------------
// Properties to check the presence or absence or sanitizers
//-----------------------------------------------------------------------------
// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
// a compiler instrumentation module and a run-time library. The
// MEMORY_SANITIZER macro is deprecated but we will continue to honor it for
// now.
#ifdef LIBC_HAVE_MEMORY_SANITIZER
#error "LIBC_HAVE_MEMORY_SANITIZER cannot be directly set."
#elif defined(MEMORY_SANITIZER) || defined(__SANITIZE_MEMORY__) || \
(LIBC_HAS_FEATURE(memory_sanitizer) && !defined(__native_client__))
#define LIBC_HAVE_MEMORY_SANITIZER
#endif
// AddressSanitizer (ASan) is a fast memory error detector. The
// ADDRESS_SANITIZER macro is deprecated but we will continue to honor it for
// now.
#ifdef LIBC_HAVE_ADDRESS_SANITIZER
#error "LIBC_HAVE_ADDRESS_SANITIZER cannot be directly set."
#elif defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__) || \
LIBC_HAS_FEATURE(address_sanitizer)
#define LIBC_HAVE_ADDRESS_SANITIZER
#endif
// HWAddressSanitizer (HWASan) is a fast, low memory overhead error detector.
#ifdef LIBC_HAVE_HWADDRESS_SANITIZER
#error "LIBC_HAVE_HWADDRESS_SANITIZER cannot be directly set."
#elif LIBC_HAS_FEATURE(hwaddress_sanitizer)
#define LIBC_HAVE_HWADDRESS_SANITIZER
#endif
//-----------------------------------------------------------------------------
// Functions to unpoison memory
//-----------------------------------------------------------------------------
#if defined(LIBC_HAVE_MEMORY_SANITIZER) && __has_builtin(__builtin_constant_p)
// Only perform MSAN unpoison in non-constexpr context.
#include <sanitizer/msan_interface.h>
#define MSAN_UNPOISON(addr, size) \
do { \
if (!__builtin_constant_p(*addr)) { \
__msan_unpoison(addr, size); \
} \
} while (0)
#else
#define MSAN_UNPOISON(ptr, size)
#endif
#ifdef LIBC_HAVE_ADDRESS_SANITIZER
#include <sanitizer/asan_interface.h>
#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) ((void)(addr), (void)(size))
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
#endif
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H