Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 1 | //===-- 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 Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 18 | #include "sanitizer_common/sanitizer_internal_defs.h" |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 19 | |
Alexey Samsonov | 36ea94d | 2013-02-19 13:14:48 +0000 | [diff] [blame] | 20 | // ASan flag values can be defined in four ways: |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 21 | // 1) initialized with default values at startup. |
Alexey Samsonov | 36ea94d | 2013-02-19 13:14:48 +0000 | [diff] [blame] | 22 | // 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 Samsonov | b750c4c | 2012-07-25 10:40:57 +0000 | [diff] [blame] | 25 | // __asan_default_options(). |
Alexey Samsonov | 36ea94d | 2013-02-19 13:14:48 +0000 | [diff] [blame] | 26 | // 4) overriden from env variable ASAN_OPTIONS. |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 27 | |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 28 | namespace __asan { |
| 29 | |
| 30 | struct 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 Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 35 | // Size (in bytes) of redzones around heap objects. |
| 36 | // Requirement: redzone >= 32, is a power of two. |
| 37 | int redzone; |
| 38 | // If set, prints some debugging information and does additional checks. |
| 39 | bool debug; |
| 40 | // Controls the way to handle globals (0 - don't detect buffer overflow |
| 41 | // on globals, 1 - detect buffer overflow, 2 - print data about registered |
| 42 | // globals). |
| 43 | int report_globals; |
Kostya Serebryany | 3945c58 | 2012-08-21 14:10:25 +0000 | [diff] [blame] | 44 | // If set, attempts to catch initialization order issues. |
| 45 | bool check_initialization_order; |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 46 | // If set, uses custom wrappers and replacements for libc string functions |
| 47 | // to find more errors. |
| 48 | bool replace_str; |
| 49 | // If set, uses custom wrappers for memset/memcpy/memmove intinsics. |
| 50 | bool replace_intrin; |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 51 | // Used on Mac only. |
| 52 | bool mac_ignore_invalid_free; |
Kostya Serebryany | 230e52f | 2013-09-18 10:35:12 +0000 | [diff] [blame] | 53 | // Enables stack-use-after-return checking at run-time. |
| 54 | bool detect_stack_use_after_return; |
Kostya Serebryany | e1c68c3 | 2013-09-27 11:37:23 +0000 | [diff] [blame] | 55 | // The minimal fake stack size log. |
| 56 | int uar_stack_size_log; |
Kostya Serebryany | 2a3619e | 2013-04-04 11:17:14 +0000 | [diff] [blame] | 57 | // ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes |
| 58 | // that will be filled with malloc_fill_byte on malloc. |
| 59 | int max_malloc_fill_size, malloc_fill_byte; |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 60 | // Override exit status if something was reported. |
| 61 | int exitcode; |
| 62 | // If set, user may manually mark memory regions as poisoned or unpoisoned. |
| 63 | bool allow_user_poisoning; |
| 64 | // Number of seconds to sleep between printing an error report and |
| 65 | // terminating application. Useful for debug purposes (when one needs |
| 66 | // to attach gdb, for example). |
| 67 | int sleep_before_dying; |
| 68 | // If set, registers ASan custom segv handler. |
| 69 | bool handle_segv; |
Alexey Samsonov | 332bf33 | 2013-04-25 10:52:15 +0000 | [diff] [blame] | 70 | // If set, allows user register segv handler even if ASan registers one. |
| 71 | bool allow_user_segv_handler; |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 72 | // If set, uses alternate stack for signal handling. |
| 73 | bool use_sigaltstack; |
| 74 | // Allow the users to work around the bug in Nvidia drivers prior to 295.*. |
| 75 | bool check_malloc_usable_size; |
| 76 | // If set, explicitly unmaps (huge) shadow at exit. |
| 77 | bool unmap_shadow_on_exit; |
| 78 | // If set, calls abort() instead of _exit() after printing an error report. |
| 79 | bool abort_on_error; |
Kostya Serebryany | 95f630a | 2013-01-28 07:34:22 +0000 | [diff] [blame] | 80 | // Print various statistics after printing an error message or if atexit=1. |
| 81 | bool print_stats; |
| 82 | // Print the legend for the shadow bytes. |
| 83 | bool print_legend; |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 84 | // If set, prints ASan exit stats even after program terminates successfully. |
| 85 | bool atexit; |
| 86 | // By default, disable core dumper on 64-bit - it makes little sense |
| 87 | // to dump 16T+ core. |
| 88 | bool disable_core; |
Alexander Potapenko | eb8c46e | 2012-08-24 09:22:05 +0000 | [diff] [blame] | 89 | // Allow the tool to re-exec the program. This may interfere badly with the |
| 90 | // debugger. |
| 91 | bool allow_reexec; |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 92 | // If set, prints not only thread creation stacks for threads in error report, |
| 93 | // but also thread creation stacks for threads that created those threads, |
| 94 | // etc. up to main thread. |
| 95 | bool print_full_thread_history; |
Kostya Serebryany | 73bad81 | 2012-12-20 11:54:21 +0000 | [diff] [blame] | 96 | // Poison (or not) the heap memory on [de]allocation. Zero value is useful |
| 97 | // for benchmarking the allocator or instrumentator. |
| 98 | bool poison_heap; |
Kostya Serebryany | cca8e78 | 2013-10-16 13:49:01 +0000 | [diff] [blame] | 99 | // If true, poison partially addressable 8-byte aligned words (default=true). |
| 100 | // This flag affects heap and global buffers, but not stack buffers. |
| 101 | bool poison_partial; |
Kostya Serebryany | fe6d916 | 2012-12-21 08:53:59 +0000 | [diff] [blame] | 102 | // Report errors on malloc/delete, new/free, new/delete[], etc. |
| 103 | bool alloc_dealloc_mismatch; |
Kostya Serebryany | 9e3bd38 | 2012-12-26 06:30:02 +0000 | [diff] [blame] | 104 | // Use stack depot instead of storing stacks in the redzones. |
| 105 | bool use_stack_depot; |
Alexander Potapenko | 8bd5e74 | 2013-02-28 14:09:30 +0000 | [diff] [blame] | 106 | // If true, assume that memcmp(p1, p2, n) always reads n bytes before |
| 107 | // comparing p1 and p2. |
| 108 | bool strict_memcmp; |
Alexey Samsonov | dfeef67 | 2013-04-19 08:35:16 +0000 | [diff] [blame] | 109 | // If true, assume that dynamic initializers can never access globals from |
| 110 | // other modules, even if the latter are already initialized. |
| 111 | bool strict_init_order; |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 112 | }; |
Alexander Potapenko | 8a1dd56 | 2012-07-25 09:18:43 +0000 | [diff] [blame] | 113 | |
Kostya Serebryany | 16cc10d | 2013-04-11 18:36:04 +0000 | [diff] [blame] | 114 | extern Flags asan_flags_dont_use_directly; |
| 115 | inline Flags *flags() { |
| 116 | return &asan_flags_dont_use_directly; |
| 117 | } |
Alexey Samsonov | 7ed1d2b | 2012-07-10 07:41:27 +0000 | [diff] [blame] | 118 | void InitializeFlags(Flags *f, const char *env); |
| 119 | |
| 120 | } // namespace __asan |
| 121 | |
| 122 | #endif // ASAN_FLAGS_H |