options.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //===-- options.h -----------------------------------------------*- 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_OPTIONS_H_
  9. #define GWP_ASAN_OPTIONS_H_
  10. #include <stddef.h>
  11. #include <stdint.h>
  12. namespace gwp_asan {
  13. namespace options {
  14. // ================================ Requirements ===============================
  15. // This function is required to be either implemented by the supporting
  16. // allocator, or one of the two provided implementations may be used
  17. // (RTGwpAsanBacktraceLibc or RTGwpAsanBacktraceSanitizerCommon).
  18. // ================================ Description ================================
  19. // This function shall collect the backtrace for the calling thread and place
  20. // the result in `TraceBuffer`. This function should elide itself and all frames
  21. // below itself from `TraceBuffer`, i.e. the caller's frame should be in
  22. // TraceBuffer[0], and subsequent frames 1..n into TraceBuffer[1..n], where a
  23. // maximum of `Size` frames are stored. Returns the number of frames stored into
  24. // `TraceBuffer`, and zero on failure. If the return value of this function is
  25. // equal to `Size`, it may indicate that the backtrace is truncated.
  26. // =================================== Notes ===================================
  27. // This function may directly or indirectly call malloc(), as the
  28. // GuardedPoolAllocator contains a reentrancy barrier to prevent infinite
  29. // recursion. Any allocation made inside this function will be served by the
  30. // supporting allocator, and will not have GWP-ASan protections.
  31. typedef size_t (*Backtrace_t)(uintptr_t *TraceBuffer, size_t Size);
  32. struct Options {
  33. Backtrace_t Backtrace = nullptr;
  34. // Read the options from the included definitions file.
  35. #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \
  36. Type Name = DefaultValue;
  37. #include "gwp_asan/options.inc"
  38. #undef GWP_ASAN_OPTION
  39. void setDefaults() {
  40. #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \
  41. Name = DefaultValue;
  42. #include "gwp_asan/options.inc"
  43. #undef GWP_ASAN_OPTION
  44. Backtrace = nullptr;
  45. }
  46. };
  47. } // namespace options
  48. } // namespace gwp_asan
  49. #endif // GWP_ASAN_OPTIONS_H_