acadia/zion/memory/user_stack_manager.cpp
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

24 lines
581 B
C++

#include "memory/user_stack_manager.h"
#include "debug/debug.h"
#include "memory/paging_util.h"
uint64_t UserStackManager::NewUserStack() {
if (!freed_stacks_.empty()) {
return freed_stacks_.PopFront();
}
next_stack_ -= kUserStackSize;
uint64_t stack = next_stack_;
if (stack <= kUserStackMin) {
panic("Out of user stacks!");
}
return stack;
}
void UserStackManager::FreeUserStack(uint64_t stack_base) {
if (stack_base & (kUserStackSize - 1)) {
dbgln("WARN freeing unaligned user stack {x}", stack_base);
}
freed_stacks_.PushBack(stack_base);
}