Vitaly Buka | a3cd67c | 2019-09-12 01:35:09 | [diff] [blame] | 1 | //===-- hwasan_flags.inc ----------------------------------------*- C++ -*-===// |
Evgeniy Stepanov | 9595d16 | 2017-12-09 01:31:51 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 | [diff] [blame] | 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 |
Evgeniy Stepanov | 9595d16 | 2017-12-09 01:31:51 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Hwasan runtime flags. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | #ifndef HWASAN_FLAG |
| 13 | # error "Define HWASAN_FLAG prior to including this file!" |
| 14 | #endif |
| 15 | |
| 16 | // HWASAN_FLAG(Type, Name, DefaultValue, Description) |
| 17 | // See COMMON_FLAG in sanitizer_flags.inc for more details. |
| 18 | |
Kostya Serebryany | 3d8f49a | 2018-09-04 23:26:08 | [diff] [blame] | 19 | HWASAN_FLAG(bool, verbose_threads, false, |
| 20 | "inform on thread creation/destruction") |
Evgeniy Stepanov | 9595d16 | 2017-12-09 01:31:51 | [diff] [blame] | 21 | HWASAN_FLAG(bool, tag_in_malloc, true, "") |
| 22 | HWASAN_FLAG(bool, tag_in_free, true, "") |
Evgeniy Stepanov | 9595d16 | 2017-12-09 01:31:51 | [diff] [blame] | 23 | HWASAN_FLAG(bool, print_stats, false, "") |
| 24 | HWASAN_FLAG(bool, halt_on_error, true, "") |
| 25 | HWASAN_FLAG(bool, atexit, false, "") |
Enna1 | b720a59 | 2023-04-19 11:27:26 | [diff] [blame] | 26 | HWASAN_FLAG( |
| 27 | bool, print_live_threads_info, true, |
| 28 | "If set, prints the remaining threads in report as an extra information.") |
Evgeniy Stepanov | 9595d16 | 2017-12-09 01:31:51 | [diff] [blame] | 29 | |
| 30 | // Test only flag to disable malloc/realloc/free memory tagging on startup. |
| 31 | // Tagging can be reenabled with __hwasan_enable_allocator_tagging(). |
| 32 | HWASAN_FLAG(bool, disable_allocator_tagging, false, "") |
Evgeniy Stepanov | 29e3f5b | 2018-01-10 19:36:10 | [diff] [blame] | 33 | |
| 34 | // If false, use simple increment of a thread local counter to generate new |
| 35 | // tags. |
| 36 | HWASAN_FLAG(bool, random_tags, true, "") |
Evgeniy Stepanov | fa9f785 | 2018-08-16 20:13:09 | [diff] [blame] | 37 | |
| 38 | HWASAN_FLAG( |
Evgenii Stepanov | d1a6e4d | 2020-06-05 17:57:44 | [diff] [blame] | 39 | int, max_malloc_fill_size, 0, |
Evgeniy Stepanov | fa9f785 | 2018-08-16 20:13:09 | [diff] [blame] | 40 | "HWASan allocator flag. max_malloc_fill_size is the maximal amount of " |
| 41 | "bytes that will be filled with malloc_fill_byte on malloc.") |
Kostya Serebryany | ba5c716 | 2018-11-16 19:38:48 | [diff] [blame] | 42 | |
Kostya Serebryany | c265e76 | 2018-11-17 00:25:17 | [diff] [blame] | 43 | HWASAN_FLAG(bool, free_checks_tail_magic, 1, |
| 44 | "If set, free() will check the magic values " |
Florian Mayer | 9006b08 | 2022-08-24 23:40:26 | [diff] [blame] | 45 | "after the allocated object " |
Kostya Serebryany | c265e76 | 2018-11-17 00:25:17 | [diff] [blame] | 46 | "if the allocation size is not a divident of the granule size") |
Evgeniy Stepanov | fa9f785 | 2018-08-16 20:13:09 | [diff] [blame] | 47 | HWASAN_FLAG( |
| 48 | int, max_free_fill_size, 0, |
| 49 | "HWASan allocator flag. max_free_fill_size is the maximal amount of " |
| 50 | "bytes that will be filled with free_fill_byte during free.") |
| 51 | HWASAN_FLAG(int, malloc_fill_byte, 0xbe, |
| 52 | "Value used to fill the newly allocated memory.") |
| 53 | HWASAN_FLAG(int, free_fill_byte, 0x55, |
| 54 | "Value used to fill deallocated memory.") |
Kostya Serebryany | 51e1a83 | 2018-08-29 21:07:07 | [diff] [blame] | 55 | HWASAN_FLAG(int, heap_history_size, 1023, |
| 56 | "The number of heap (de)allocations remembered per thread. " |
| 57 | "Affects the quality of heap-related reports, but not the ability " |
| 58 | "to find bugs.") |
Evgeniy Stepanov | d263cb8 | 2018-09-08 00:11:12 | [diff] [blame] | 59 | HWASAN_FLAG(bool, export_memory_stats, true, |
| 60 | "Export up-to-date memory stats through /proc") |
Evgeniy Stepanov | 090f0f9 | 2018-09-24 23:03:34 | [diff] [blame] | 61 | HWASAN_FLAG(int, stack_history_size, 1024, |
| 62 | "The number of stack frames remembered per thread. " |
| 63 | "Affects the quality of stack-related reports, but not the ability " |
| 64 | "to find bugs.") |
Evgeniy Stepanov | a70d88c | 2019-02-15 18:38:14 | [diff] [blame] | 65 | |
| 66 | // Malloc / free bisection. Only tag malloc and free calls when a hash of |
| 67 | // allocation size and stack trace is between malloc_bisect_left and |
| 68 | // malloc_bisect_right (both inclusive). [0, 0] range is special and disables |
| 69 | // bisection (i.e. everything is tagged). Once the range is narrowed down |
| 70 | // enough, use malloc_bisect_dump to see interesting allocations. |
| 71 | HWASAN_FLAG(uptr, malloc_bisect_left, 0, |
| 72 | "Left bound of malloc bisection, inclusive.") |
| 73 | HWASAN_FLAG(uptr, malloc_bisect_right, 0, |
| 74 | "Right bound of malloc bisection, inclusive.") |
| 75 | HWASAN_FLAG(bool, malloc_bisect_dump, false, |
| 76 | "Print all allocations within [malloc_bisect_left, " |
| 77 | "malloc_bisect_right] range ") |
Matthew Malcomson | c1653b8 | 2021-02-19 16:19:37 | [diff] [blame] | 78 | |
| 79 | |
| 80 | // Exit if we fail to enable the AArch64 kernel ABI relaxation which allows |
| 81 | // tagged pointers in syscalls. This is the default, but being able to disable |
| 82 | // that behaviour is useful for running the testsuite on more platforms (the |
| 83 | // testsuite can run since we manually ensure any pointer arguments to syscalls |
| 84 | // are untagged before the call. |
| 85 | HWASAN_FLAG(bool, fail_without_syscall_abi, true, |
Vitaly Buka | c88c460 | 2021-02-27 03:40:10 | [diff] [blame] | 86 | "Exit if fail to request relaxed syscall ABI.") |
Thurston Dang | 0ca05e8 | 2024-06-14 00:47:04 | [diff] [blame] | 87 | |
| 88 | HWASAN_FLAG( |
| 89 | uptr, fixed_shadow_base, -1, |
| 90 | "If not -1, HWASan will attempt to allocate the shadow at this address, " |
| 91 | "instead of choosing one dynamically." |
| 92 | "Tip: this can be combined with the compiler option, " |
| 93 | "-hwasan-mapping-offset, to optimize the instrumentation.") |