[Zion] Plumb user stack to free function on thread exit.

This commit is contained in:
Drew Galbraith 2023-11-23 07:12:23 -08:00
parent 941d7c8d59
commit 84e1b4cdb4
4 changed files with 11 additions and 4 deletions

View File

@ -22,6 +22,10 @@ uint64_t AddressSpace::AllocateUserStack() {
return user_stacks_.NewUserStack();
}
void AddressSpace::FreeUserStack(uint64_t rsp) {
return user_stacks_.FreeUserStack(rsp);
}
uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) {
if (size == 0) {
panic("Zero size memmap");

View File

@ -66,6 +66,7 @@ class AddressSpace : public KernelObject {
// User Mappings.
uint64_t AllocateUserStack();
void FreeUserStack(uint64_t);
uint64_t GetNextMemMapAddr(uint64_t size);
// Maps in a memory object at a specific address.

View File

@ -67,14 +67,14 @@ void Thread::Init() {
#if K_THREAD_DEBUG
dbgln("Thread start.", pid(), id_);
#endif
uint64_t rsp = process_.vmas()->AllocateUserStack();
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;
rsp_ -= 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::Exit() {
@ -102,6 +102,7 @@ void Thread::Cleanup() {
// TODO: Race condition when called from exit, once kernel stack manager
// actually reuses stacks this will cause an issue
KernelVmm::FreeKernelStack(rsp0_start_);
process_.vmas()->FreeUserStack(rsp_);
}
void Thread::Wait() {

View File

@ -77,6 +77,7 @@ class Thread : public KernelObject, public glcr::IntrusiveListNode<Thread> {
State state_ = CREATED;
// Startup Context for the thread.
uint64_t rsp_;
uint64_t rip_;
uint64_t arg1_;
uint64_t arg2_;