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