| 1 | //===-- options.h -----------------------------------------------*- 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 GWP_ASAN_OPTIONS_H_ |
| 10 | #define GWP_ASAN_OPTIONS_H_ |
| 11 | |
| 12 | #include <stddef.h> |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | namespace gwp_asan { |
| 16 | namespace options { |
| 17 | // ================================ Requirements =============================== |
| 18 | // This function is required to be either implemented by the supporting |
| 19 | // allocator, or one of the two provided implementations may be used |
| 20 | // (RTGwpAsanBacktraceLibc or RTGwpAsanBacktraceSanitizerCommon). |
| 21 | // ================================ Description ================================ |
| 22 | // This function shall collect the backtrace for the calling thread and place |
| 23 | // the result in `TraceBuffer`. This function should elide itself and all frames |
| 24 | // below itself from `TraceBuffer`, i.e. the caller's frame should be in |
| 25 | // TraceBuffer[0], and subsequent frames 1..n into TraceBuffer[1..n], where a |
| 26 | // maximum of `Size` frames are stored. Returns the number of frames stored into |
| 27 | // `TraceBuffer`, and zero on failure. If the return value of this function is |
| 28 | // equal to `Size`, it may indicate that the backtrace is truncated. |
| 29 | // =================================== Notes =================================== |
| 30 | // This function may directly or indirectly call malloc(), as the |
| 31 | // GuardedPoolAllocator contains a reentrancy barrier to prevent infinite |
| 32 | // recursion. Any allocation made inside this function will be served by the |
| 33 | // supporting allocator, and will not have GWP-ASan protections. |
| 34 | typedef size_t (*Backtrace_t)(uintptr_t *TraceBuffer, size_t Size); |
| 35 | |
| 36 | struct Options { |
| 37 | Backtrace_t Backtrace = nullptr; |
| 38 | |
| 39 | // Read the options from the included definitions file. |
| 40 | #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \ |
| 41 | Type Name = DefaultValue; |
| 42 | #include "gwp_asan/options.inc" |
| 43 | #undef GWP_ASAN_OPTION |
| 44 | |
| 45 | void setDefaults() { |
| 46 | #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \ |
| 47 | Name = DefaultValue; |
| 48 | #include "gwp_asan/options.inc" |
| 49 | #undef GWP_ASAN_OPTION |
| 50 | |
| 51 | Backtrace = nullptr; |
| 52 | } |
| 53 | }; |
| 54 | } // namespace options |
| 55 | } // namespace gwp_asan |
| 56 | |
| 57 | #endif // GWP_ASAN_OPTIONS_H_ |
| 58 | |