summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/arch/i386/boot.c2
-rw-r--r--src/kernel/arch/i386/interrupts/isr.c4
-rw-r--r--src/kernel/main.c1
-rw-r--r--src/kernel/panic.h10
-rw-r--r--src/kernel/proc.c2
-rw-r--r--src/kernel/syscalls.c4
-rw-r--r--src/kernel/tests/main.c2
-rw-r--r--src/kernel/vfs/request.c7
-rw-r--r--src/kernel/vfs/root.c4
9 files changed, 20 insertions, 16 deletions
diff --git a/src/kernel/arch/i386/boot.c b/src/kernel/arch/i386/boot.c
index 57f8ff5..94eefd6 100644
--- a/src/kernel/arch/i386/boot.c
+++ b/src/kernel/arch/i386/boot.c
@@ -19,7 +19,7 @@ void kmain_early(struct multiboot_info *multiboot) {
struct multiboot_mod *module = &multiboot->mods[0];
if (multiboot->mods_count < 1) {
tty_const("can't find init! ");
- panic();
+ panic_invalid_state(); // no init
}
info.init.at = module->start;
info.init.size = module->end - module->start;
diff --git a/src/kernel/arch/i386/interrupts/isr.c b/src/kernel/arch/i386/interrupts/isr.c
index 86f697f..1ca6da9 100644
--- a/src/kernel/arch/i386/interrupts/isr.c
+++ b/src/kernel/arch/i386/interrupts/isr.c
@@ -4,7 +4,7 @@
#include <stdbool.h>
#include <stdint.h>
-#define log_n_panic(x) {tty_const(x); panic();}
+#define log_n_panic(x) {tty_const(x); panic_unimplemented();} // TODO kill the current process instead of panicking
bool isr_test_interrupt_called = false;
@@ -17,7 +17,7 @@ void isr_stage3(int interrupt) {
tty_const("#PF at ");
asm ("mov %%cr2, %0;" : "=r"(cr2) ::);
_tty_var(cr2);
- panic();
+ panic_unimplemented();
}
case 0x34:
diff --git a/src/kernel/main.c b/src/kernel/main.c
index e96de1c..425b417 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -1,7 +1,6 @@
#include <kernel/arch/generic.h>
#include <kernel/main.h>
#include <kernel/mem/alloc.h>
-#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/tests/tests.h>
#include <kernel/util.h>
diff --git a/src/kernel/panic.h b/src/kernel/panic.h
index 9407e44..b62c630 100644
--- a/src/kernel/panic.h
+++ b/src/kernel/panic.h
@@ -2,11 +2,15 @@
#include <kernel/arch/generic.h>
#include <kernel/util.h>
-#define panic() do { \
- tty_const(" PANIC! at the "); \
+#define _panic(type) do { \
+ tty_const(" an "type" PANIC! at the "); \
tty_const(__func__); \
tty_const(" (" __FILE__ ":" NUM2STR(__LINE__) ") "); \
halt_cpu(); \
} while (0)
-#define assert(stmt) do { if (!(stmt)) panic(); } while (0)
+#define panic_invalid_state() _panic("invalid state")
+#define panic_unimplemented() _panic("unimplemented")
+#define assert(stmt) do { if (!(stmt)) _panic(); } while (0)
+
+#undef panic
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 39b4fb0..df20df3 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -67,7 +67,7 @@ _Noreturn void process_switch_any(void) {
process_switch(found);
mem_debugprint();
- panic();
+ panic_unimplemented(); // TODO shutdown();
}
// TODO there's no check for going past the stack - VULN
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index d321d33..39cad3a 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -259,7 +259,7 @@ int _syscall_fs_respond(char __user *buf, int ret) {
int _syscall_memflag(void __user *addr, size_t len, int flags) {
userptr_t goal = addr + len;
struct pagedir *pages = process_current->pages;
- if (flags != MEMFLAG_PRESENT) panic(); // currently only allocation is implemented
+ if (flags != MEMFLAG_PRESENT) panic_unimplemented(); // TODO
addr = (userptr_t)((int)addr & ~PAGE_MASK); // align to page boundary
for (; addr < goal; addr += PAGE_SIZE) {
@@ -303,6 +303,6 @@ int _syscall(int num, int a, int b, int c, int d) {
return _syscall_memflag((userptr_t)a, b, c);
default:
tty_const("unknown syscall ");
- panic();
+ panic_unimplemented(); // TODO fail gracefully
}
}
diff --git a/src/kernel/tests/main.c b/src/kernel/tests/main.c
index aed7d6a..f9c9413 100644
--- a/src/kernel/tests/main.c
+++ b/src/kernel/tests/main.c
@@ -11,5 +11,5 @@ void tests_all(void) {
tests_vfs();
if (_did_tests_fail)
- panic();
+ panic_invalid_state();
}
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index b197f4b..fcd6c47 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -33,7 +33,7 @@ int vfs_request_create(struct vfs_request req_) {
vfs_request_pass2handler(req);
}
default:
- panic();
+ panic_invalid_state();
}
}
@@ -75,7 +75,7 @@ _Noreturn void vfs_request_pass2handler(struct vfs_request *req) {
regs_savereturn(&handler->regs, req->type);
process_switch(handler);
fail:
- panic(); // TODO
+ panic_unimplemented(); // TODO
}
int vfs_request_finish(struct vfs_request *req, int ret) {
@@ -84,7 +84,8 @@ int vfs_request_finish(struct vfs_request *req, int ret) {
// we need to wrap the id returned by the VFS in a handle passed to
// the client
handle_t handle = process_find_handle(req->caller);
- if (handle < 0) panic();
+ if (handle < 0)
+ panic_invalid_state(); // we check for free handles before the open() call
req->caller->handles[handle] = (struct handle){
.type = HANDLE_FILE,
.file = {
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c
index 6fcfc08..dca81d2 100644
--- a/src/kernel/vfs/root.c
+++ b/src/kernel/vfs/root.c
@@ -25,8 +25,8 @@ int vfs_root_handler(struct vfs_request *req) {
tty_write(iter.frag, iter.frag_len);
return iter.prior;
}
- default: panic();
+ default: panic_invalid_state();
}
- default: panic();
+ default: panic_unimplemented(); // TODO
}
}