blob: 7c2a1e36b671436ecc14272ffed27cedd47b93ca [file] [log] [blame]
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +00001//===-- asan_flags.h -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of AddressSanitizer, an address sanity checker.
11//
12// ASan runtime flags.
13//===----------------------------------------------------------------------===//
14
15#ifndef ASAN_FLAGS_H
16#define ASAN_FLAGS_H
17
Evgeniy Stepanov250f2212013-01-30 13:12:08 +000018#include "sanitizer_common/sanitizer_internal_defs.h"
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000019
Alexey Samsonov36ea94d2013-02-19 13:14:48 +000020// ASan flag values can be defined in four ways:
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000021// 1) initialized with default values at startup.
Alexey Samsonov36ea94d2013-02-19 13:14:48 +000022// 2) overriden during compilation of ASan runtime by providing
23// compile definition ASAN_DEFAULT_OPTIONS.
24// 3) overriden from string returned by user-specified function
Alexey Samsonovb750c4c2012-07-25 10:40:57 +000025// __asan_default_options().
Alexey Samsonov36ea94d2013-02-19 13:14:48 +000026// 4) overriden from env variable ASAN_OPTIONS.
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000027
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000028namespace __asan {
29
30struct Flags {
31 // Size (in bytes) of quarantine used to detect use-after-free errors.
32 // Lower value may reduce memory usage but increase the chance of
33 // false negatives.
34 int quarantine_size;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000035 // Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).
36 int verbosity;
37 // Size (in bytes) of redzones around heap objects.
38 // Requirement: redzone >= 32, is a power of two.
39 int redzone;
40 // If set, prints some debugging information and does additional checks.
41 bool debug;
42 // Controls the way to handle globals (0 - don't detect buffer overflow
43 // on globals, 1 - detect buffer overflow, 2 - print data about registered
44 // globals).
45 int report_globals;
Kostya Serebryany3945c582012-08-21 14:10:25 +000046 // If set, attempts to catch initialization order issues.
47 bool check_initialization_order;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000048 // If set, uses custom wrappers and replacements for libc string functions
49 // to find more errors.
50 bool replace_str;
51 // If set, uses custom wrappers for memset/memcpy/memmove intinsics.
52 bool replace_intrin;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000053 // Used on Mac only.
54 bool mac_ignore_invalid_free;
Kostya Serebryany230e52f2013-09-18 10:35:12 +000055 // Enables stack-use-after-return checking at run-time.
56 bool detect_stack_use_after_return;
Kostya Serebryanye1c68c32013-09-27 11:37:23 +000057 // The minimal fake stack size log.
58 int uar_stack_size_log;
Kostya Serebryany2a3619e2013-04-04 11:17:14 +000059 // ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes
60 // that will be filled with malloc_fill_byte on malloc.
61 int max_malloc_fill_size, malloc_fill_byte;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000062 // Override exit status if something was reported.
63 int exitcode;
64 // If set, user may manually mark memory regions as poisoned or unpoisoned.
65 bool allow_user_poisoning;
66 // Number of seconds to sleep between printing an error report and
67 // terminating application. Useful for debug purposes (when one needs
68 // to attach gdb, for example).
69 int sleep_before_dying;
70 // If set, registers ASan custom segv handler.
71 bool handle_segv;
Alexey Samsonov332bf332013-04-25 10:52:15 +000072 // If set, allows user register segv handler even if ASan registers one.
73 bool allow_user_segv_handler;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000074 // If set, uses alternate stack for signal handling.
75 bool use_sigaltstack;
76 // Allow the users to work around the bug in Nvidia drivers prior to 295.*.
77 bool check_malloc_usable_size;
78 // If set, explicitly unmaps (huge) shadow at exit.
79 bool unmap_shadow_on_exit;
80 // If set, calls abort() instead of _exit() after printing an error report.
81 bool abort_on_error;
Kostya Serebryany95f630a2013-01-28 07:34:22 +000082 // Print various statistics after printing an error message or if atexit=1.
83 bool print_stats;
84 // Print the legend for the shadow bytes.
85 bool print_legend;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +000086 // If set, prints ASan exit stats even after program terminates successfully.
87 bool atexit;
88 // By default, disable core dumper on 64-bit - it makes little sense
89 // to dump 16T+ core.
90 bool disable_core;
Alexander Potapenkoeb8c46e2012-08-24 09:22:05 +000091 // Allow the tool to re-exec the program. This may interfere badly with the
92 // debugger.
93 bool allow_reexec;
Alexey Samsonov71b42c92012-09-05 07:37:15 +000094 // If set, prints not only thread creation stacks for threads in error report,
95 // but also thread creation stacks for threads that created those threads,
96 // etc. up to main thread.
97 bool print_full_thread_history;
Kostya Serebryany73bad812012-12-20 11:54:21 +000098 // Poison (or not) the heap memory on [de]allocation. Zero value is useful
99 // for benchmarking the allocator or instrumentator.
100 bool poison_heap;
Kostya Serebryanyfe6d9162012-12-21 08:53:59 +0000101 // Report errors on malloc/delete, new/free, new/delete[], etc.
102 bool alloc_dealloc_mismatch;
Kostya Serebryany9e3bd382012-12-26 06:30:02 +0000103 // Use stack depot instead of storing stacks in the redzones.
104 bool use_stack_depot;
Alexander Potapenko8bd5e742013-02-28 14:09:30 +0000105 // If true, assume that memcmp(p1, p2, n) always reads n bytes before
106 // comparing p1 and p2.
107 bool strict_memcmp;
Alexey Samsonovdfeef672013-04-19 08:35:16 +0000108 // If true, assume that dynamic initializers can never access globals from
109 // other modules, even if the latter are already initialized.
110 bool strict_init_order;
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +0000111};
Alexander Potapenko8a1dd562012-07-25 09:18:43 +0000112
Kostya Serebryany16cc10d2013-04-11 18:36:04 +0000113extern Flags asan_flags_dont_use_directly;
114inline Flags *flags() {
115 return &asan_flags_dont_use_directly;
116}
Alexey Samsonov7ed1d2b2012-07-10 07:41:27 +0000117void InitializeFlags(Flags *f, const char *env);
118
119} // namespace __asan
120
121#endif // ASAN_FLAGS_H