summaryrefslogtreecommitdiff
path: root/kernel/sched/scheduler.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-26 15:42:01 +0200
committerAnton Kling <anton@kling.gg>2024-04-26 15:44:26 +0200
commit15bc439577c49e97c24a074fe6d9e9464f917054 (patch)
tree8a60437726c70f5e046da785db3ea904b282cd66 /kernel/sched/scheduler.c
parentea653dc177eca18291f3081348d6104ac817f763 (diff)
Kernel: Handle userspace memory errors instead of crashing.
The kernel should kill the process if it has memory issues.
Diffstat (limited to 'kernel/sched/scheduler.c')
-rw-r--r--kernel/sched/scheduler.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/kernel/sched/scheduler.c b/kernel/sched/scheduler.c
index 423c1b6..57ab33b 100644
--- a/kernel/sched/scheduler.c
+++ b/kernel/sched/scheduler.c
@@ -216,6 +216,7 @@ void free_process(process_t *p) {
void exit_process(process_t *p, int status) {
disable_interrupts();
+ int killing_itself = (p == current_task);
assert(p->pid != 1);
if (p->parent) {
p->parent->halts[WAIT_CHILD_HALT] = 0;
@@ -246,6 +247,9 @@ void exit_process(process_t *p, int status) {
}
tmp = tmp->next;
}
+ if (killing_itself) {
+ switch_task();
+ }
}
void exit(int status) {
@@ -474,9 +478,14 @@ void signal_process(process_t *p, int sig) {
if (SIGTERM == sig) {
kprintf("HAS NO SIGTERM\n");
exit_process(p, 1 /*TODO: what should the status be?*/);
+ ASSERT_NOT_REACHED;
+ } else if (SIGSEGV == sig) {
+ kprintf("HAS NO SIGSEGV\n");
+ exit_process(p, 1 /*TODO: what should the status be?*/);
+ ASSERT_NOT_REACHED;
} else {
// TODO: Should also exit proess(I think)
- assert(0);
+ ASSERT_NOT_REACHED;
}
}
signal_t signal = {.handler_ip = (uintptr_t)p->signal_handlers[sig]};