acadia/zion/memory/user_stack_manager.h
Drew Galbraith 2dd69f5844 [Zion] Map user stacks in as regular MemoryObjects.
This allows us to easily track the physical memory so it
can be freed when the thread exits. It also simplifies the page fault
handler as it just needs to check regular mappings to find a user stack.
2023-11-24 16:51:35 -08:00

30 lines
675 B
C++

#pragma once
#include <glacier/container/linked_list.h>
#include <stdint.h>
#include "memory/constants.h"
// Per-process class to manage user stacks.
//
// User stacks live at
// 0x00007FF0 00000000 - 0x00007FFF FFFFFFFF
// and grow downwards.
//
// Each user stack gets 1 MiB (0x100000 bytes)
// less a page boundary.
// with 1 page allocated at a time.
// TODO: consider increasing this.
class UserStackManager {
public:
UserStackManager() {}
UserStackManager(const UserStackManager&) = delete;
uint64_t NewUserStack();
void FreeUserStack(uint64_t stack_base);
private:
uint64_t next_stack_ = kUserStackMax;
glcr::LinkedList<uint64_t> freed_stacks_;
};