1 //===-- sanitizer_flags.cc ------------------------------------------------===//
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 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_flags.h"
16 #include "sanitizer_common.h"
17 #include "sanitizer_libc.h"
18 #include "sanitizer_list.h"
19 #include "sanitizer_flag_parser.h"
21 namespace __sanitizer {
23 CommonFlags common_flags_dont_use;
25 struct FlagDescription {
27 const char *description;
28 FlagDescription *next;
31 IntrusiveList<FlagDescription> flag_descriptions;
33 // If set, the tool will install its own SEGV signal handler by default.
34 #ifndef SANITIZER_NEEDS_SEGV
35 # define SANITIZER_NEEDS_SEGV 1
38 void CommonFlags::SetDefaults() {
39 #define COMMON_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
40 #include "sanitizer_flags.inc"
44 void CommonFlags::CopyFrom(const CommonFlags &other) {
45 internal_memcpy(this, &other, sizeof(*this));
48 class FlagHandlerInclude : public FlagHandlerBase {
49 static const uptr kMaxIncludeSize = 1 << 15;
53 explicit FlagHandlerInclude(FlagParser *parser) : parser_(parser) {}
54 bool Parse(const char *value) {
56 uptr data_mapped_size;
59 ReadFileToBuffer(value, &data, &data_mapped_size,
60 Max(kMaxIncludeSize, GetPageSizeCached()), &err);
62 Printf("Failed to read options from '%s': error %d\n", value, err);
65 parser_->ParseString(data);
66 UnmapOrDie(data, data_mapped_size);
71 void RegisterIncludeFlag(FlagParser *parser, CommonFlags *cf) {
72 FlagHandlerInclude *fh_include =
73 new (FlagParser::Alloc) FlagHandlerInclude(parser); // NOLINT
74 parser->RegisterHandler("include", fh_include,
75 "read more options from the given file");
78 void RegisterCommonFlags(FlagParser *parser, CommonFlags *cf) {
79 #define COMMON_FLAG(Type, Name, DefaultValue, Description) \
80 RegisterFlag(parser, #Name, Description, &cf->Name);
81 #include "sanitizer_flags.inc"
84 RegisterIncludeFlag(parser, cf);
87 } // namespace __sanitizer