1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_DEFAULT_DISPATCH_TO_PARTITION_ALLOC_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_DEFAULT_DISPATCH_TO_PARTITION_ALLOC_H_
7
8 #include "partition_alloc/partition_alloc_buildflags.h"
9
10 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
11 #include "partition_alloc/partition_alloc.h"
12 #include "partition_alloc/partition_alloc_base/component_export.h"
13 #include "partition_alloc/shim/allocator_shim.h"
14
15 namespace allocator_shim::internal {
16
PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)17 class PA_COMPONENT_EXPORT(ALLOCATOR_SHIM) PartitionAllocMalloc {
18 public:
19 // Returns true if ConfigurePartitions() has completed, meaning that the
20 // allocators are effectively set in stone.
21 static bool AllocatorConfigurationFinalized();
22
23 static partition_alloc::PartitionRoot* Allocator();
24 // May return |nullptr|, will never return the same pointer as |Allocator()|.
25 static partition_alloc::PartitionRoot* OriginalAllocator();
26 // May return the same pointer as |Allocator()|.
27 static partition_alloc::PartitionRoot* AlignedAllocator();
28 };
29
30 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
31 void* PartitionMalloc(const AllocatorDispatch*, size_t size, void* context);
32
33 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
34 void* PartitionMallocUnchecked(const AllocatorDispatch*,
35 size_t size,
36 void* context);
37
38 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
39 void* PartitionCalloc(const AllocatorDispatch*,
40 size_t n,
41 size_t size,
42 void* context);
43
44 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
45 void* PartitionMemalign(const AllocatorDispatch*,
46 size_t alignment,
47 size_t size,
48 void* context);
49
50 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
51 void* PartitionAlignedAlloc(const AllocatorDispatch* dispatch,
52 size_t size,
53 size_t alignment,
54 void* context);
55
56 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
57 void* PartitionAlignedRealloc(const AllocatorDispatch* dispatch,
58 void* address,
59 size_t size,
60 size_t alignment,
61 void* context);
62
63 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
64 void* PartitionRealloc(const AllocatorDispatch*,
65 void* address,
66 size_t size,
67 void* context);
68
69 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
70 void PartitionFree(const AllocatorDispatch*, void* object, void* context);
71
72 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
73 size_t PartitionGetSizeEstimate(const AllocatorDispatch*,
74 void* address,
75 void* context);
76
77 } // namespace allocator_shim::internal
78
79 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM)
80
81 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_DEFAULT_DISPATCH_TO_PARTITION_ALLOC_H_
82