Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
asan_annotations.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
///
6
/// @file asan_annotations.hpp
7
/// @brief Provides a stable interface to asan's public API
8
///
9
10
#
ifndef
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_ASAN_ANNOTATIONS_HPP_
11
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_ASAN_ANNOTATIONS_HPP_
12
13
// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
14
#
include
"arene/base/compiler_support/platform_queries.hpp"
15
#
include
"arene/base/compiler_support/preprocessor.hpp"
16
17
// clang-format off
18
// formatting is disabled because clang-format doesn't understand the include syntax for HAS_INCLUDE
19
// parasoft-begin-suppress AUTOSAR-M16_0_7-a "False positive: parasoft doesn't understand the include syntax for HAS_INCLUDE"
20
#
if
ARENE_HAS_INCLUDE
(
<
sanitizer
/
asan_interface
.
h
>
)
&&
ARENE_IS_ON
(
ARENE_ASAN_ENABLED
)
21
#
include
"arene/base/compiler_support/detail/asan_annotations_enabled.hpp"
22
#
else
23
#
include
"arene/base/compiler_support/detail/asan_annotations_disabled.hpp"
24
#
endif
25
// clang-format on
26
// parasoft-end-suppress AUTOSAR-M16_0_7-a
27
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
28
29
// NOLINTBEGIN(cppcoreguidelines-macro-usage) These are wrappers around existing macros that must be macros.
30
// parasoft-begin-suppress AUTOSAR-A16_0_1-d "Conditional defines permitted by A16-0-1 Permit #2"
31
32
///
33
/// @brief Marks a memory region as unaddressable from ASAN's perspective.
34
/// @param addr The starting address of the region.
35
/// @param size The size, in bytes, of the memory region to poison.
36
/// @post If the binary has been compiled under address sanitizer, any attempt to read from the memory location without
37
/// first marking it as addressable will trigger an ASAN violation. Otherwise it is a noop.
38
/// @note This is a simple wrapper around ASAN's
39
/// [public interface](https://github.com/llvm-mirror/compiler-rt/blob/master/include/sanitizer/asan_interface.h).
40
/// If the platform does not provides @c <sanitizer/asan_interface.h> , this is a noop
41
/// @warning Due to asan alignment restrictions, this function may only poison a subregion of the input region. In
42
/// addition, this method is not thread-safe WRT other invocations of ASAN annotations that interact with the
43
/// same memory region.
44
///
45
#
define
ARENE_ASAN_POISON_MEMORY_REGION
(
addr
,
size
)
ARENE_ASAN_POISON_MEMORY_REGION_IMPL
(
(
addr
)
,
(
size
)
)
46
47
///
48
/// @brief Marks a memory region as addressable from ASAN's perspective.
49
/// @param addr The starting address of the region.
50
/// @param size The size, in bytes, of the memory region.
51
/// @post If the binary has been compiled under address sanitizer, the memory region will have no special considerations
52
/// from ASAN's perspective. Otherwise it is a noop.
53
/// @note This is a simple wrapper around ASAN's
54
/// [public interface](https://github.com/llvm-mirror/compiler-rt/blob/master/include/sanitizer/asan_interface.h).
55
/// If the platform does not provides @c <sanitizer/asan_interface.h> , this is a noop
56
/// @warning Due to asan alignment restrictions, this function may only unpoison a subregion of the input region. In
57
/// addition, this method is not thread-safe WRT other invocations of ASAN annotations that interact with the
58
/// same memory region.
59
///
60
#
define
ARENE_ASAN_UNPOISON_MEMORY_REGION
(
addr
,
size
)
ARENE_ASAN_UNPOISON_MEMORY_REGION_IMPL
(
(
addr
)
,
(
size
)
)
61
62
///
63
/// @brief Marks a memory region as unaddressable from ASAN's perspective.
64
/// @param span_of_t An @c arene::base::span<T> defining the range of memory to poison. If @c T is not
65
/// @c arene::base::byte, then the size of the region to mark will be determined by first converting the span
66
/// to bytes via @c arene::base::span::as_bytes , and then using the size of that resulting span.
67
/// @post If the binary has been compiled under address sanitizer, any attempt to read from the memory location without
68
/// first marking it as addressable will trigger an ASAN violation. Otherwise it is a noop.
69
/// @note This is a simple wrapper around ASAN's
70
/// [public interface](https://github.com/llvm-mirror/compiler-rt/blob/master/include/sanitizer/asan_interface.h).
71
/// If the platform does not provides @c <sanitizer/asan_interface.h> , this is a nop
72
/// @warning Due to asan alignment restrictions, this function may only poison a subregion of the input region. In
73
/// addition, this method is not thread-safe WRT other invocations of ASAN annotations that interact with the
74
/// same memory region.
75
///
76
#
define
ARENE_ASAN_POISON_MEMORY_SPAN
(
span_of_t
)
ARENE_ASAN_POISON_MEMORY_SPAN_IMPL
(
span_of_t
)
77
78
///
79
/// @brief Marks a memory region as addressable from ASAN's perspective.
80
/// @param span_of_t A span defining the range of memory to unpoison. If @c T is not
81
/// @c arene::base::byte, then the size of the region to mark will be determined by first converting the span
82
/// to bytes via @c arene::base::span::as_bytes , and then using the size of that resulting span.
83
/// @post If the binary has been compiled under address sanitizer, the memory region will have no special considerations
84
/// from ASAN's perspective. Otherwise it is a noop.
85
/// @note This is a simple wrapper around ASAN's
86
/// [public interface](https://github.com/llvm-mirror/compiler-rt/blob/master/include/sanitizer/asan_interface.h).
87
/// If the platform does not provides @c <sanitizer/asan_interface.h> , this is a nop
88
/// @warning Due to asan alignment restrictions, this function may only unpoison a subregion of the input region. In
89
/// addition, this method is not thread-safe WRT other invocations of ASAN annotations that interact with the
90
/// same memory region.
91
///
92
#
define
ARENE_ASAN_UNPOISON_MEMORY_SPAN
(
span_of_t
)
ARENE_ASAN_UNPOISON_MEMORY_SPAN_IMPL
(
span_of_t
)
93
94
// parasoft-end-suppress AUTOSAR-A16_0_1-d
95
// NOLINTEND(cppcoreguidelines-macro-usage)
96
97
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_ASAN_ANNOTATIONS_HPP_
arene
base
compiler_support
asan_annotations.hpp
Generated by
1.13.2