[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(); return user_stacks_.NewUserStack();
} }
void AddressSpace::FreeUserStack(uint64_t rsp) {
return user_stacks_.FreeUserStack(rsp);
}
uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) { uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) {
if (size == 0) { if (size == 0) {
panic("Zero size memmap"); panic("Zero size memmap");

View File

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

View File

@ -67,14 +67,14 @@ void Thread::Init() {
#if K_THREAD_DEBUG #if K_THREAD_DEBUG
dbgln("Thread start.", pid(), id_); dbgln("Thread start.", pid(), id_);
#endif #endif
uint64_t rsp = process_.vmas()->AllocateUserStack(); uint64_t rsp_ = process_.vmas()->AllocateUserStack();
// TODO: Investigate this further but without this GCC // TODO: Investigate this further but without this GCC
// will emit movaps calls to non-16-bit-aligned stack // will emit movaps calls to non-16-bit-aligned stack
// addresses. // addresses.
rsp -= 0x8; rsp_ -= 0x8;
*reinterpret_cast<uint64_t*>(rsp) = kStackBaseSentinel; *reinterpret_cast<uint64_t*>(rsp_) = kStackBaseSentinel;
SetRsp0(rsp0_start_); SetRsp0(rsp0_start_);
jump_user_space(rip_, rsp, arg1_, arg2_); jump_user_space(rip_, rsp_, arg1_, arg2_);
} }
void Thread::Exit() { void Thread::Exit() {
@ -102,6 +102,7 @@ void Thread::Cleanup() {
// TODO: Race condition when called from exit, once kernel stack manager // TODO: Race condition when called from exit, once kernel stack manager
// actually reuses stacks this will cause an issue // actually reuses stacks this will cause an issue
KernelVmm::FreeKernelStack(rsp0_start_); KernelVmm::FreeKernelStack(rsp0_start_);
process_.vmas()->FreeUserStack(rsp_);
} }
void Thread::Wait() { void Thread::Wait() {

View File

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