Kill usermode process on exceptions.

This commit is contained in:
Alexander Myltsev 2025-01-18 02:46:38 +04:00
parent e8845b5012
commit 4c71e65cc5
2 changed files with 8 additions and 0 deletions

View File

@ -105,6 +105,13 @@ void trap(registers_t *r) {
if (r->int_no < ARRLEN(exception_messages)) { if (r->int_no < ARRLEN(exception_messages)) {
msg = exception_messages[r->int_no]; 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); panic(msg);
} }
} }

1
proc.c
View File

@ -82,6 +82,7 @@ _Noreturn void killproc() {
void* task_stack; void* task_stack;
switchkvm(); switchkvm();
freevm(vm.user_task->pgdir); freevm(vm.user_task->pgdir);
sti();
swtch(&task_stack, vm.kernel_thread); swtch(&task_stack, vm.kernel_thread);
__builtin_unreachable(); __builtin_unreachable();
} }