58 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef GWP_ASAN_OPTIONS_H_10#define GWP_ASAN_OPTIONS_H_11 12#include <stddef.h>13#include <stdint.h>14 15namespace gwp_asan {16namespace options {17// ================================ Requirements ===============================18// This function is required to be either implemented by the supporting19// allocator, or one of the two provided implementations may be used20// (RTGwpAsanBacktraceLibc or RTGwpAsanBacktraceSanitizerCommon).21// ================================ Description ================================22// This function shall collect the backtrace for the calling thread and place23// the result in `TraceBuffer`. This function should elide itself and all frames24// below itself from `TraceBuffer`, i.e. the caller's frame should be in25// TraceBuffer[0], and subsequent frames 1..n into TraceBuffer[1..n], where a26// maximum of `Size` frames are stored. Returns the number of frames stored into27// `TraceBuffer`, and zero on failure. If the return value of this function is28// equal to `Size`, it may indicate that the backtrace is truncated.29// =================================== Notes ===================================30// This function may directly or indirectly call malloc(), as the31// GuardedPoolAllocator contains a reentrancy barrier to prevent infinite32// recursion. Any allocation made inside this function will be served by the33// supporting allocator, and will not have GWP-ASan protections.34typedef size_t (*Backtrace_t)(uintptr_t *TraceBuffer, size_t Size);35 36struct Options {37 Backtrace_t Backtrace = nullptr;38 39 // Read the options from the included definitions file.40#define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \41 Type Name = DefaultValue;42#include "gwp_asan/options.inc"43#undef GWP_ASAN_OPTION44 45 void setDefaults() {46#define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \47 Name = DefaultValue;48#include "gwp_asan/options.inc"49#undef GWP_ASAN_OPTION50 51 Backtrace = nullptr;52 }53};54} // namespace options55} // namespace gwp_asan56 57#endif // GWP_ASAN_OPTIONS_H_58