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<> 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 // 1GB regions 43 typedef SizeClassAllocator64<SizeClassMap, 30U> Primary; 44 #else 45 // 512KB regions 46 typedef SizeClassAllocator32<SizeClassMap, 19U> Primary; 47 #endif 48 typedef MapAllocator<> Secondary; 49 template <class A> 50 using TSDRegistryT = TSDRegistrySharedT<A, 2U>; // Shared, max 2 TSDs. 51 }; 52 53 struct AndroidSvelteConfig { 54 using SizeClassMap = SvelteSizeClassMap; 55 #if SCUDO_CAN_USE_PRIMARY64 56 // 512MB regions 57 typedef SizeClassAllocator64<SizeClassMap, 29U> Primary; 58 #else 59 // 64KB regions 60 typedef SizeClassAllocator32<SizeClassMap, 16U> Primary; 61 #endif 62 typedef MapAllocator<0U> Secondary; 63 template <class A> 64 using TSDRegistryT = TSDRegistrySharedT<A, 1U>; // Shared, only 1 TSD. 65 }; 66 67 #if SCUDO_CAN_USE_PRIMARY64 68 struct FuchsiaConfig { 69 // 1GB Regions 70 typedef SizeClassAllocator64<DefaultSizeClassMap, 30U> Primary; 71 typedef MapAllocator<0U> Secondary; 72 template <class A> 73 using TSDRegistryT = TSDRegistrySharedT<A, 8U>; // Shared, max 8 TSDs. 74 }; 75 #endif 76 77 #if SCUDO_ANDROID 78 typedef AndroidConfig Config; 79 #elif SCUDO_FUCHSIA 80 typedef FuchsiaConfig Config; 81 #else 82 typedef DefaultConfig Config; 83 #endif 84 85 } // namespace scudo 86 87 #endif // SCUDO_ALLOCATOR_CONFIG_H_ 88