diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -120,7 +120,7 @@ if (COMPILER_RT_HAS_GWP_ASAN) list(APPEND SCUDO_OBJECT_LIBS - RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler RTGwpAsanOptionsParser) + RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler) list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS) endif() diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -28,7 +28,6 @@ #ifdef GWP_ASAN_HOOKS #include "gwp_asan/guarded_pool_allocator.h" #include "gwp_asan/optional/backtrace.h" -#include "gwp_asan/optional/options_parser.h" #include "gwp_asan/optional/segv_handler.h" #endif // GWP_ASAN_HOOKS @@ -184,12 +183,17 @@ // be functional, best called from PostInitCallback. void initGwpAsan() { #ifdef GWP_ASAN_HOOKS + gwp_asan::options::Options Opt; + Opt.Enabled = getFlags()->GWP_ASAN_Enabled; // Bear in mind - Scudo has its own alignment guarantees that are strictly // enforced. Scudo exposes the same allocation function for everything from // malloc() to posix_memalign, so in general this flag goes unused, as Scudo // will always ask GWP-ASan for an aligned amount of bytes. - gwp_asan::options::initOptions(getEnv("GWP_ASAN_OPTIONS"), Printf); - gwp_asan::options::Options Opt = gwp_asan::options::getOptions(); + Opt.PerfectlyRightAlign = getFlags()->GWP_ASAN_PerfectlyRightAlign; + Opt.MaxSimultaneousAllocations = + getFlags()->GWP_ASAN_MaxSimultaneousAllocations; + Opt.SampleRate = getFlags()->GWP_ASAN_SampleRate; + Opt.InstallSignalHandlers = getFlags()->GWP_ASAN_InstallSignalHandlers; // Embedded GWP-ASan is locked through the Scudo atfork handler (via // Allocator::disable calling GWPASan.disable). Disable GWP-ASan's atfork // handler. diff --git a/compiler-rt/lib/scudo/standalone/flags.cpp b/compiler-rt/lib/scudo/standalone/flags.cpp --- a/compiler-rt/lib/scudo/standalone/flags.cpp +++ b/compiler-rt/lib/scudo/standalone/flags.cpp @@ -23,6 +23,13 @@ #define SCUDO_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue; #include "flags.inc" #undef SCUDO_FLAG + +#ifdef GWP_ASAN_HOOKS +#define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \ + GWP_ASAN_##Name = DefaultValue; +#include "gwp_asan/options.inc" +#undef GWP_ASAN_OPTION +#endif // GWP_ASAN_HOOKS } void registerFlags(FlagParser *Parser, Flags *F) { @@ -31,6 +38,14 @@ reinterpret_cast(&F->Name)); #include "flags.inc" #undef SCUDO_FLAG + +#ifdef GWP_ASAN_HOOKS +#define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \ + Parser->registerFlag("GWP_ASAN_" #Name, Description, FlagType::FT_##Type, \ + reinterpret_cast(&F->GWP_ASAN_##Name)); +#include "gwp_asan/options.inc" +#undef GWP_ASAN_OPTION +#endif // GWP_ASAN_HOOKS } static const char *getCompileDefinitionScudoDefaultOptions() { diff --git a/compiler-rt/lib/scudo/standalone/flags_parser.h b/compiler-rt/lib/scudo/standalone/flags_parser.h --- a/compiler-rt/lib/scudo/standalone/flags_parser.h +++ b/compiler-rt/lib/scudo/standalone/flags_parser.h @@ -29,7 +29,7 @@ void printFlagDescriptions(); private: - static const u32 MaxFlags = 16; + static const u32 MaxFlags = 20; struct Flag { const char *Name; const char *Desc; diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -45,7 +45,7 @@ cmake_parse_arguments(TEST "" "" "SOURCES;ADDITIONAL_RTOBJECTS" ${ARGN}) if (COMPILER_RT_HAS_GWP_ASAN) list(APPEND TEST_ADDITIONAL_RTOBJECTS - RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler RTGwpAsanOptionsParser) + RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler) endif() if(COMPILER_RT_HAS_SCUDO_STANDALONE) diff --git a/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp b/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp @@ -117,3 +117,18 @@ EXPECT_TRUE(Flags.delete_size_mismatch); EXPECT_EQ(2048, Flags.quarantine_max_chunk_size); } + +#ifdef GWP_ASAN_HOOKS +TEST(ScudoFlagsTest, GWPASanFlags) { + scudo::FlagParser Parser; + scudo::Flags Flags; + scudo::registerFlags(&Parser, &Flags); + Flags.setDefaults(); + Flags.GWP_ASAN_Enabled = false; + Parser.parseString("GWP_ASAN_Enabled=true:GWP_ASAN_SampleRate=1:" + "GWP_ASAN_InstallSignalHandlers=false"); + EXPECT_TRUE(Flags.GWP_ASAN_Enabled); + EXPECT_FALSE(Flags.GWP_ASAN_InstallSignalHandlers); + EXPECT_EQ(1, Flags.GWP_ASAN_SampleRate); +} +#endif // GWP_ASAN_HOOKS diff --git a/compiler-rt/test/scudo/standalone/unit/lit.site.cfg.py.in b/compiler-rt/test/scudo/standalone/unit/lit.site.cfg.py.in --- a/compiler-rt/test/scudo/standalone/unit/lit.site.cfg.py.in +++ b/compiler-rt/test/scudo/standalone/unit/lit.site.cfg.py.in @@ -13,4 +13,4 @@ # Disable GWP-ASan for scudo internal tests. if config.gwp_asan: - config.environment['GWP_ASAN_OPTIONS'] = 'Enabled=false' + config.environment['SCUDO_OPTIONS'] = 'GWP_ASAN_Enabled=0'