1 //===-- allocator_config.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef SCUDO_ALLOCATOR_CONFIG_H_ 10 #define SCUDO_ALLOCATOR_CONFIG_H_ 11 12 #include "combined.h" 13 #include "common.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" 21 22 namespace scudo { 23 24 // Default configurations for various platforms. 25 26 struct DefaultConfig { 27 using SizeClassMap = DefaultSizeClassMap; 28 #if SCUDO_CAN_USE_PRIMARY64 29 // 1GB Regions 30 typedef SizeClassAllocator64<SizeClassMap, 30U> Primary; 31 #else 32 // 512KB regions 33 typedef SizeClassAllocator32<SizeClassMap, 19U> Primary; 34 #endif 35 typedef MapAllocator<MapAllocatorCache<>> Secondary; 36 template <class A> using TSDRegistryT = TSDRegistryExT<A>; // Exclusive 37 }; 38 39 struct AndroidConfig { 40 using SizeClassMap = AndroidSizeClassMap; 41 #if SCUDO_CAN_USE_PRIMARY64 42 // 256MB regions 43 typedef SizeClassAllocator64<SizeClassMap, 28U, 1000, 1000, 44 /*MaySupportMemoryTagging=*/true> 45 Primary; 46 #else 47 // 256KB regions 48 typedef SizeClassAllocator32<SizeClassMap, 18U, 1000, 1000> Primary; 49 #endif 50 // Cache blocks up to 2MB 51 typedef MapAllocator<MapAllocatorCache<32U, 2UL << 20, 0, 1000>> Secondary; 52 template <class A> 53 using TSDRegistryT = TSDRegistrySharedT<A, 2U>; // Shared, max 2 TSDs. 54 }; 55 56 struct AndroidSvelteConfig { 57 using SizeClassMap = SvelteSizeClassMap; 58 #if SCUDO_CAN_USE_PRIMARY64 59 // 128MB regions 60 typedef SizeClassAllocator64<SizeClassMap, 27U, 1000, 1000> Primary; 61 #else 62 // 64KB regions 63 typedef SizeClassAllocator32<SizeClassMap, 16U, 1000, 1000> Primary; 64 #endif 65 typedef MapAllocator<MapAllocatorCache<4U, 1UL << 18, 0, 0>> Secondary; 66 template <class A> 67 using TSDRegistryT = TSDRegistrySharedT<A, 1U>; // Shared, only 1 TSD. 68 }; 69 70 #if SCUDO_CAN_USE_PRIMARY64 71 struct FuchsiaConfig { 72 // 1GB Regions 73 typedef SizeClassAllocator64<DefaultSizeClassMap, 30U> Primary; 74 typedef MapAllocator<MapAllocatorNoCache> Secondary; 75 template <class A> 76 using TSDRegistryT = TSDRegistrySharedT<A, 8U>; // Shared, max 8 TSDs. 77 }; 78 #endif 79 80 #if SCUDO_ANDROID 81 typedef AndroidConfig Config; 82 #elif SCUDO_FUCHSIA 83 typedef FuchsiaConfig Config; 84 #else 85 typedef DefaultConfig Config; 86 #endif 87 88 } // namespace scudo 89 90 #endif // SCUDO_ALLOCATOR_CONFIG_H_ 91