diff options
| author | Anton Kling <anton@kling.gg> | 2024-04-26 15:42:01 +0200 | 
|---|---|---|
| committer | Anton Kling <anton@kling.gg> | 2024-04-26 15:44:26 +0200 | 
| commit | 15bc439577c49e97c24a074fe6d9e9464f917054 (patch) | |
| tree | 8a60437726c70f5e046da785db3ea904b282cd66 /kernel/cpu | |
| parent | ea653dc177eca18291f3081348d6104ac817f763 (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')
| -rw-r--r-- | kernel/cpu/idt.c | 13 | ||||
| -rw-r--r-- | kernel/cpu/isr.s | 9 | 
2 files changed, 16 insertions, 6 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();  } diff --git a/kernel/cpu/isr.s b/kernel/cpu/isr.s index 8032485..819b22b 100644 --- a/kernel/cpu/isr.s +++ b/kernel/cpu/isr.s @@ -11,6 +11,13 @@      push \num      jmp isr_common_stub  .endm +.macro ISR_ERRCODE num +  .global isr\num +  isr\num: +    cli  +    push \num +    jmp isr_common_stub +.endm  ISR_NOERRCODE 0  ISR_NOERRCODE 1 @@ -26,7 +33,7 @@ ISR_NOERRCODE 10  ISR_NOERRCODE 11  ISR_NOERRCODE 12  ISR_NOERRCODE 13 -ISR_NOERRCODE 14 +ISR_ERRCODE 14  ISR_NOERRCODE 15  ISR_NOERRCODE 16  ISR_NOERRCODE 17 |