mem/pool: Alloc-bound pooled things

These pieces of metadata (specifically, the Allocator structures) are never
deallocated at the moment, so we need not consider how we might amplify these
bounded pointers back to higher authority.
This commit is contained in:
Nathaniel Wesley Filardo
2022-06-06 19:08:02 +01:00
committed by Nathaniel Filardo
parent 94957f0f72
commit 1f79c7638a
2 changed files with 12 additions and 8 deletions

View File

@@ -29,7 +29,7 @@ namespace snmalloc
private:
MPMCStack<T, PreZeroed> stack;
FlagWord lock{};
T* list{nullptr};
capptr::Alloc<T> list{nullptr};
public:
constexpr PoolState() = default;
@@ -121,12 +121,12 @@ namespace snmalloc
static T* acquire(Args&&... args)
{
PoolState<T>& pool = get_state();
T* p = pool.stack.pop();
auto p = capptr::Alloc<T>::unsafe_from(pool.stack.pop());
if (p != nullptr)
{
p->set_in_use();
return p;
return p.unsafe_ptr();
}
auto raw =
@@ -137,14 +137,18 @@ namespace snmalloc
Config::Pal::error("Failed to initialise thread local allocator.");
}
p = new (raw.unsafe_ptr()) T(std::forward<Args>(args)...);
p = capptr_to_user_address_control(
Aal::capptr_bound<T, capptr::bounds::AllocFull>(
capptr::Arena<T>::unsafe_from(new (raw.unsafe_ptr())
T(std::forward<Args>(args)...)),
sizeof(T)));
FlagLock f(pool.lock);
p->list_next = pool.list;
pool.list = p;
p->set_in_use();
return p;
return p.unsafe_ptr();
}
/**
@@ -185,9 +189,9 @@ namespace snmalloc
static T* iterate(T* p = nullptr)
{
if (p == nullptr)
return get_state().list;
return get_state().list.unsafe_ptr();
return p->list_next;
return p->list_next.unsafe_ptr();
}
};
} // namespace snmalloc

View File

@@ -23,7 +23,7 @@ namespace snmalloc
/// Used by the pool for chaining together entries when not in use.
std::atomic<T*> next{nullptr};
/// Used by the pool to keep the list of all entries ever created.
T* list_next;
capptr::Alloc<T> list_next;
std::atomic_flag in_use = ATOMIC_FLAG_INIT;
public: