asan_flags.h revision 2a3619ecbb56e828090b4c40ece28550f68c94de
146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton//===-- asan_flags.h -------------------------------------------*- C++ -*-===// 246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// The LLVM Compiler Infrastructure 446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// This file is distributed under the University of Illinois Open Source 646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// License. See LICENSE.TXT for details. 746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton//===----------------------------------------------------------------------===// 946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 1046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// This file is a part of AddressSanitizer, an address sanity checker. 1146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 1246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// ASan runtime flags. 1346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton//===----------------------------------------------------------------------===// 1446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton 1546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton#ifndef ASAN_FLAGS_H 1646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton#define ASAN_FLAGS_H 1746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton 1846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton#include "sanitizer_common/sanitizer_internal_defs.h" 1946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton 2046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// ASan flag values can be defined in four ways: 2146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 1) initialized with default values at startup. 2294a5d0de4433dce556db59758f3d6124eb0e1a2aJim Ingham// 2) overriden during compilation of ASan runtime by providing 2346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// compile definition ASAN_DEFAULT_OPTIONS. 2446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 3) overriden from string returned by user-specified function 2546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// __asan_default_options(). 2646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton// 4) overriden from env variable ASAN_OPTIONS. 2746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton 2846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Claytonnamespace __asan { 2946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton 3046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Claytonstruct Flags { 3146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Size (in bytes) of quarantine used to detect use-after-free errors. 3246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Lower value may reduce memory usage but increase the chance of 3346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // false negatives. 3446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int quarantine_size; 3546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, uses in-process symbolizer from common sanitizer runtime. 3646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool symbolize; 3746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output). 3846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int verbosity; 3946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Size (in bytes) of redzones around heap objects. 4046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Requirement: redzone >= 32, is a power of two. 4146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int redzone; 4246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, prints some debugging information and does additional checks. 4346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool debug; 4446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Controls the way to handle globals (0 - don't detect buffer overflow 4546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // on globals, 1 - detect buffer overflow, 2 - print data about registered 4646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // globals). 4746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int report_globals; 4846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, attempts to catch initialization order issues. 4946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool check_initialization_order; 5046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Max number of stack frames kept for each allocation/deallocation. 5146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int malloc_context_size; 5246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, uses custom wrappers and replacements for libc string functions 5346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // to find more errors. 5446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool replace_str; 5546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, uses custom wrappers for memset/memcpy/memmove intinsics. 5646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool replace_intrin; 5746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Used on Mac only. 5846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool mac_ignore_invalid_free; 5946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // ASan allocator flag. See asan_allocator.cc. 6046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool use_fake_stack; 6146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes 6246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // that will be filled with malloc_fill_byte on malloc. 6346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int max_malloc_fill_size, malloc_fill_byte; 6446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Override exit status if something was reported. 6546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int exitcode; 6646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, user may manually mark memory regions as poisoned or unpoisoned. 6746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool allow_user_poisoning; 6846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Number of seconds to sleep between printing an error report and 6946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // terminating application. Useful for debug purposes (when one needs 7046c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // to attach gdb, for example). 7146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton int sleep_before_dying; 7246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, registers ASan custom segv handler. 7346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool handle_segv; 7446c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, uses alternate stack for signal handling. 7546c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool use_sigaltstack; 7646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // Allow the users to work around the bug in Nvidia drivers prior to 295.*. 7746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool check_malloc_usable_size; 7846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, explicitly unmaps (huge) shadow at exit. 7946c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool unmap_shadow_on_exit; 80f4124deeb9532044a38c0774ced872f2709347daGreg Clayton // If set, calls abort() instead of _exit() after printing an error report. 8146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool abort_on_error; 82863aa28adf536c9c008e1590f25da662431d6f13Greg Clayton // Print various statistics after printing an error message or if atexit=1. 8346c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool print_stats; 84863aa28adf536c9c008e1590f25da662431d6f13Greg Clayton // Print the legend for the shadow bytes. 85863aa28adf536c9c008e1590f25da662431d6f13Greg Clayton bool print_legend; 8646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // If set, prints ASan exit stats even after program terminates successfully. 8746c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton bool atexit; 8846c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton // By default, disable core dumper on 64-bit - it makes little sense 89 // to dump 16T+ core. 90 bool disable_core; 91 // Allow the tool to re-exec the program. This may interfere badly with the 92 // debugger. 93 bool allow_reexec; 94 // Strips this prefix from file paths in error reports. 95 const char *strip_path_prefix; 96 // If set, prints not only thread creation stacks for threads in error report, 97 // but also thread creation stacks for threads that created those threads, 98 // etc. up to main thread. 99 bool print_full_thread_history; 100 // ASan will write logs to "log_path.pid" instead of stderr. 101 const char *log_path; 102 // Use fast (frame-pointer-based) unwinder on fatal errors (if available). 103 bool fast_unwind_on_fatal; 104 // Use fast (frame-pointer-based) unwinder on malloc/free (if available). 105 bool fast_unwind_on_malloc; 106 // Poison (or not) the heap memory on [de]allocation. Zero value is useful 107 // for benchmarking the allocator or instrumentator. 108 bool poison_heap; 109 // Report errors on malloc/delete, new/free, new/delete[], etc. 110 bool alloc_dealloc_mismatch; 111 // Use stack depot instead of storing stacks in the redzones. 112 bool use_stack_depot; 113 // If true, assume that memcmp(p1, p2, n) always reads n bytes before 114 // comparing p1 and p2. 115 bool strict_memcmp; 116}; 117 118Flags *flags(); 119void InitializeFlags(Flags *f, const char *env); 120 121} // namespace __asan 122 123#endif // ASAN_FLAGS_H 124