xref: /freebsd/contrib/llvm-project/compiler-rt/lib/gwp_asan/options.h (revision 2f513db72b034fd5ef7f080b11be5c711c15186a)
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 // The function pointer type for printf(). Follows the standard format from the
18 // sanitizers library. If the supported allocator exposes printing via a
19 // different function signature, please provide a wrapper which has this
20 // printf() signature, and pass the wrapper instead.
21 typedef void (*Printf_t)(const char *Format, ...);
22 
23 // The function pointer type for backtrace information. Required to be
24 // implemented by the supporting allocator. The callee should elide itself and
25 // all frames below itself from TraceBuffer, i.e. the caller's frame should be
26 // in TraceBuffer[0], and subsequent frames 1..n into TraceBuffer[1..n], where a
27 // maximum of `MaximumDepth - 1` frames are stored. TraceBuffer should be
28 // nullptr-terminated (i.e. if there are 5 frames; TraceBuffer[5] == nullptr).
29 // If the allocator cannot supply backtrace information, it should set
30 // TraceBuffer[0] == nullptr.
31 typedef void (*Backtrace_t)(uintptr_t *TraceBuffer, size_t Size);
32 typedef void (*PrintBacktrace_t)(uintptr_t *TraceBuffer, Printf_t Print);
33 
34 struct Options {
35   Printf_t Printf = nullptr;
36   Backtrace_t Backtrace = nullptr;
37   PrintBacktrace_t PrintBacktrace = 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     Printf = nullptr;
52     Backtrace = nullptr;
53     PrintBacktrace = nullptr;
54   }
55 };
56 } // namespace options
57 } // namespace gwp_asan
58 
59 #endif // GWP_ASAN_OPTIONS_H_
60