• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<256U, 32U, 2UL << 20, 0, 1000>>
52       Secondary;
53   template <class A>
54   using TSDRegistryT = TSDRegistrySharedT<A, 8U, 2U>; // Shared, max 8 TSDs.
55 };
56 
57 struct AndroidSvelteConfig {
58   using SizeClassMap = SvelteSizeClassMap;
59 #if SCUDO_CAN_USE_PRIMARY64
60   // 128MB regions
61   typedef SizeClassAllocator64<SizeClassMap, 27U, 1000, 1000> Primary;
62 #else
63   // 64KB regions
64   typedef SizeClassAllocator32<SizeClassMap, 16U, 1000, 1000> Primary;
65 #endif
66   typedef MapAllocator<MapAllocatorCache<16U, 4U, 1UL << 18, 0, 0>> Secondary;
67   template <class A>
68   using TSDRegistryT = TSDRegistrySharedT<A, 2U, 1U>; // Shared, max 2 TSDs.
69 };
70 
71 #if SCUDO_CAN_USE_PRIMARY64
72 struct FuchsiaConfig {
73   // 1GB Regions
74   typedef SizeClassAllocator64<DefaultSizeClassMap, 30U> Primary;
75   typedef MapAllocator<MapAllocatorNoCache> Secondary;
76   template <class A>
77   using TSDRegistryT = TSDRegistrySharedT<A, 8U, 4U>; // Shared, max 8 TSDs.
78 };
79 #endif
80 
81 #if SCUDO_ANDROID
82 typedef AndroidConfig Config;
83 #elif SCUDO_FUCHSIA
84 typedef FuchsiaConfig Config;
85 #else
86 typedef DefaultConfig Config;
87 #endif
88 
89 } // namespace scudo
90 
91 #endif // SCUDO_ALLOCATOR_CONFIG_H_
92