//===-- primary_test.cpp ----------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "tests/scudo_unit_test.h" #include "allocator_config.h" #include "allocator_config_wrapper.h" #include "condition_variable.h" #include "primary32.h" #include "primary64.h" #include "size_class_map.h" #include #include #include #include #include #include #include #include // Note that with small enough regions, the SizeClassAllocator64 also works on // 32-bit architectures. It's not something we want to encourage, but we still // should ensure the tests pass. template struct TestConfig1 { static const bool MaySupportMemoryTagging = false; template using TSDRegistryT = void; template using PrimaryT = void; template using SecondaryT = void; struct Primary { using SizeClassMap = SizeClassMapT; static const scudo::uptr RegionSizeLog = 18U; static const scudo::uptr GroupSizeLog = 18U; static const scudo::s32 MinReleaseToOsIntervalMs = INT32_MIN; static const scudo::s32 MaxReleaseToOsIntervalMs = INT32_MAX; typedef scudo::uptr CompactPtrT; static const scudo::uptr CompactPtrScale = 0; static const bool EnableRandomOffset = true; static const scudo::uptr MapSizeIncrement = 1UL << 18; }; }; template struct TestConfig2 { static const bool MaySupportMemoryTagging = false; template using TSDRegistryT = void; template using PrimaryT = void; template using SecondaryT = void; struct Primary { using SizeClassMap = SizeClassMapT; #if defined(__mips__) // Unable to allocate greater size on QEMU-user. static const scudo::uptr RegionSizeLog = 23U; #else static const scudo::uptr RegionSizeLog = 24U; #endif static const scudo::uptr GroupSizeLog = 20U; static const scudo::s32 MinReleaseToOsIntervalMs = INT32_MIN; static const scudo::s32 MaxReleaseToOsIntervalMs = INT32_MAX; typedef scudo::uptr CompactPtrT; static const scudo::uptr CompactPtrScale = 0; static const bool EnableRandomOffset = true; static const scudo::uptr MapSizeIncrement = 1UL << 18; }; }; template struct TestConfig3 { static const bool MaySupportMemoryTagging = true; template using TSDRegistryT = void; template using PrimaryT = void; template using SecondaryT = void; struct Primary { using SizeClassMap = SizeClassMapT; #if defined(__mips__) // Unable to allocate greater size on QEMU-user. static const scudo::uptr RegionSizeLog = 23U; #else static const scudo::uptr RegionSizeLog = 24U; #endif static const scudo::uptr GroupSizeLog = 20U; static const scudo::s32 MinReleaseToOsIntervalMs = INT32_MIN; static const scudo::s32 MaxReleaseToOsIntervalMs = INT32_MAX; typedef scudo::uptr CompactPtrT; static const scudo::uptr CompactPtrScale = 0; static const bool EnableContiguousRegions = false; static const bool EnableRandomOffset = true; static const scudo::uptr MapSizeIncrement = 1UL << 18; }; }; template struct TestConfig4 { static const bool MaySupportMemoryTagging = true; template using TSDRegistryT = void; template using PrimaryT = void; template using SecondaryT = void; struct Primary { using SizeClassMap = SizeClassMapT; #if defined(__mips__) // Unable to allocate greater size on QEMU-user. static const scudo::uptr RegionSizeLog = 23U; #else static const scudo::uptr RegionSizeLog = 24U; #endif static const scudo::s32 MinReleaseToOsIntervalMs = INT32_MIN; static const scudo::s32 MaxReleaseToOsIntervalMs = INT32_MAX; static const scudo::uptr CompactPtrScale = 3U; static const scudo::uptr GroupSizeLog = 20U; typedef scudo::u32 CompactPtrT; static const bool EnableRandomOffset = true; static const scudo::uptr MapSizeIncrement = 1UL << 18; }; }; // This is the only test config that enables the condition variable. template struct TestConfig5 { static const bool MaySupportMemoryTagging = true; template using TSDRegistryT = void; template using PrimaryT = void; template using SecondaryT = void; struct Primary { using SizeClassMap = SizeClassMapT; #if defined(__mips__) // Unable to allocate greater size on QEMU-user. static const scudo::uptr RegionSizeLog = 23U; #else static const scudo::uptr RegionSizeLog = 24U; #endif static const scudo::s32 MinReleaseToOsIntervalMs = INT32_MIN; static const scudo::s32 MaxReleaseToOsIntervalMs = INT32_MAX; static const scudo::uptr CompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG; static const scudo::uptr GroupSizeLog = 18U; typedef scudo::u32 CompactPtrT; static const bool EnableRandomOffset = true; static const scudo::uptr MapSizeIncrement = 1UL << 18; #if SCUDO_LINUX using ConditionVariableT = scudo::ConditionVariableLinux; #else using ConditionVariableT = scudo::ConditionVariableDummy; #endif }; }; template