Fix MMU context on ressource checking

This commit is contained in:
Mathieu Maret 2024-02-07 23:14:42 +01:00 committed by Mathieu Maret
parent b5df821b8b
commit 5cc0ef0317

View File

@ -57,18 +57,25 @@ void pagefault_handler(struct cpu_state *frame, ulong intr)
struct thread *current = getCurrentThread();
assert(frame == current->cpuState);
if (cpu_context_is_in_user_mode(current->cpuState)) {
struct uAddrSpace *as = processGetAddrSpace(current->process);
vaddr_t faultAddr = cpu_context_get_EX_faulting_vaddr(frame);
int needMMUSetup =
(uAddrSpaceGetMMUContext(as) != getCurrentThread()->squattedContext);
if (needMMUSetup) {
threadChangeCurrentContext(uAddrSpaceGetMMUContext(as));
}
if (!uAddrSpaceHeapCheckNAlloc(as, faultAddr))
return;
goto release_context;
// PAGE_FAULT is a interrupt with an error code (see exception_wrapper.S)
uint32_t error_code = cpu_context_get_EX_err(frame);
int ret = uAddrSpaceSolvePageFault(as, faultAddr, error_code & 0x2);
if (!ret){
return;
}
int ret = uAddrSpaceSolvePageFault(as, faultAddr, error_code & 0x2);
if (!ret)
goto release_context;
printf(
"page fault while in thread [%s] at 0x%p when trying to access 0x%p err_code 0x%x ressource ret %d\n",
@ -76,10 +83,15 @@ void pagefault_handler(struct cpu_state *frame, ulong intr)
ret);
printf("Killing User Thread\n");
threadExit();
release_context:
if (needMMUSetup)
threadChangeCurrentContext(NULL);
return;
}
VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", intr);
(void)intr;
for (;;)
continue;
}