Fix freeing squattedCtx when deleting thread

This commit is contained in:
Mathieu Maret 2024-02-27 23:14:09 +01:00
parent 1047400be2
commit dc4c465e94
2 changed files with 6 additions and 5 deletions

View File

@ -53,10 +53,12 @@ void print_handler(struct cpu_state *frame, ulong intr)
void pagefault_handler(struct cpu_state *frame, ulong intr) void pagefault_handler(struct cpu_state *frame, ulong intr)
{ {
// PAGE_FAULT is a interrupt with an error code (see exception_wrapper.S)
uint32_t error_code = cpu_context_get_EX_err(frame);
struct thread *current = getCurrentThread(); struct thread *current = getCurrentThread();
assert(frame == current->cpuState);
if (cpu_context_is_in_user_mode(current->cpuState)) { if (cpu_context_is_in_user_mode(current->cpuState)) {
assert(frame == current->cpuState); // pagefault in kernel not supported ATM
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);
@ -70,8 +72,6 @@ void pagefault_handler(struct cpu_state *frame, ulong intr)
if (!uAddrSpaceHeapCheckNAlloc(as, faultAddr)) if (!uAddrSpaceHeapCheckNAlloc(as, faultAddr))
goto release_context; 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); int ret = uAddrSpaceSolvePageFault(as, faultAddr, error_code & 0x2);
if (!ret) if (!ret)

View File

@ -165,8 +165,9 @@ void threadDelete(struct thread *thread)
} }
if (thread->squattedContext) { if (thread->squattedContext) {
threadChangeCurrentContext(NULL); mmuContextUnref(thread->squattedContext);
} }
if (thread->process) if (thread->process)
processRemoveThread(thread); processRemoveThread(thread);