1 //===-- scudo_flags.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Hardened Allocator flag parsing logic.
12 //===----------------------------------------------------------------------===//
14 #include "scudo_flags.h"
15 #include "scudo_utils.h"
17 #include "sanitizer_common/sanitizer_flags.h"
18 #include "sanitizer_common/sanitizer_flag_parser.h"
22 Flags scudo_flags_dont_use_directly; // use via flags().
24 void Flags::setDefaults() {
25 #define SCUDO_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
26 #include "scudo_flags.inc"
30 static void RegisterScudoFlags(FlagParser *parser, Flags *f) {
31 #define SCUDO_FLAG(Type, Name, DefaultValue, Description) \
32 RegisterFlag(parser, #Name, Description, &f->Name);
33 #include "scudo_flags.inc"
38 SetCommonFlagsDefaults();
41 cf.CopyFrom(*common_flags());
43 OverrideCommonFlags(cf);
45 Flags *f = getFlags();
48 FlagParser scudo_parser;
49 RegisterScudoFlags(&scudo_parser, f);
50 RegisterCommonFlags(&scudo_parser);
52 scudo_parser.ParseString(GetEnv("SCUDO_OPTIONS"));
54 InitializeCommonFlags();
56 // Sanity checks and default settings for the Quarantine parameters.
58 if (f->QuarantineSizeMb < 0) {
59 const int DefaultQuarantineSizeMb = 64;
60 f->QuarantineSizeMb = DefaultQuarantineSizeMb;
62 // We enforce an upper limit for the quarantine size of 4Gb.
63 if (f->QuarantineSizeMb > (4 * 1024)) {
64 dieWithMessage("ERROR: the quarantine size is too large\n");
66 if (f->ThreadLocalQuarantineSizeKb < 0) {
67 const int DefaultThreadLocalQuarantineSizeKb = 1024;
68 f->ThreadLocalQuarantineSizeKb = DefaultThreadLocalQuarantineSizeKb;
70 // And an upper limit of 128Mb for the thread quarantine cache.
71 if (f->ThreadLocalQuarantineSizeKb > (128 * 1024)) {
72 dieWithMessage("ERROR: the per thread quarantine cache size is too "
78 return &scudo_flags_dont_use_directly;