From 4c71e65cc595a01226653fc013ab41228fe2d3a5 Mon Sep 17 00:00:00 2001 From: Alexander Myltsev Date: Sat, 18 Jan 2025 02:46:38 +0400 Subject: [PATCH] Kill usermode process on exceptions. --- cpu/idt.c | 7 +++++++ proc.c | 1 + 2 files changed, 8 insertions(+) diff --git a/cpu/idt.c b/cpu/idt.c index ff4d3d8..91d8d02 100644 --- a/cpu/idt.c +++ b/cpu/idt.c @@ -105,6 +105,13 @@ void trap(registers_t *r) { if (r->int_no < ARRLEN(exception_messages)) { msg = exception_messages[r->int_no]; } + if (r->cs & 3) { + // exception from user mode, kill offending process + printk("Exception: "); + printk(msg); + printk("\n"); + killproc(); + } panic(msg); } } diff --git a/proc.c b/proc.c index 851471b..4bacc84 100644 --- a/proc.c +++ b/proc.c @@ -82,6 +82,7 @@ _Noreturn void killproc() { void* task_stack; switchkvm(); freevm(vm.user_task->pgdir); + sti(); swtch(&task_stack, vm.kernel_thread); __builtin_unreachable(); }