syscall: change handling of exceptions and traps
This commit is contained in:
parent
b595652ef4
commit
0a0235612e
5 changed files with 59 additions and 18 deletions
17
dev/pic.c
17
dev/pic.c
|
|
@ -32,23 +32,6 @@ void pic_eoi(uint8_t irq)
|
|||
outb(PIC1_CMD, 0x20);
|
||||
}
|
||||
|
||||
void exception(int vector, int error)
|
||||
{
|
||||
kprintf(LOG_WARN "EXCEPTION: %x, error code: %d\n", vector, error);
|
||||
pid_t pid = getpid();
|
||||
|
||||
struct proc *proc = proc_find(pid);
|
||||
|
||||
if (proc->is_kernel) {
|
||||
kprintf(LOG_ERROR "Kernel process %d crashed\n", pid);
|
||||
panic();
|
||||
} else {
|
||||
proc_term(pid);
|
||||
kprintf(LOG_WARN "Process %d terminated\n", pid);
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
void pic_init()
|
||||
{
|
||||
/* disable the PIC */
|
||||
|
|
|
|||
|
|
@ -60,5 +60,6 @@ void proc_term(pid_t pid);
|
|||
struct proc *proc_find(pid_t pid);
|
||||
void proc_set_current(pid_t pid);
|
||||
void proc_init(unsigned num_cpus);
|
||||
void schedule();
|
||||
|
||||
#endif /* _PROC_H_ */
|
||||
|
|
|
|||
56
init/trap.c
Normal file
56
init/trap.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/proc.h>
|
||||
|
||||
static const char *exception_names[] = {
|
||||
"Divide-by-zero Error",
|
||||
"Debug",
|
||||
"Non-maskable Interrupt",
|
||||
"Breakpoint",
|
||||
"Overflow",
|
||||
"Bound Range Exceeded",
|
||||
"Invalid Opcode",
|
||||
"Device Not Available",
|
||||
"Double Fault",
|
||||
"Coprocessor Segment Overrun",
|
||||
"Invalid TSS",
|
||||
"Segment Not Present",
|
||||
"Stack-Segment Fault",
|
||||
"General Protection Fault",
|
||||
"Page Fault",
|
||||
"Reserved",
|
||||
"x87 Floating-Point Exception",
|
||||
"Alignment Check",
|
||||
"Machine Check",
|
||||
"SIMD Floating-Point Exception",
|
||||
"Virtualization Exception",
|
||||
"Invalid exception",
|
||||
"Invalid exception",
|
||||
"Invalid exception",
|
||||
"Invalid exception",
|
||||
"Invalid exception",
|
||||
"Invalid exception",
|
||||
"Invalid exception",
|
||||
"Security Exception",
|
||||
"Reserved",
|
||||
"Triple Fault",
|
||||
};
|
||||
|
||||
void exception(int vector, int error)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
|
||||
struct proc *proc = proc_find(pid);
|
||||
|
||||
if (proc->is_kernel) {
|
||||
kprintf(LOG_ERROR "Kernel process %d crashed: %s(%xh)\n", pid, exception_names[vector], error);
|
||||
panic();
|
||||
} else {
|
||||
proc_term(pid);
|
||||
kprintf("Process %d terminated: %s(%xh)\n", pid, exception_names[vector], error);
|
||||
proc_set_current(0);
|
||||
|
||||
schedule();
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ gate_syscall:
|
|||
movq 40(%rax), %rsi /* arguments */
|
||||
|
||||
call syscall
|
||||
call schedule
|
||||
iretq
|
||||
|
||||
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */
|
||||
.global _return_to_user
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ void sys_exit(int status)
|
|||
kprintf("(syscall)Process %d exited with status 0x%x\n", getpid(), status);
|
||||
|
||||
proc_set_current(0);
|
||||
schedule();
|
||||
}
|
||||
|
||||
static void syscall_insert(uint64_t syscall_no, syscall_t syscall)
|
||||
|
|
|
|||
Loading…
Reference in a new issue