diff --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h --- a/compiler-rt/lib/scudo/standalone/allocator_config.h +++ b/compiler-rt/lib/scudo/standalone/allocator_config.h @@ -80,6 +80,34 @@ template using TSDRegistryT = TSDRegistryExT; // Exclusive }; +struct MemoryTaggingConfig { + using SizeClassMap = DefaultSizeClassMap; + static const bool MaySupportMemoryTagging = true; + +#if SCUDO_CAN_USE_PRIMARY64 + typedef SizeClassAllocator64 Primary; + static const uptr PrimaryRegionSizeLog = 32U; + typedef uptr PrimaryCompactPtrT; + static const uptr PrimaryCompactPtrScale = 0; +#else + typedef SizeClassAllocator32 Primary; + static const uptr PrimaryRegionSizeLog = 19U; + typedef uptr PrimaryCompactPtrT; +#endif + static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN; + static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX; + + typedef MapAllocatorCache SecondaryCache; + static const u32 SecondaryCacheEntriesArraySize = 32U; + static const u32 SecondaryCacheQuarantineSize = 0U; + static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U; + static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 19; + static const s32 SecondaryCacheMinReleaseToOsIntervalMs = INT32_MIN; + static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = INT32_MAX; + + template using TSDRegistryT = TSDRegistryExT; // Exclusive +}; + struct AndroidConfig { using SizeClassMap = AndroidSizeClassMap; static const bool MaySupportMemoryTagging = true; @@ -160,6 +188,8 @@ typedef AndroidConfig Config; #elif SCUDO_FUCHSIA typedef FuchsiaConfig Config; +#elif SCUDO_LINUX && defined(__aarch64__) +typedef MemoryTaggingConfig Config; #else typedef DefaultConfig Config; #endif diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -111,6 +111,7 @@ #define SCUDO_TYPED_TEST_ALL_TYPES(FIXTURE, NAME) \ SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, AndroidSvelteConfig) \ SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, DefaultConfig) \ + SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, MemoryTaggingConfig) \ SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, AndroidConfig) #endif diff --git a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp --- a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp @@ -17,12 +17,24 @@ #define DEALLOC_TYPE_MISMATCH "true" #endif +static void EnableMemoryTaggingIfSupported() { + if (!scudo::archSupportsMemoryTagging()) + return; + static bool Done = []() { + if (!scudo::systemDetectsMemoryTagFaultsTestOnly()) + scudo::enableSystemMemoryTaggingTestOnly(); + return true; + }(); + (void)Done; +} + // This allows us to turn on/off a Quarantine for specific tests. The Quarantine // parameters are on the low end, to avoid having to loop excessively in some // tests. bool UseQuarantine = true; extern "C" __attribute__((visibility("default"))) const char * __scudo_default_options() { + EnableMemoryTaggingIfSupported(); if (!UseQuarantine) return "dealloc_type_mismatch=" DEALLOC_TYPE_MISMATCH; return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:" @@ -34,8 +46,7 @@ // for Fuchsia builds. #if !SCUDO_FUCHSIA int main(int argc, char **argv) { - if (scudo::archSupportsMemoryTagging()) - scudo::enableSystemMemoryTaggingTestOnly(); + EnableMemoryTaggingIfSupported(); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "memtag.h" #include "tests/scudo_unit_test.h" #include @@ -107,6 +108,11 @@ } TEST(ScudoWrappersCppTest, ThreadedNew) { +#if !SCUDO_ANDROID + // TODO: Investigate why libc sometimes crashes with tag missmatch in + // __pthread_clockjoin_ex. + scudo::ScopedDisableMemoryTagChecks NoTags; +#endif Ready = false; std::thread Threads[32]; for (size_t I = 0U; I < sizeof(Threads) / sizeof(Threads[0]); I++)