diff options
author | dzwdz | 2021-10-05 20:57:01 +0200 |
---|---|---|
committer | dzwdz | 2021-10-05 20:57:01 +0200 |
commit | 8d3ef773f8daea3a0c2b110ab48f235f5d2bf22d (patch) | |
tree | 7e21974cf6eb51439ac402902f92c418e72d3863 /src | |
parent | bb2c65663dd03aaf1948c36c7e6006af7e3840a6 (diff) |
kill the process that caused an exception instead of panicking
Diffstat (limited to 'src')
-rw-r--r-- | src/init/main.c | 13 | ||||
-rw-r--r-- | src/kernel/arch/i386/interrupts/isr.c | 27 |
2 files changed, 32 insertions, 8 deletions
diff --git a/src/init/main.c b/src/init/main.c index 71a2d4e..ec6d5be 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -85,9 +85,22 @@ void fs_test(void) { void test_await(void) { int ret; + // regular exit()s if (!_syscall_fork()) _syscall_exit(69); if (!_syscall_fork()) _syscall_exit(420); + // faults + if (!_syscall_fork()) { // invalid memory access + asm volatile("movb $69, 0" ::: "memory"); + log("this shouldn't happen"); + _syscall_exit(-1); + } + if (!_syscall_fork()) { // #GP + asm volatile("hlt" ::: "memory"); + log("this shouldn't happen"); + _syscall_exit(-1); + } + while ((ret = _syscall_await()) != ~0) { log("await returned: "); //_syscall_write(tty_fd, buf, len, 0); TODO printf diff --git a/src/kernel/arch/i386/interrupts/isr.c b/src/kernel/arch/i386/interrupts/isr.c index dacecba..6701d58 100644 --- a/src/kernel/arch/i386/interrupts/isr.c +++ b/src/kernel/arch/i386/interrupts/isr.c @@ -1,29 +1,40 @@ #include <kernel/arch/i386/interrupts/isr.h> #include <kernel/arch/io.h> #include <kernel/panic.h> +#include <kernel/proc.h> #include <stdbool.h> #include <stdint.h> -#define log_n_panic(x) {tty_const(x); panic_unimplemented();} // TODO kill the current process instead of panicking - bool isr_test_interrupt_called = false; +/** Kills the process that caused the exception */ +_Noreturn static void exception_finish(void) { + // TODO check if the exception was in the kernel + process_kill(process_current, 0); // TODO make the return code mean something + process_switch_any(); +} + void isr_stage3(int interrupt) { switch (interrupt) { - case 0x08: log_n_panic("#DF"); // double fault - case 0x0D: log_n_panic("#GP"); // general protection fault + case 0x08: // double fault + tty_const("#DF"); + panic_invalid_state(); + case 0x0D: // general protection fault + exception_finish(); case 0x0E: { // page fault - int cr2; + /*int cr2; tty_const("#PF at "); asm ("mov %%cr2, %0;" : "=r"(cr2) ::); - _tty_var(cr2); - panic_unimplemented(); + _tty_var(cr2);*/ + exception_finish(); } case 0x34: isr_test_interrupt_called = true; return; - default: log_n_panic("unknown interrupt"); + default: + tty_const("unknown interrupt"); + panic_unimplemented(); } } |