# Pagemap The Pagemap now stores all the meta-data for the object allocation. The meta-data in the pagemap is effectively a triple of the sizeclass, the remote allocator, and a pointer to a 64 byte block of meta-data for this chunk of memory. By storing the pointer to a block, it allows the pagemap to handle multiple slab sizes without branching on the fast path. There is one entry in the pagemap per 16KiB of address space, but by using the same entry in the pagemap for 4 adjacent entries, then we can treat a 64KiB range can be treated as a single slab of allocations. This change also means there is almost no capability amplification required by the implementation on CHERI for finding meta-data. The only amplification is required, when we change the way a chunk is used to a size of object allocation. # Backend There is a second major aspect of the refactor that there is now a narrow API that abstracts the Pagemap, PAL and address space management. This should better enable the compartmentalisation and makes it easier to produce alternative backends for various research directions. This is a template parameter that can be used to specialised by the front-end in different ways. # Thread local state The thread local state has been refactored into two components, one (called 'localalloc') that is stored directly in the TLS and is constant initialised, and one that is allocated in the address space (called 'coreallloc') which is lazily created and pooled. # Difference This removes Superslabs/Medium slabs as there meta-data is now part of the pagemap.
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "address.h"
|
|
|
|
namespace snmalloc
|
|
{
|
|
/**
|
|
* Invalid pointer class. This is similar to `std::nullptr_t`, but allows
|
|
* other values.
|
|
*/
|
|
template<address_t Sentinel>
|
|
struct InvalidPointer
|
|
{
|
|
/**
|
|
* Equality comparison. Two invalid pointer values with the same sentinel
|
|
* are always the same, invalid pointer values with different sentinels are
|
|
* always different.
|
|
*/
|
|
template<address_t OtherSentinel>
|
|
constexpr bool operator==(const InvalidPointer<OtherSentinel>&)
|
|
{
|
|
return Sentinel == OtherSentinel;
|
|
}
|
|
/**
|
|
* Equality comparison. Two invalid pointer values with the same sentinel
|
|
* are always the same, invalid pointer values with different sentinels are
|
|
* always different.
|
|
*/
|
|
template<address_t OtherSentinel>
|
|
constexpr bool operator!=(const InvalidPointer<OtherSentinel>&)
|
|
{
|
|
return Sentinel != OtherSentinel;
|
|
}
|
|
/**
|
|
* Implicit conversion, creates a pointer with the value of the sentinel.
|
|
* On CHERI and other provenance-tracking systems, this is a
|
|
* provenance-free integer and so will trap if dereferenced, on other
|
|
* systems the sentinel should be a value in unmapped memory.
|
|
*/
|
|
template<typename T>
|
|
operator T*() const
|
|
{
|
|
return reinterpret_cast<T*>(Sentinel);
|
|
}
|
|
/**
|
|
* Implicit conversion to an address, returns the sentinel value.
|
|
*/
|
|
operator address_t() const
|
|
{
|
|
return Sentinel;
|
|
}
|
|
};
|
|
} // namespace snmalloc
|