You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.0 KiB
52 lines
2.0 KiB
|
|
|
|
#include <map>
|
|
|
|
#include <alloc.h>
|
|
|
|
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<T, deleter_for<T>>` where: `deleter_for<T> final : public deleter { virtual ~deleter_for(); ... };`, or `std::shared_ptr<T>`, where: `std::shared_ptr<value_with_deleter<T>>` aliases-ctor(`old, old->value_ptr()`) -> `std::shared_ptr<T>`
|
|
std::shared_ptr<anon_raw_secmem> 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<anon_raw_secmem> m_manager;
|
|
std::map<alloc_info, std::unique_ptr<alloc_value>> 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 */
|
|
|
|
}
|