mmap #8

Merged
mathieu merged 22 commits from mmap into master 2024-02-11 15:29:59 +01:00
Showing only changes of commit 5a2042e577 - Show all commits

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;
}
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;
}