Fix MMU context on ressource checking
This commit is contained in:
parent
b5df821b8b
commit
5cc0ef0317
@ -57,18 +57,25 @@ void pagefault_handler(struct cpu_state *frame, ulong intr)
|
|||||||
struct thread *current = getCurrentThread();
|
struct thread *current = getCurrentThread();
|
||||||
assert(frame == current->cpuState);
|
assert(frame == current->cpuState);
|
||||||
if (cpu_context_is_in_user_mode(current->cpuState)) {
|
if (cpu_context_is_in_user_mode(current->cpuState)) {
|
||||||
|
|
||||||
struct uAddrSpace *as = processGetAddrSpace(current->process);
|
struct uAddrSpace *as = processGetAddrSpace(current->process);
|
||||||
vaddr_t faultAddr = cpu_context_get_EX_faulting_vaddr(frame);
|
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))
|
if (!uAddrSpaceHeapCheckNAlloc(as, faultAddr))
|
||||||
return;
|
goto release_context;
|
||||||
|
|
||||||
// PAGE_FAULT is a interrupt with an error code (see exception_wrapper.S)
|
// PAGE_FAULT is a interrupt with an error code (see exception_wrapper.S)
|
||||||
uint32_t error_code = cpu_context_get_EX_err(frame);
|
uint32_t error_code = cpu_context_get_EX_err(frame);
|
||||||
int ret = uAddrSpaceSolvePageFault(as, faultAddr, error_code & 0x2);
|
int ret = uAddrSpaceSolvePageFault(as, faultAddr, error_code & 0x2);
|
||||||
if (!ret){
|
|
||||||
return;
|
if (!ret)
|
||||||
}
|
goto release_context;
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
"page fault while in thread [%s] at 0x%p when trying to access 0x%p err_code 0x%x ressource ret %d\n",
|
"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);
|
ret);
|
||||||
printf("Killing User Thread\n");
|
printf("Killing User Thread\n");
|
||||||
threadExit();
|
threadExit();
|
||||||
|
|
||||||
|
release_context:
|
||||||
|
if (needMMUSetup)
|
||||||
|
threadChangeCurrentContext(NULL);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", intr);
|
VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", intr);
|
||||||
(void)intr;
|
|
||||||
for (;;)
|
for (;;)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user