Unverified Commit 68d07bdf authored by PhoeniX's avatar PhoeniX

Fix stack-related exception on process exit

parent 05d9ba75
Pipeline #1847 passed with stages
in 31 seconds
......@@ -17,11 +17,14 @@ static void syscall_puts(uintptr_t strptr) {
static void syscall_exit(int code) {
ProcessManager *manager = ProcessManager::getManager();
Process *process = manager->currentProcess();
void *rsp; asm volatile("mov %%rsp, %q0; and $~0xFFF, %q0":"=r"(rsp));
Pagetable::Entry *pt; asm volatile("mov %%cr3, %q0":"=r"(pt));
Pagetable::Entry *pte = Pagetable::Entry::find(rsp, pt);
asm volatile(
"callq _ZN7Process4exitEi;"
"sti;"
"sti; movq $0, %q2;"
"jmp _ZN14ProcessManager12process_loopEv"
::"D"(process), "S"(code)
::"D"(process), "S"(code), "a"(pte)
);
}
......
......@@ -16,6 +16,7 @@ Process::Process() {
_aslrStack = RAND::get<uintptr_t>(0x40000000llu, 0x80000000llu) << 12;
}
Process::~Process() {
void *rsp; asm volatile("mov %%rsp, %q0; and $~0xFFF, %q0":"=r"(rsp));
if (pagetable != nullptr) {
PTE addr;
for (uintptr_t ptx = 0; ptx < 512; ptx++) {
......@@ -38,10 +39,11 @@ Process::~Process() {
if (!addr.present)
continue;
void *page = addr.getPtr();
if (uintptr_t(page) == ((ptx << (12 + 9 + 9 + 9))
uintptr_t ptaddr = ((ptx << (12 + 9 + 9 + 9))
| (pdx << (12 + 9 + 9))
| (pdpx << (12 + 9)) | (pml4x << (12))))
continue;
| (pdpx << (12 + 9)) | (pml4x << (12)));
if (page == rsp) continue;
if (uintptr_t(page) == ptaddr) continue;
Pagetable::free(page);
}
Pagetable::free(ppml4e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment