From f82b07328ad5ddd594a1d536fbbb8646936c4198 Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 19 Jun 2024 21:56:26 -0300 Subject: [PATCH] syscalls: ppoll --- kernel-src/arch/x86-64/syscall.asm | 4 +++- kernel-src/arch/x86-64/syscalllog.c | 8 ++++--- kernel-src/sys/syscalls/poll.c | 31 ++++++++++++++++++++++++++ patches/mlibc/jinx-working-patch.patch | 21 ++++++++++------- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index a994c02f..0cfeec75 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -74,6 +74,7 @@ extern syscall_getsockname extern syscall_getpeername extern syscall_chroot extern syscall_pause +extern syscall_ppoll syscalltab: dq syscall_print dq syscall_mmap @@ -150,7 +151,8 @@ dq syscall_getsockname dq syscall_getpeername dq syscall_chroot dq syscall_pause -syscallcount equ 75 +dq syscall_ppoll +syscallcount equ 76 section .text global arch_syscall_entry ; on entry: diff --git a/kernel-src/arch/x86-64/syscalllog.c b/kernel-src/arch/x86-64/syscalllog.c index bf51fdc1..0a202d8f 100644 --- a/kernel-src/arch/x86-64/syscalllog.c +++ b/kernel-src/arch/x86-64/syscalllog.c @@ -5,7 +5,7 @@ #ifdef SYSCALL_LOGGING -#define SYSCALL_COUNT 75 +#define SYSCALL_COUNT 76 #define LOGSTR(x) arch_e9_puts(x) static char *name[] = { @@ -83,7 +83,8 @@ static char *name[] = { "getsockname", "getpeername", "chroot", - "pause" + "pause", + "ppoll" }; static char *args[] = { @@ -161,7 +162,8 @@ static char *args[] = { "fd %d addr %p addrlen %p", // getsockname "fd %d addr %p addrlen %p", // getpeername "path %s", // chroot - "N/A" + "N/A", // pause + "fds %p nfds %d timeout %p sigmask %p" // ppoll }; #endif diff --git a/kernel-src/sys/syscalls/poll.c b/kernel-src/sys/syscalls/poll.c index 0b4be565..d21f268e 100644 --- a/kernel-src/sys/syscalls/poll.c +++ b/kernel-src/sys/syscalls/poll.c @@ -100,3 +100,34 @@ syscallret_t syscall_poll(context_t *, pollfd_t *fds, size_t nfds, int timeoutms free(fdsbuff); return ret; } + +syscallret_t syscall_ppoll(context_t *context, pollfd_t *fds, size_t nfds, timespec_t *utimeout, sigset_t *usigset) { + timespec_t timeout; + sigset_t sigset; + sigset_t savedset; + + if (utimeout) { + syscallret_t ret; + ret.ret = -1; + ret.errno = usercopy_fromuser(&timeout, utimeout, sizeof(timespec_t)); + if (ret.errno) + return ret; + } + + if (usigset) { + syscallret_t ret; + ret.ret = -1; + ret.errno = usercopy_fromuser(&sigset, usigset, sizeof(sigset_t)); + if (ret.errno) + return ret; + + signal_changemask(_cpu()->thread, SIG_SETMASK, &sigset, &savedset); + } + + syscallret_t ret = syscall_poll(context, fds, nfds, utimeout ? (timeout.s * 1000 + timeout.ns / 1000000) : -1); + + if (usigset) + signal_changemask(_cpu()->thread, SIG_SETMASK, &savedset, NULL); + + return ret; +} diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index b1796a8b..3109e71e 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -207,10 +207,10 @@ index 0000000..e5b087a + diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp new file mode 100644 -index 0000000..476ae95 +index 0000000..e11d5a4 --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp -@@ -0,0 +1,800 @@ +@@ -0,0 +1,804 @@ +#include +#include +#include @@ -652,7 +652,13 @@ index 0000000..476ae95 + return error; + } + -+// XXX emulate with ppoll ++ int sys_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask, int *num_events) { ++ long ret; ++ long error = syscall(SYSCALL_PPOLL, &ret, (uint64_t)fds, nfds, (uint64_t)timeout, (uint64_t)sigmask); ++ *num_events = ret; ++ return error; ++ } ++ +#ifndef MLIBC_BUILDING_RTLD + int sys_pselect(int num_fds, fd_set *read_set, fd_set *write_set, fd_set *except_set, const struct timespec *timeout, const sigset_t *sigmask, int *num_events) { + pollfd *fds = (pollfd *)malloc(num_fds * sizeof(pollfd)); @@ -684,10 +690,8 @@ index 0000000..476ae95 + } + } + -+ int time = timeout == NULL ? -1 : timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000; -+ + int num; -+ int err = sys_poll(fds, actualcount, time, &num); ++ int err = sys_ppoll(fds, actualcount, timeout, sigmask, &num); + + if (err) { + free(fds); @@ -1030,10 +1034,10 @@ index 0000000..990eca0 +#endif diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h new file mode 100644 -index 0000000..7e6a56a +index 0000000..6b2e7da --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h -@@ -0,0 +1,98 @@ +@@ -0,0 +1,99 @@ +#ifndef _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE + @@ -1112,6 +1116,7 @@ index 0000000..7e6a56a +#define SYSCALL_GETPEERNAME 72 +#define SYSCALL_CHROOT 73 +#define SYSCALL_PAUSE 74 ++#define SYSCALL_PPOLL 75 + +#include +#include