add a class to allocate and manage user space stacks
This commit is contained in:
parent
1db93e5b12
commit
2eefda6114
6 changed files with 67 additions and 7 deletions
23
zion/memory/user_stack_manager.cpp
Normal file
23
zion/memory/user_stack_manager.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "memory/user_stack_manager.h"
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "memory/paging_util.h"
|
||||
|
||||
uint64_t UserStackManager::NewUserStack() {
|
||||
uint64_t stack = next_stack_;
|
||||
next_stack_ -= kStackSize;
|
||||
if (stack <= kStackMin) {
|
||||
panic("Out of user stacks!");
|
||||
}
|
||||
if (stack == kStackMax) {
|
||||
// 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_++;
|
||||
dbgln("%u freed user stacks", freed_stacks_);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue