1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include "../mem/mem.h"
namespace snmalloc
{
/**
* Example of type stored in the pagemap.
* The following class could be replaced by:
*
* ```
* using DefaultPagemapEntry = FrontendMetaEntry<FrontendSlabMetadata>;
* ```
*
* The full form here provides an example of how to extend the pagemap
* entries. It also guarantees that the front end never directly
* constructs meta entries, it only ever reads them or modifies them in
* place.
*/
template<typename SlabMetadata>
class DefaultPagemapEntryT : public FrontendMetaEntry<SlabMetadata>
{
/**
* The private initialising constructor is usable only by this back end.
*/
template<
SNMALLOC_CONCEPT(IsPAL) A1,
typename A2,
typename A3,
typename A4,
typename A5>
friend class BackendAllocator;
/**
* The private default constructor is usable only by the pagemap.
*/
template<size_t GRANULARITY_BITS, typename T, typename PAL, bool has_bounds>
friend class FlatPagemap;
/**
* The only constructor that creates newly initialised meta entries.
* This is callable only by the back end. The front end may copy,
* query, and update these entries, but it may not create them
* directly. This contract allows the back end to store any arbitrary
* metadata in meta entries when they are first constructed.
*/
SNMALLOC_FAST_PATH
DefaultPagemapEntryT(SlabMetadata* meta, uintptr_t ras)
: FrontendMetaEntry<SlabMetadata>(meta, ras)
{}
/**
* Copy assignment is used only by the pagemap.
*/
DefaultPagemapEntryT& operator=(const DefaultPagemapEntryT& other)
{
FrontendMetaEntry<SlabMetadata>::operator=(other);
return *this;
}
/**
* Default constructor. This must be callable from the pagemap.
*/
SNMALLOC_FAST_PATH DefaultPagemapEntryT() = default;
};
template<typename ClientMetaDataProvider>
class DefaultSlabMetadata : public FrontendSlabMetadata<
DefaultSlabMetadata<ClientMetaDataProvider>,
ClientMetaDataProvider>
{};
template<typename ClientMetaDataProvider>
using DefaultPagemapEntry =
DefaultPagemapEntryT<DefaultSlabMetadata<ClientMetaDataProvider>>;
} // namespace snmalloc