2023-05-30 22:35:57 -07:00
|
|
|
#include "memory/user_stack_manager.h"
|
|
|
|
|
|
|
|
#include "debug/debug.h"
|
|
|
|
#include "memory/paging_util.h"
|
|
|
|
|
|
|
|
uint64_t UserStackManager::NewUserStack() {
|
2023-11-24 16:16:25 -08:00
|
|
|
if (!freed_stacks_.empty()) {
|
|
|
|
return freed_stacks_.PopFront();
|
|
|
|
}
|
|
|
|
|
|
|
|
next_stack_ -= kUserStackSize;
|
2023-11-24 16:51:35 -08:00
|
|
|
uint64_t stack = next_stack_;
|
2023-11-24 16:16:25 -08:00
|
|
|
if (stack <= kUserStackMin) {
|
2023-05-30 22:35:57 -07:00
|
|
|
panic("Out of user stacks!");
|
|
|
|
}
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2023-11-24 16:51:35 -08:00
|
|
|
void UserStackManager::FreeUserStack(uint64_t stack_base) {
|
|
|
|
if (stack_base & (kUserStackSize - 1)) {
|
|
|
|
dbgln("WARN freeing unaligned user stack {x}", stack_base);
|
2023-06-12 23:28:23 -07:00
|
|
|
}
|
2023-11-24 16:51:35 -08:00
|
|
|
freed_stacks_.PushBack(stack_base);
|
2023-06-12 23:28:23 -07:00
|
|
|
}
|