[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.
This commit is contained in:
Drew Galbraith 2023-11-24 16:51:35 -08:00
parent ba1b4df702
commit 2dd69f5844
6 changed files with 29 additions and 42 deletions

View file

@ -72,14 +72,15 @@ void Thread::Init() {
#if K_THREAD_DEBUG
dbgln("Thread start.", pid(), id_);
#endif
uint64_t rsp_ = process_.vmas()->AllocateUserStack();
// TODO: Investigate this further but without this GCC
// will emit movaps calls to non-16-bit-aligned stack
// addresses.
rsp_ -= 0x8;
*reinterpret_cast<uint64_t*>(rsp_) = kStackBaseSentinel;
auto stack_or = process_.vmas()->AllocateUserStack();
if (!stack_or.ok()) {
panic("Unable to allocate user stack: {}", stack_or.error());
}
user_stack_base_ = stack_or.value();
uint64_t rsp = user_stack_base_ + kUserStackSize - 0x8;
*reinterpret_cast<uint64_t*>(rsp) = kStackBaseSentinel;
SetRsp0(rsp0_start_);
jump_user_space(rip_, rsp_, arg1_, arg2_);
jump_user_space(rip_, rsp, arg1_, arg2_);
}
void Thread::SetState(State state) {
if (IsDying()) {
@ -113,7 +114,8 @@ void Thread::Cleanup() {
}
// 1. Release User Stack
process_.vmas()->FreeUserStack(rsp_);
PANIC_ON_ERR(process_.vmas()->FreeUserStack(user_stack_base_),
"Unable to free user stack.");
// 2. Unblock waiting threads.
while (blocked_threads_.size() != 0) {