options.inc 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===-- options.inc ---------------------------------------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef GWP_ASAN_OPTION
  9. #error "Define GWP_ASAN_OPTION prior to including this file!"
  10. #endif
  11. #ifndef GWP_ASAN_DEFAULT_ENABLED
  12. #define GWP_ASAN_DEFAULT_ENABLED true
  13. #endif
  14. #ifndef GWP_ASAN_STRINGIFY
  15. #define GWP_ASAN_STRINGIFY(S) GWP_ASAN_STRINGIFY_(S)
  16. #define GWP_ASAN_STRINGIFY_(S) #S
  17. #endif
  18. GWP_ASAN_OPTION(bool, Enabled, GWP_ASAN_DEFAULT_ENABLED,
  19. "Is GWP-ASan enabled? Defaults to " GWP_ASAN_STRINGIFY(
  20. GWP_ASAN_DEFAULT_ENABLED) ".")
  21. GWP_ASAN_OPTION(int, MaxSimultaneousAllocations, 16,
  22. "Number of simultaneously-guarded allocations available in the "
  23. "pool. Defaults to 16.")
  24. GWP_ASAN_OPTION(int, SampleRate, 5000,
  25. "The probability (1 / SampleRate) that an allocation is "
  26. "selected for GWP-ASan sampling. Default is 5000. Sample rates "
  27. "up to (2^30 - 1) are supported.")
  28. // Developer note - This option is not actually processed by GWP-ASan itself. It
  29. // is included here so that a user can specify whether they want signal handlers
  30. // or not. The supporting allocator should inspect this value to see whether
  31. // signal handlers need to be installed, and then use
  32. // crash_handler::installSignalHandlers() in order to install the handlers. Note
  33. // that in order to support signal handlers, you will need to link against the
  34. // optional crash_handler component.
  35. GWP_ASAN_OPTION(
  36. bool, InstallSignalHandlers, true,
  37. "Install GWP-ASan signal handlers for SIGSEGV during dynamic loading. This "
  38. "allows better error reports by providing stack traces for allocation and "
  39. "deallocation when reporting a memory error. GWP-ASan's signal handler "
  40. "will forward the signal to any previously-installed handler, and user "
  41. "programs that install further signal handlers should make sure they do "
  42. "the same. Note, if the previously installed SIGSEGV handler is SIG_IGN, "
  43. "we terminate the process after dumping the error report.")
  44. GWP_ASAN_OPTION(
  45. bool, Recoverable, false,
  46. "Install GWP-ASan's signal handler in recoverable mode. This means that "
  47. "upon GWP-ASan detecting an error, it'll print the error report, but *not* "
  48. "crash. Only one crash per sampled allocation will ever be recorded, and "
  49. "if a sampled allocation does actually cause a crash, it'll permanently "
  50. "occupy a slot in the pool. The recoverable mode also means that "
  51. "previously-installed signal handlers will only be triggered for "
  52. "non-GWP-ASan errors, as all GWP-ASan errors won't be forwarded.")
  53. GWP_ASAN_OPTION(bool, InstallForkHandlers, true,
  54. "Install GWP-ASan atfork handlers to acquire internal locks "
  55. "before fork and release them after.")
  56. GWP_ASAN_OPTION(bool, help, false, "Print a summary of the available options.")
  57. // =============================================================================
  58. // ==== WARNING
  59. // =============================================================================
  60. // If you are adding flags to GWP-ASan, please note that GWP-ASan flag strings
  61. // may be parsed by trusted system components (on Android, GWP-ASan flag strings
  62. // are parsed by libc during the dynamic loader). This means that GWP-ASan
  63. // should never feature flags like log paths on disk, because this can lead to
  64. // arbitrary file write and thus privilege escalation. For an example, see the
  65. // setuid ASan log_path exploits: https://www.exploit-db.com/exploits/46241.
  66. //
  67. // Please place all new flags above this warning, so that the warning always
  68. // stays at the bottom.