From 250789aa209313ca517f4c0813941094d438d661 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 29 Aug 2023 00:13:21 +0300 Subject: [PATCH] Kernel: better handle kernel errors --- BAN/include/BAN/Errors.h | 5 +++++ kernel/kernel/Syscall.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/BAN/include/BAN/Errors.h b/BAN/include/BAN/Errors.h index ac649a0b8d..bbfc59669c 100644 --- a/BAN/include/BAN/Errors.h +++ b/BAN/include/BAN/Errors.h @@ -48,6 +48,11 @@ namespace BAN { return (Kernel::ErrorCode)(m_error_code & ~kernel_error_mask); } + + bool is_kernel_error() const + { + return m_error_code & kernel_error_mask; + } #endif uint64_t get_error_code() const { return m_error_code; } diff --git a/kernel/kernel/Syscall.cpp b/kernel/kernel/Syscall.cpp index 0847fccb9d..fd9df89a2b 100644 --- a/kernel/kernel/Syscall.cpp +++ b/kernel/kernel/Syscall.cpp @@ -186,6 +186,9 @@ namespace Kernel asm volatile("cli"); + if (ret.is_error() && ret.error().is_kernel_error()) + Kernel::panic("Kernel error while returning to userspace {}", ret.error()); + ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing); Thread::current().load_sse();