asan_flags.h revision b1971ca4a3057916ca90a733c672a08127d5fe67
1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//===-- asan_flags.h -------------------------------------------*- C++ -*-===//
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//                     The LLVM Compiler Infrastructure
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// This file is distributed under the University of Illinois Open Source
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// License. See LICENSE.TXT for details.
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//===----------------------------------------------------------------------===//
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// This file is a part of AddressSanitizer, an address sanity checker.
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// ASan runtime flags.
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//===----------------------------------------------------------------------===//
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef ASAN_FLAGS_H
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define ASAN_FLAGS_H
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "sanitizer_common/sanitizer_internal_defs.h"
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// ASan flag values can be defined in four ways:
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// 1) initialized with default values at startup.
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// 2) overriden during compilation of ASan runtime by providing
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//    compile definition ASAN_DEFAULT_OPTIONS.
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// 3) overriden from string returned by user-specified function
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov//    __asan_default_options().
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// 4) overriden from env variable ASAN_OPTIONS.
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovnamespace __asan {
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovstruct Flags {
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Size (in bytes) of quarantine used to detect use-after-free errors.
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Lower value may reduce memory usage but increase the chance of
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // false negatives.
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  quarantine_size;
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, uses in-process symbolizer from common sanitizer runtime.
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool symbolize;
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  verbosity;
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Size (in bytes) of redzones around heap objects.
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Requirement: redzone >= 32, is a power of two.
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  redzone;
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, prints some debugging information and does additional checks.
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool debug;
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Controls the way to handle globals (0 - don't detect buffer overflow
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // on globals, 1 - detect buffer overflow, 2 - print data about registered
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // globals).
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  report_globals;
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, attempts to catch initialization order issues.
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool check_initialization_order;
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Max number of stack frames kept for each allocation/deallocation.
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  malloc_context_size;
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, uses custom wrappers and replacements for libc string functions
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // to find more errors.
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool replace_str;
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, uses custom wrappers for memset/memcpy/memmove intinsics.
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool replace_intrin;
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Used on Mac only.
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool mac_ignore_invalid_free;
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // ASan allocator flag.
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool use_fake_stack;
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // that will be filled with malloc_fill_byte on malloc.
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int max_malloc_fill_size, malloc_fill_byte;
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Override exit status if something was reported.
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  exitcode;
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, user may manually mark memory regions as poisoned or unpoisoned.
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool allow_user_poisoning;
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Number of seconds to sleep between printing an error report and
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // terminating application. Useful for debug purposes (when one needs
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // to attach gdb, for example).
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  int  sleep_before_dying;
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, registers ASan custom segv handler.
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool handle_segv;
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, uses alternate stack for signal handling.
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool use_sigaltstack;
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Allow the users to work around the bug in Nvidia drivers prior to 295.*.
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool check_malloc_usable_size;
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, explicitly unmaps (huge) shadow at exit.
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool unmap_shadow_on_exit;
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, calls abort() instead of _exit() after printing an error report.
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool abort_on_error;
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Print various statistics after printing an error message or if atexit=1.
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool print_stats;
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Print the legend for the shadow bytes.
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool print_legend;
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, prints ASan exit stats even after program terminates successfully.
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool atexit;
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // By default, disable core dumper on 64-bit - it makes little sense
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // to dump 16T+ core.
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool disable_core;
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Allow the tool to re-exec the program. This may interfere badly with the
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // debugger.
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool allow_reexec;
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Strips this prefix from file paths in error reports.
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  const char *strip_path_prefix;
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If set, prints not only thread creation stacks for threads in error report,
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // but also thread creation stacks for threads that created those threads,
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // etc. up to main thread.
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool print_full_thread_history;
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // ASan will write logs to "log_path.pid" instead of stderr.
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  const char *log_path;
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Use fast (frame-pointer-based) unwinder on fatal errors (if available).
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool fast_unwind_on_fatal;
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Use fast (frame-pointer-based) unwinder on malloc/free (if available).
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool fast_unwind_on_malloc;
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Poison (or not) the heap memory on [de]allocation. Zero value is useful
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // for benchmarking the allocator or instrumentator.
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool poison_heap;
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Report errors on malloc/delete, new/free, new/delete[], etc.
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool alloc_dealloc_mismatch;
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // Use stack depot instead of storing stacks in the redzones.
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool use_stack_depot;
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // If true, assume that memcmp(p1, p2, n) always reads n bytes before
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  // comparing p1 and p2.
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  bool strict_memcmp;
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFlags *flags();
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid InitializeFlags(Flags *f, const char *env);
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}  // namespace __asan
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif  // ASAN_FLAGS_H
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov