xref: /freebsd/contrib/llvm-project/compiler-rt/lib/gwp_asan/options.inc (revision e7437ae907c89bf85a99c5cbb7ddd194a1ff1354)
1//===-- options.inc ---------------------------------------------*- 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_OPTION
10#error "Define GWP_ASAN_OPTION prior to including this file!"
11#endif
12
13#ifndef GWP_ASAN_DEFAULT_ENABLED
14#define GWP_ASAN_DEFAULT_ENABLED true
15#endif
16
17#ifndef GWP_ASAN_STRINGIFY
18#define GWP_ASAN_STRINGIFY(S) GWP_ASAN_STRINGIFY_(S)
19#define GWP_ASAN_STRINGIFY_(S) #S
20#endif
21
22GWP_ASAN_OPTION(bool, Enabled, GWP_ASAN_DEFAULT_ENABLED,
23                "Is GWP-ASan enabled? Defaults to " GWP_ASAN_STRINGIFY(
24                    GWP_ASAN_DEFAULT_ENABLED) ".")
25
26GWP_ASAN_OPTION(int, MaxSimultaneousAllocations, 16,
27                "Number of simultaneously-guarded allocations available in the "
28                "pool. Defaults to 16.")
29
30GWP_ASAN_OPTION(int, SampleRate, 5000,
31                "The probability (1 / SampleRate) that an allocation is "
32                "selected for GWP-ASan sampling. Default is 5000. Sample rates "
33                "up to (2^30 - 1) are supported.")
34
35// Developer note - This option is not actually processed by GWP-ASan itself. It
36// is included here so that a user can specify whether they want signal handlers
37// or not. The supporting allocator should inspect this value to see whether
38// signal handlers need to be installed, and then use
39// crash_handler::installSignalHandlers() in order to install the handlers. Note
40// that in order to support signal handlers, you will need to link against the
41// optional crash_handler component.
42GWP_ASAN_OPTION(
43    bool, InstallSignalHandlers, true,
44    "Install GWP-ASan signal handlers for SIGSEGV during dynamic loading. This "
45    "allows better error reports by providing stack traces for allocation and "
46    "deallocation when reporting a memory error. GWP-ASan's signal handler "
47    "will forward the signal to any previously-installed handler, and user "
48    "programs that install further signal handlers should make sure they do "
49    "the same. Note, if the previously installed SIGSEGV handler is SIG_IGN, "
50    "we terminate the process after dumping the error report.")
51
52GWP_ASAN_OPTION(bool, InstallForkHandlers, true,
53                "Install GWP-ASan atfork handlers to acquire internal locks "
54                "before fork and release them after.")
55
56GWP_ASAN_OPTION(bool, help, false, "Print a summary of the available options.")
57
58// =============================================================================
59// ==== WARNING
60// =============================================================================
61// If you are adding flags to GWP-ASan, please note that GWP-ASan flag strings
62// may be parsed by trusted system components (on Android, GWP-ASan flag strings
63// are parsed by libc during the dynamic loader). This means that GWP-ASan
64// should never feature flags like log paths on disk, because this can lead to
65// arbitrary file write and thus privilege escalation. For an example, see the
66// setuid ASan log_path exploits: https://www.exploit-db.com/exploits/46241.
67//
68// Please place all new flags above this warning, so that the warning always
69// stays at the bottom.
70