summaryrefslogtreecommitdiff
path: root/kernel/cpu/idt.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/cpu/idt.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/cpu/idt.c')
-rw-r--r--kernel/cpu/idt.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c
index 9508f8c..acede33 100644
--- a/kernel/cpu/idt.c
+++ b/kernel/cpu/idt.c
@@ -76,6 +76,13 @@ void page_fault(reg_t *regs) {
process_pop_restore_context(NULL, regs);
return;
}
+
+ int is_userspace = (regs->error_code & (1 << 2));
+ if (is_userspace) {
+ signal_process(current_task, SIGSEGV);
+ return;
+ }
+
klog("Page Fault", LOG_ERROR);
kprintf("CR2: %x\n", cr2);
if (current_task) {
@@ -97,15 +104,11 @@ void page_fault(reg_t *regs) {
kprintf("read access\n");
}
- if (regs->error_code & (1 << 2)) {
- kprintf("CPL = 3\n");
- }
-
if (regs->error_code & (1 << 4)) {
kprintf("Attempted instruction fetch\n");
}
- dump_backtrace(20);
+ dump_backtrace(15);
halt();
}