1 //===-- flags.cpp -----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
11 #include "flags_parser.h"
13 #include "scudo/interface.h"
22 void Flags::setDefaults() {
23 #define SCUDO_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
28 #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \
29 GWP_ASAN_##Name = DefaultValue;
30 #include "gwp_asan/options.inc"
31 #undef GWP_ASAN_OPTION
32 #endif // GWP_ASAN_HOOKS
35 void registerFlags(FlagParser
*Parser
, Flags
*F
) {
36 #define SCUDO_FLAG(Type, Name, DefaultValue, Description) \
37 Parser->registerFlag(#Name, Description, FlagType::FT_##Type, \
38 reinterpret_cast<void *>(&F->Name));
43 #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \
44 Parser->registerFlag("GWP_ASAN_" #Name, Description, FlagType::FT_##Type, \
45 reinterpret_cast<void *>(&F->GWP_ASAN_##Name));
46 #include "gwp_asan/options.inc"
47 #undef GWP_ASAN_OPTION
48 #endif // GWP_ASAN_HOOKS
51 static const char *getCompileDefinitionScudoDefaultOptions() {
52 #ifdef SCUDO_DEFAULT_OPTIONS
53 return STRINGIFY(SCUDO_DEFAULT_OPTIONS
);
59 static const char *getScudoDefaultOptions() {
60 return (&__scudo_default_options
) ? __scudo_default_options() : "";
64 Flags
*F
= getFlags();
67 registerFlags(&Parser
, F
);
68 Parser
.parseString(getCompileDefinitionScudoDefaultOptions());
69 Parser
.parseString(getScudoDefaultOptions());
70 Parser
.parseString(getEnv("SCUDO_OPTIONS"));
71 if (const char *V
= getEnv("SCUDO_ALLOCATION_RING_BUFFER_SIZE")) {
72 Parser
.parseStringPair("allocation_ring_buffer_size", V
);