From cb288f547e72cd0f74596491cf799d08c1995114 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Thu, 13 Jun 2024 22:59:38 -0400 Subject: [PATCH] syscall: fix page fault on non-existent syscall Signed-off-by: Michael Shaw --- include/lib/errno.h | 1 + lib/errno.c | 1 + sched/syscall.c | 9 ++++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/lib/errno.h b/include/lib/errno.h index 26f3c6d..c2f41d7 100644 --- a/include/lib/errno.h +++ b/include/lib/errno.h @@ -14,6 +14,7 @@ #define EFAULT 10 #define EAGAIN 11 #define EBUSY 12 +#define ENOSYS 13 const char *strerror(int errnum); diff --git a/lib/errno.c b/lib/errno.c index 7dde4a3..eda6c7c 100644 --- a/lib/errno.c +++ b/lib/errno.c @@ -16,6 +16,7 @@ static const char *errno_str[] = { [EFAULT] = "Bad address", [EAGAIN] = "Try again", [EBUSY] = "Device or resource busy", + [ENOSYS] = "Function not implemented", }; inline const char *strerror(int errnum) diff --git a/sched/syscall.c b/sched/syscall.c index 8dc31dc..f0fa08f 100644 --- a/sched/syscall.c +++ b/sched/syscall.c @@ -10,16 +10,19 @@ #define SYSCALL_MAX 0x100 -typedef void (*syscall_t)(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); +typedef void *(*syscall_t)(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); syscall_t syscall_table[SYSCALL_MAX]; slab_t *fd_slab; -void syscall(uint64_t syscall_no, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) +uint64_t syscall(uint64_t syscall_no, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) { syscall_t syscall = (void *)syscall_table[syscall_no]; - syscall(arg1, arg2, arg3, arg4, arg5); + if (syscall == NULL) + return -ENOSYS; + + return (uint64_t)syscall(arg1, arg2, arg3, arg4, arg5); } ssize_t sys_read(int fd, void *buf, size_t count)