#include #include extern "C" { base_allocator::~base_allocator() {} } namespace alloc { // This is the *true manager* of the allocation arena, when it is destroyed, the memory is cleared struct FrozenAllocator::anon_raw_secmem { // Base class for all deallocations that happen within an `anon_raw_secmem` (managed, static, polymorphic, unmanaged, etc.) (TODO: See below, the base should be moved into the header so typed children can be templated...) struct deleter { //XXX: TODO: How to define this type in the header file? It should be the virt base of all templated deleters, //TODO: XXX: Rework this design, the deleter must be typed for the value it is deleting... This virtual base should be in the header, and should just contain the shared_ptr reference to anon_raw_secmem. virtual ~deleter() = default; protected: // To prevent anon_raw_secmem being destroyed while there are still allocated values, the base class for the deleter for those values contains a refcount. e.g: `std::unique_ptr>` where: `deleter_for final : public deleter { virtual ~deleter_for(); ... };`, or `std::shared_ptr`, where: `std::shared_ptr>` aliases-ctor(`old, old->value_ptr()`) -> `std::shared_ptr` std::shared_ptr m_manager_ref; }; ~anon_raw_secmem() { //TODO: Clear and `munmap()` the used page(s) //XXX: Due to how this is managed via `shared_ptr<>`, it is UB for this to be called *before* all actual allocation of the memory are unallocated (via `deleter`, which they must *all* be managed by. } }; struct FrozenAllocator::alloc_info { }; struct FrozenAllocator::alloc_value { }; struct FrozenAllocator::_impl { std::shared_ptr m_manager; std::map> m_values; }; #define $CLASS FrozenAllocator $ctor_move(m) noexcept : inner_(std::move(m.inner_)) {} $assign_move(m) { if($LIKELY(this != &m)) inner_ = std::move(m.inner_); return *this; } $dtor() {} #undef $CLASS /* FrozenAllocator */ }