Kernel: Add macro to dump all syscalls and their return values

This commit is contained in:
Bananymous 2024-08-01 17:20:20 +03:00
parent 4599e1dec5
commit da3b30cd94
1 changed files with 15 additions and 1 deletions

View File

@ -7,6 +7,8 @@
#include <termios.h> #include <termios.h>
#define DUMP_ALL_SYSCALLS 0
namespace Kernel namespace Kernel
{ {
@ -28,6 +30,12 @@ namespace Kernel
#undef O #undef O
}; };
static constexpr const char* s_syscall_names[] {
#define O(enum, name) #enum,
__SYSCALL_LIST(O)
#undef O
};
extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, InterruptStack* interrupt_stack) extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, InterruptStack* interrupt_stack)
{ {
ASSERT(GDT::is_user_segment(interrupt_stack->cs)); ASSERT(GDT::is_user_segment(interrupt_stack->cs));
@ -46,7 +54,13 @@ namespace Kernel
asm volatile("cli"); asm volatile("cli");
if (ret.is_error() && ret.error().get_error_code() == ENOTSUP) if (ret.is_error() && ret.error().get_error_code() == ENOTSUP)
dprintln("ENOTSUP {}", syscall); dprintln("{}: ENOTSUP", s_syscall_names[syscall]);
#if DUMP_ALL_SYSCALLS
else if (ret.is_error())
dprintln("{}: {}", s_syscall_names[syscall], ret.error());
else
dprintln("{}: {}", s_syscall_names[syscall], ret.value());
#endif
if (ret.is_error() && ret.error().is_kernel_error()) if (ret.is_error() && ret.error().is_kernel_error())
Kernel::panic("Kernel error while returning to userspace {}", ret.error()); Kernel::panic("Kernel error while returning to userspace {}", ret.error());