From dc4c465e946a8f17729c2cb7177a5fee95bb5217 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Tue, 27 Feb 2024 23:14:09 +0100 Subject: [PATCH] Fix freeing squattedCtx when deleting thread --- arch/x86/exception.c | 8 ++++---- core/thread.c | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/exception.c b/arch/x86/exception.c index 512f8c5..61f5616 100644 --- a/arch/x86/exception.c +++ b/arch/x86/exception.c @@ -53,10 +53,12 @@ void print_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(); - assert(frame == 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); 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)) 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) diff --git a/core/thread.c b/core/thread.c index 2f74f01..6e78c12 100644 --- a/core/thread.c +++ b/core/thread.c @@ -165,8 +165,9 @@ void threadDelete(struct thread *thread) } if (thread->squattedContext) { - threadChangeCurrentContext(NULL); + mmuContextUnref(thread->squattedContext); } + if (thread->process) processRemoveThread(thread);