From: Tulio A M Mendes Date: Sun, 8 Feb 2026 03:56:13 +0000 (-0300) Subject: x86: treat user page fault as SIGSEGV X-Git-Url: https://projects.tadryanom.me/sitemap.xml?a=commitdiff_plain;h=444aae5afb4209745222971718d6726b8c18aeab;p=AdrOS.git x86: treat user page fault as SIGSEGV Handle ISR14 page faults from ring3 by terminating the current process with a SIGSEGV-like status (128+11) instead of kernel panic. Add userland smoke test that triggers a NULL write and validates waitpid status. --- diff --git a/src/arch/x86/idt.c b/src/arch/x86/idt.c index 9db3e06..aa0d257 100644 --- a/src/arch/x86/idt.c +++ b/src/arch/x86/idt.c @@ -1,6 +1,7 @@ #include "idt.h" #include "io.h" #include "uart_console.h" +#include "process.h" #include "spinlock.h" #include @@ -171,6 +172,17 @@ void isr_handler(struct registers* regs) { } else { // If Exception (0-31), Panic if (regs->int_no < 32) { + if (regs->int_no == 14) { + // If page fault came from ring3, treat it as a SIGSEGV-like fatal event. + if ((regs->cs & 3U) == 3U) { + const int SIG_SEGV = 11; + process_exit_notify(128 + SIG_SEGV); + __asm__ volatile("sti"); + schedule(); + for (;;) __asm__ volatile("hlt"); + } + } + __asm__ volatile("cli"); // Stop everything uart_print("\n\n!!! KERNEL PANIC !!!\n"); diff --git a/user/init.c b/user/init.c index aa7b77b..0d74559 100644 --- a/user/init.c +++ b/user/init.c @@ -35,6 +35,7 @@ enum { enum { SIGKILL = 9, + SIGSEGV = 11, }; enum { @@ -823,6 +824,32 @@ void _start(void) { } } + { + int pid = sys_fork(); + if (pid < 0) { + static const char msg[] = "[init] sigsegv test fork failed\n"; + (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); + sys_exit(1); + } + + if (pid == 0) { + volatile uint32_t* p = (volatile uint32_t*)0; + *p = 1; + sys_exit(1); + } + + int st = 0; + int wp = sys_waitpid(pid, &st, 0); + if (wp == pid && st == (128 + SIGSEGV)) { + static const char msg[] = "[init] SIGSEGV OK\n"; + (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); + } else { + static const char msg[] = "[init] SIGSEGV failed\n"; + (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); + sys_exit(1); + } + } + int ok = 1; for (int i = 0; i < NCHILD; i++) { int st = 0;