1 //===-- scudo_allocator_combined.h ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Scudo Combined Allocator, dispatches allocation & deallocation requests to
11 /// the Primary or the Secondary backend allocators.
13 //===----------------------------------------------------------------------===//
15 #ifndef SCUDO_ALLOCATOR_COMBINED_H_
16 #define SCUDO_ALLOCATOR_COMBINED_H_
18 #ifndef SCUDO_ALLOCATOR_H_
19 # error "This file must be included inside scudo_allocator.h."
22 template <class PrimaryAllocator, class AllocatorCache,
23 class SecondaryAllocator>
24 class CombinedAllocator {
26 void init(s32 ReleaseToOSIntervalMs) {
27 Primary.Init(ReleaseToOSIntervalMs);
32 // Primary allocations are always MinAlignment aligned, and as such do not
33 // require an Alignment parameter.
34 void *allocatePrimary(AllocatorCache *Cache, uptr ClassId) {
35 return Cache->Allocate(&Primary, ClassId);
38 // Secondary allocations do not require a Cache, but do require an Alignment
40 void *allocateSecondary(uptr Size, uptr Alignment) {
41 return Secondary.Allocate(&Stats, Size, Alignment);
44 void deallocatePrimary(AllocatorCache *Cache, void *Ptr, uptr ClassId) {
45 Cache->Deallocate(&Primary, ClassId, Ptr);
48 void deallocateSecondary(void *Ptr) {
49 Secondary.Deallocate(&Stats, Ptr);
52 void initCache(AllocatorCache *Cache) {
56 void destroyCache(AllocatorCache *Cache) {
57 Cache->Destroy(&Primary, &Stats);
60 void getStats(AllocatorStatCounters StatType) const {
66 Secondary.PrintStats();
70 PrimaryAllocator Primary;
71 SecondaryAllocator Secondary;
72 AllocatorGlobalStats Stats;
75 #endif // SCUDO_ALLOCATOR_COMBINED_H_