[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:
parent
ba1b4df702
commit
2dd69f5844
6 changed files with 29 additions and 42 deletions
|
|
@ -8,30 +8,17 @@ uint64_t UserStackManager::NewUserStack() {
|
|||
return freed_stacks_.PopFront();
|
||||
}
|
||||
|
||||
uint64_t stack = next_stack_;
|
||||
next_stack_ -= kUserStackSize;
|
||||
uint64_t stack = next_stack_;
|
||||
if (stack <= kUserStackMin) {
|
||||
panic("Out of user stacks!");
|
||||
}
|
||||
if (stack == kUserStackMax) {
|
||||
// Add a additional page boudary between kernel and user space.
|
||||
stack -= 0x1000;
|
||||
}
|
||||
EnsureResident(stack - 1, 1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
void UserStackManager::FreeUserStack(uint64_t stack_ptr) {
|
||||
freed_stacks_.PushBack(stack_ptr);
|
||||
}
|
||||
|
||||
bool UserStackManager::IsValidStack(uint64_t vaddr) {
|
||||
if (vaddr < next_stack_ || vaddr > (kUserStackMax - 0x1000)) {
|
||||
return false;
|
||||
void UserStackManager::FreeUserStack(uint64_t stack_base) {
|
||||
if (stack_base & (kUserStackSize - 1)) {
|
||||
dbgln("WARN freeing unaligned user stack {x}", stack_base);
|
||||
}
|
||||
// Checks if the address is in the first page of the stack.
|
||||
if (vaddr & 0xFF000) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
freed_stacks_.PushBack(stack_base);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,7 @@ class UserStackManager {
|
|||
UserStackManager(const UserStackManager&) = delete;
|
||||
|
||||
uint64_t NewUserStack();
|
||||
void FreeUserStack(uint64_t stack_ptr);
|
||||
|
||||
// Used to check if we should page in this address.
|
||||
bool IsValidStack(uint64_t vaddr);
|
||||
void FreeUserStack(uint64_t stack_base);
|
||||
|
||||
private:
|
||||
uint64_t next_stack_ = kUserStackMax;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue