Kernel: Hardware exceptions now sends signals to userspace

This commit is contained in:
Bananymous 2023-07-30 14:17:39 +03:00
parent a152d0aac5
commit 5e434f5131
2 changed files with 32 additions and 4 deletions

View File

@ -163,10 +163,33 @@ namespace IDT
if (tid && Kernel::Thread::current().is_userspace() && !Kernel::Thread::current().is_in_syscall()) if (tid && Kernel::Thread::current().is_userspace() && !Kernel::Thread::current().is_in_syscall())
{ {
auto message = BAN::String::formatted("{}, aborting\n", isr_exceptions[isr]); // TODO: Confirm and fix the exception to signal mappings
(void)Kernel::Process::current().sys_write(STDERR_FILENO, message.data(), message.size());
asm volatile("sti"); int signal = 0;
Kernel::Process::current().exit(1); switch (isr)
{
case ISR::DeviceNotAvailable:
case ISR::DivisionError:
case ISR::SIMDFloatingPointException:
case ISR::x87FloatingPointException:
signal = SIGFPE;
break;
case ISR::AlignmentCheck:
signal = SIGBUS;
break;
case ISR::InvalidOpcode:
signal = SIGILL;
break;
case ISR::PageFault:
signal = SIGSEGV;
break;
default:
dwarnln("Unhandled exception");
signal = SIGABRT;
break;
}
Kernel::Thread::current().handle_signal(-signal);
} }
else else
{ {

View File

@ -260,6 +260,11 @@ int execute_command(BAN::Vector<BAN::String>& args)
while (*current) while (*current)
printf("%s\n", *current++); printf("%s\n", *current++);
} }
else if (args.front() == "page-fault-test"sv)
{
volatile int* ptr = nullptr;
*ptr = 0;
}
else if (args.front() == "kill-test"sv) else if (args.front() == "kill-test"sv)
{ {
pid_t pid = fork(); pid_t pid = fork();