xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_flags.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===-- sanitizer_flags.h ---------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef SANITIZER_FLAGS_H
140b57cec5SDimitry Andric #define SANITIZER_FLAGS_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "sanitizer_internal_defs.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric namespace __sanitizer {
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric enum HandleSignalMode {
210b57cec5SDimitry Andric   kHandleSignalNo,
220b57cec5SDimitry Andric   kHandleSignalYes,
230b57cec5SDimitry Andric   kHandleSignalExclusive,
240b57cec5SDimitry Andric };
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric struct CommonFlags {
270b57cec5SDimitry Andric #define COMMON_FLAG(Type, Name, DefaultValue, Description) Type Name;
280b57cec5SDimitry Andric #include "sanitizer_flags.inc"
290b57cec5SDimitry Andric #undef COMMON_FLAG
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric   void SetDefaults();
320b57cec5SDimitry Andric   void CopyFrom(const CommonFlags &other);
330b57cec5SDimitry Andric };
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric // Functions to get/set global CommonFlags shared by all sanitizer runtimes:
360b57cec5SDimitry Andric extern CommonFlags common_flags_dont_use;
common_flags()370b57cec5SDimitry Andric inline const CommonFlags *common_flags() {
380b57cec5SDimitry Andric   return &common_flags_dont_use;
390b57cec5SDimitry Andric }
400b57cec5SDimitry Andric 
SetCommonFlagsDefaults()410b57cec5SDimitry Andric inline void SetCommonFlagsDefaults() {
420b57cec5SDimitry Andric   common_flags_dont_use.SetDefaults();
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric // This function can only be used to setup tool-specific overrides for
460b57cec5SDimitry Andric // CommonFlags defaults. Generally, it should only be used right after
470b57cec5SDimitry Andric // SetCommonFlagsDefaults(), but before ParseCommonFlagsFromString(), and
480b57cec5SDimitry Andric // only during the flags initialization (i.e. before they are used for
490b57cec5SDimitry Andric // the first time).
OverrideCommonFlags(const CommonFlags & cf)500b57cec5SDimitry Andric inline void OverrideCommonFlags(const CommonFlags &cf) {
510b57cec5SDimitry Andric   common_flags_dont_use.CopyFrom(cf);
520b57cec5SDimitry Andric }
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric void SubstituteForFlagValue(const char *s, char *out, uptr out_size);
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric class FlagParser;
570b57cec5SDimitry Andric void RegisterCommonFlags(FlagParser *parser,
580b57cec5SDimitry Andric                          CommonFlags *cf = &common_flags_dont_use);
590b57cec5SDimitry Andric void RegisterIncludeFlags(FlagParser *parser, CommonFlags *cf);
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric // Should be called after parsing all flags. Sets up common flag values
620b57cec5SDimitry Andric // and perform initializations common to all sanitizers (e.g. setting
630b57cec5SDimitry Andric // verbosity).
640b57cec5SDimitry Andric void InitializeCommonFlags(CommonFlags *cf = &common_flags_dont_use);
65*e8d8bef9SDimitry Andric 
66*e8d8bef9SDimitry Andric // Platform specific flags initialization.
67*e8d8bef9SDimitry Andric void InitializePlatformCommonFlags(CommonFlags *cf);
68*e8d8bef9SDimitry Andric 
690b57cec5SDimitry Andric }  // namespace __sanitizer
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric #endif  // SANITIZER_FLAGS_H
72