Path: blob/main/contrib/llvm-project/compiler-rt/lib/scudo/standalone/allocator_config.h
35291 views
//===-- allocator_config.h --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef SCUDO_ALLOCATOR_CONFIG_H_9#define SCUDO_ALLOCATOR_CONFIG_H_1011#include "combined.h"12#include "common.h"13#include "condition_variable.h"14#include "flags.h"15#include "primary32.h"16#include "primary64.h"17#include "secondary.h"18#include "size_class_map.h"19#include "tsd_exclusive.h"20#include "tsd_shared.h"2122// To import a custom configuration, define `SCUDO_USE_CUSTOM_CONFIG` and23// aliasing the `Config` like:24//25// namespace scudo {26// // The instance of Scudo will be initiated with `Config`.27// typedef CustomConfig Config;28// // Aliasing as default configuration to run the tests with this config.29// typedef CustomConfig DefaultConfig;30// } // namespace scudo31//32// Put them in the header `custom_scudo_config.h` then you will be using the33// custom configuration and able to run all the tests as well.34#ifdef SCUDO_USE_CUSTOM_CONFIG35#include "custom_scudo_config.h"36#endif3738namespace scudo {3940// Scudo uses a structure as a template argument that specifies the41// configuration options for the various subcomponents of the allocator. See the42// following configs as examples and check `allocator_config.def` for all the43// available options.4445#ifndef SCUDO_USE_CUSTOM_CONFIG4647// Default configurations for various platforms. Note this is only enabled when48// there's no custom configuration in the build system.49struct DefaultConfig {50static const bool MaySupportMemoryTagging = true;51template <class A> using TSDRegistryT = TSDRegistryExT<A>; // Exclusive5253struct Primary {54using SizeClassMap = DefaultSizeClassMap;55#if SCUDO_CAN_USE_PRIMARY6456static const uptr RegionSizeLog = 32U;57static const uptr GroupSizeLog = 21U;58typedef uptr CompactPtrT;59static const uptr CompactPtrScale = 0;60static const bool EnableRandomOffset = true;61static const uptr MapSizeIncrement = 1UL << 18;62#else63static const uptr RegionSizeLog = 19U;64static const uptr GroupSizeLog = 19U;65typedef uptr CompactPtrT;66#endif67static const s32 MinReleaseToOsIntervalMs = INT32_MIN;68static const s32 MaxReleaseToOsIntervalMs = INT32_MAX;69};70#if SCUDO_CAN_USE_PRIMARY6471template <typename Config> using PrimaryT = SizeClassAllocator64<Config>;72#else73template <typename Config> using PrimaryT = SizeClassAllocator32<Config>;74#endif7576struct Secondary {77struct Cache {78static const u32 EntriesArraySize = 32U;79static const u32 QuarantineSize = 0U;80static const u32 DefaultMaxEntriesCount = 32U;81static const uptr DefaultMaxEntrySize = 1UL << 19;82static const s32 MinReleaseToOsIntervalMs = INT32_MIN;83static const s32 MaxReleaseToOsIntervalMs = INT32_MAX;84};85template <typename Config> using CacheT = MapAllocatorCache<Config>;86};8788template <typename Config> using SecondaryT = MapAllocator<Config>;89};9091#endif // SCUDO_USE_CUSTOM_CONFIG9293struct AndroidConfig {94static const bool MaySupportMemoryTagging = true;95template <class A>96using TSDRegistryT = TSDRegistrySharedT<A, 8U, 2U>; // Shared, max 8 TSDs.9798struct Primary {99using SizeClassMap = AndroidSizeClassMap;100#if SCUDO_CAN_USE_PRIMARY64101static const uptr RegionSizeLog = 28U;102typedef u32 CompactPtrT;103static const uptr CompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG;104static const uptr GroupSizeLog = 20U;105static const bool EnableRandomOffset = true;106static const uptr MapSizeIncrement = 1UL << 18;107#else108static const uptr RegionSizeLog = 18U;109static const uptr GroupSizeLog = 18U;110typedef uptr CompactPtrT;111#endif112static const s32 MinReleaseToOsIntervalMs = 1000;113static const s32 MaxReleaseToOsIntervalMs = 1000;114};115#if SCUDO_CAN_USE_PRIMARY64116template <typename Config> using PrimaryT = SizeClassAllocator64<Config>;117#else118template <typename Config> using PrimaryT = SizeClassAllocator32<Config>;119#endif120121struct Secondary {122struct Cache {123static const u32 EntriesArraySize = 256U;124static const u32 QuarantineSize = 32U;125static const u32 DefaultMaxEntriesCount = 32U;126static const uptr DefaultMaxEntrySize = 2UL << 20;127static const s32 MinReleaseToOsIntervalMs = 0;128static const s32 MaxReleaseToOsIntervalMs = 1000;129};130template <typename Config> using CacheT = MapAllocatorCache<Config>;131};132133template <typename Config> using SecondaryT = MapAllocator<Config>;134};135136#if SCUDO_CAN_USE_PRIMARY64137struct FuchsiaConfig {138static const bool MaySupportMemoryTagging = false;139template <class A>140using TSDRegistryT = TSDRegistrySharedT<A, 8U, 4U>; // Shared, max 8 TSDs.141142struct Primary {143using SizeClassMap = FuchsiaSizeClassMap;144#if SCUDO_RISCV64145// Support 39-bit VMA for riscv-64146static const uptr RegionSizeLog = 28U;147static const uptr GroupSizeLog = 19U;148static const bool EnableContiguousRegions = false;149#else150static const uptr RegionSizeLog = 30U;151static const uptr GroupSizeLog = 21U;152#endif153typedef u32 CompactPtrT;154static const bool EnableRandomOffset = true;155static const uptr MapSizeIncrement = 1UL << 18;156static const uptr CompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG;157static const s32 MinReleaseToOsIntervalMs = INT32_MIN;158static const s32 MaxReleaseToOsIntervalMs = INT32_MAX;159};160template <typename Config> using PrimaryT = SizeClassAllocator64<Config>;161162struct Secondary {163template <typename Config> using CacheT = MapAllocatorNoCache<Config>;164};165template <typename Config> using SecondaryT = MapAllocator<Config>;166};167168struct TrustyConfig {169static const bool MaySupportMemoryTagging = true;170template <class A>171using TSDRegistryT = TSDRegistrySharedT<A, 1U, 1U>; // Shared, max 1 TSD.172173struct Primary {174using SizeClassMap = TrustySizeClassMap;175static const uptr RegionSizeLog = 28U;176static const uptr GroupSizeLog = 20U;177typedef u32 CompactPtrT;178static const bool EnableRandomOffset = false;179static const uptr MapSizeIncrement = 1UL << 12;180static const uptr CompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG;181static const s32 MinReleaseToOsIntervalMs = INT32_MIN;182static const s32 MaxReleaseToOsIntervalMs = INT32_MAX;183};184template <typename Config> using PrimaryT = SizeClassAllocator64<Config>;185186struct Secondary {187template <typename Config> using CacheT = MapAllocatorNoCache<Config>;188};189190template <typename Config> using SecondaryT = MapAllocator<Config>;191};192#endif193194#ifndef SCUDO_USE_CUSTOM_CONFIG195196#if SCUDO_ANDROID197typedef AndroidConfig Config;198#elif SCUDO_FUCHSIA199typedef FuchsiaConfig Config;200#elif SCUDO_TRUSTY201typedef TrustyConfig Config;202#else203typedef DefaultConfig Config;204#endif205206#endif // SCUDO_USE_CUSTOM_CONFIG207208} // namespace scudo209210#endif // SCUDO_ALLOCATOR_CONFIG_H_211212213