summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/init/main.c10
-rw-r--r--src/kernel/syscalls.c10
-rw-r--r--src/kernel/syscalls.h2
3 files changed, 19 insertions, 3 deletions
diff --git a/src/init/main.c b/src/init/main.c
index 33a4372..84475da 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -4,6 +4,11 @@
int _syscall(int, int, int, int);
+void exit(const char *msg, size_t len) {
+ _syscall(SC_EXIT, (void*)msg, len, 0);
+ __builtin_unreachable();
+}
+
int debuglog(const char *msg, size_t len) {
return _syscall(SC_DEBUGLOG, (void*)msg, len, 0);
}
@@ -13,7 +18,6 @@ int main() {
debuglog("hello from init! ",
sizeof("hello from init! ") - 1);
- // try to mess with kernel memory
- uint8_t *kernel = (void*) 0x100000;
- *kernel = 0; // should segfault
+ exit( "bye from init! ",
+ sizeof("bye from init! ") - 1);
}
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 24706d3..1bc1a44 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -4,6 +4,13 @@
#include <kernel/syscalls.h>
#include <stdint.h>
+int sc_exit(const char *msg, size_t len) {
+ // the message is currently ignored
+
+ log_const("last process returned. ");
+ panic();
+}
+
int sc_debuglog(const char *msg, size_t len) {
struct pagedir *pages = process_current->pages;
void *phys = pagedir_virt2phys(pages, msg, true, false);
@@ -23,6 +30,9 @@ int syscall_handler(int num, int a, int b, int c, void *stack, void *eip) {
process_current->eip = eip;
switch (num) {
+ case SC_EXIT:
+ sc_exit((void*)a, b);
+ panic(); // sc_exit should never return
case SC_DEBUGLOG:
return sc_debuglog((void*)a, b);
default:
diff --git a/src/kernel/syscalls.h b/src/kernel/syscalls.h
index 39db6a9..a249046 100644
--- a/src/kernel/syscalls.h
+++ b/src/kernel/syscalls.h
@@ -2,5 +2,7 @@
// not caring about stable syscall numbers just yet
enum {
+ SC_EXIT,
+
SC_DEBUGLOG
};