forked from Bananymous/banan-os
Kernel: ISR will now crash userspace process instead of panicing kernel
This commit is contained in:
parent
636c308993
commit
0202ccec5f
|
@ -6,6 +6,8 @@
|
|||
#include <kernel/Process.h>
|
||||
#include <kernel/Scheduler.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define REGISTER_ISR_HANDLER(i) register_interrupt_handler(i, isr ## i)
|
||||
#define REGISTER_IRQ_HANDLER(i) register_interrupt_handler(IRQ_VECTOR_BASE + i, irq ## i)
|
||||
|
||||
|
@ -99,19 +101,30 @@ namespace IDT
|
|||
|
||||
extern "C" void cpp_isr_handler(uint64_t isr, uint64_t error, const Registers* regs)
|
||||
{
|
||||
Kernel::panic(
|
||||
dwarnln(
|
||||
"{} (error code: 0x{16H}), pid {}, tid {}\r\n"
|
||||
"Register dump\r\n"
|
||||
"rax=0x{16H}, rbx=0x{16H}, rcx=0x{16H}, rdx=0x{16H}\r\n"
|
||||
"rsp=0x{16H}, rbp=0x{16H}, rdi=0x{16H}, rsi=0x{16H}\r\n"
|
||||
"rip=0x{16H}, rflags=0x{16H}\r\n"
|
||||
"cr0=0x{16H}, cr2=0x{16H}, cr3=0x{16H}, cr4=0x{16H}\r\n",
|
||||
"cr0=0x{16H}, cr2=0x{16H}, cr3=0x{16H}, cr4=0x{16H}",
|
||||
isr_exceptions[isr], error, Kernel::Process::current().pid(), Kernel::Thread::current().tid(),
|
||||
regs->rax, regs->rbx, regs->rcx, regs->rdx,
|
||||
regs->rsp, regs->rbp, regs->rdi, regs->rsi,
|
||||
regs->rip, regs->rflags,
|
||||
regs->cr0, regs->cr2, regs->cr3, regs->cr4
|
||||
);
|
||||
|
||||
if (Kernel::Thread::current().is_userspace() && !Kernel::Thread::current().is_in_syscall())
|
||||
{
|
||||
auto message = BAN::String::formatted("{}, aborting\n", isr_exceptions[isr]);
|
||||
(void)Kernel::Process::current().write(STDERR_FILENO, message.data(), message.size());
|
||||
Kernel::Process::current().exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
Kernel::panic("Unhandled exception");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void cpp_irq_handler(uint64_t irq)
|
||||
|
|
|
@ -58,6 +58,9 @@ namespace Kernel
|
|||
|
||||
void set_in_syscall(bool b) { m_in_syscall = b; }
|
||||
|
||||
bool is_userspace() const { return m_is_userspace; }
|
||||
bool is_in_syscall() const { return m_in_syscall; }
|
||||
|
||||
private:
|
||||
Thread(pid_t tid, Process*);
|
||||
void on_exit();
|
||||
|
|
Loading…
Reference in New Issue