summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/proc.c10
-rw-r--r--src/kernel/proc.h1
-rw-r--r--src/kernel/syscalls.c12
3 files changed, 14 insertions, 9 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index bdd92ba..e1b650c 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -1,5 +1,6 @@
#include <kernel/arch/generic.h>
#include <kernel/mem.h>
+#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/util.h>
#include <stdint.h>
@@ -54,6 +55,15 @@ void process_switch(struct process *proc) {
sysexit(proc->regs);
}
+_Noreturn void process_switch_any() {
+ struct process *found = process_find(PS_RUNNING);
+ if (found)
+ process_switch(found);
+
+ tty_const(" no running processes left...");
+ panic();
+}
+
// TODO there's no check for going past the stack - VULN
struct process *_process_find_recursive(
enum process_state target, struct process *iter) {
diff --git a/src/kernel/proc.h b/src/kernel/proc.h
index 2f39f2e..c2dfde4 100644
--- a/src/kernel/proc.h
+++ b/src/kernel/proc.h
@@ -34,5 +34,6 @@ extern struct process *process_current;
struct process *process_seed();
struct process *process_fork(struct process *parent);
_Noreturn void process_switch(struct process *proc);
+_Noreturn void process_switch_any(); // switches to any running process
struct process *process_find(enum process_state);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index b6eede6..2b3dafc 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -36,8 +36,7 @@ _Noreturn void _syscall_exit(const char *msg, size_t len) {
if (process_current)
process_switch(process_current);
- tty_const("last process returned. ");
- panic();
+ process_switch_any();
}
int _syscall_await(char *buf, int len) {
@@ -55,13 +54,8 @@ int _syscall_await(char *buf, int len) {
// no dead children yet
// TODO check if the process even has children
-
- process_current = process_find(PS_RUNNING);
- if (process_current)
- process_switch(process_current);
-
- tty_const("this error will be fixed in the next commit."); // TODO
- panic();
+
+ process_switch_any();
}
int _syscall_fork() {