#include "idt.h"
#include "io.h"
#include "uart_console.h"
+#include "process.h"
#include "spinlock.h"
#include <stddef.h>
} 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");
enum {
SIGKILL = 9,
+ SIGSEGV = 11,
};
enum {
}
}
+ {
+ 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;