From 15bc439577c49e97c24a074fe6d9e9464f917054 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 26 Apr 2024 15:42:01 +0200 Subject: Kernel: Handle userspace memory errors instead of crashing. The kernel should kill the process if it has memory issues. --- kernel/cpu/idt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'kernel/cpu/idt.c') diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c index 9508f8c..acede33 100644 --- a/kernel/cpu/idt.c +++ b/kernel/cpu/idt.c @@ -76,6 +76,13 @@ void page_fault(reg_t *regs) { process_pop_restore_context(NULL, regs); return; } + + int is_userspace = (regs->error_code & (1 << 2)); + if (is_userspace) { + signal_process(current_task, SIGSEGV); + return; + } + klog("Page Fault", LOG_ERROR); kprintf("CR2: %x\n", cr2); if (current_task) { @@ -97,15 +104,11 @@ void page_fault(reg_t *regs) { kprintf("read access\n"); } - if (regs->error_code & (1 << 2)) { - kprintf("CPL = 3\n"); - } - if (regs->error_code & (1 << 4)) { kprintf("Attempted instruction fetch\n"); } - dump_backtrace(20); + dump_backtrace(15); halt(); } -- cgit v1.2.3