syscalls: ppoll

This commit is contained in:
Matheus
2024-06-19 21:56:26 -03:00
parent 984d74d327
commit f82b07328a
4 changed files with 52 additions and 12 deletions
+3 -1
View File
@@ -74,6 +74,7 @@ extern syscall_getsockname
extern syscall_getpeername extern syscall_getpeername
extern syscall_chroot extern syscall_chroot
extern syscall_pause extern syscall_pause
extern syscall_ppoll
syscalltab: syscalltab:
dq syscall_print dq syscall_print
dq syscall_mmap dq syscall_mmap
@@ -150,7 +151,8 @@ dq syscall_getsockname
dq syscall_getpeername dq syscall_getpeername
dq syscall_chroot dq syscall_chroot
dq syscall_pause dq syscall_pause
syscallcount equ 75 dq syscall_ppoll
syscallcount equ 76
section .text section .text
global arch_syscall_entry global arch_syscall_entry
; on entry: ; on entry:
+5 -3
View File
@@ -5,7 +5,7 @@
#ifdef SYSCALL_LOGGING #ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 75 #define SYSCALL_COUNT 76
#define LOGSTR(x) arch_e9_puts(x) #define LOGSTR(x) arch_e9_puts(x)
static char *name[] = { static char *name[] = {
@@ -83,7 +83,8 @@ static char *name[] = {
"getsockname", "getsockname",
"getpeername", "getpeername",
"chroot", "chroot",
"pause" "pause",
"ppoll"
}; };
static char *args[] = { static char *args[] = {
@@ -161,7 +162,8 @@ static char *args[] = {
"fd %d addr %p addrlen %p", // getsockname "fd %d addr %p addrlen %p", // getsockname
"fd %d addr %p addrlen %p", // getpeername "fd %d addr %p addrlen %p", // getpeername
"path %s", // chroot "path %s", // chroot
"N/A" "N/A", // pause
"fds %p nfds %d timeout %p sigmask %p" // ppoll
}; };
#endif #endif
+31
View File
@@ -100,3 +100,34 @@ syscallret_t syscall_poll(context_t *, pollfd_t *fds, size_t nfds, int timeoutms
free(fdsbuff); free(fdsbuff);
return ret; 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;
}
+13 -8
View File
@@ -207,10 +207,10 @@ index 0000000..e5b087a
+ +
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
new file mode 100644 new file mode 100644
index 0000000..476ae95 index 0000000..e11d5a4
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -0,0 +1,800 @@ @@ -0,0 +1,804 @@
+#include <bits/ensure.h> +#include <bits/ensure.h>
+#include <mlibc/debug.hpp> +#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp> +#include <mlibc/all-sysdeps.hpp>
@@ -652,7 +652,13 @@ index 0000000..476ae95
+ return error; + 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 +#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) { + 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)); + 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 num;
+ int err = sys_poll(fds, actualcount, time, &num); + int err = sys_ppoll(fds, actualcount, timeout, sigmask, &num);
+ +
+ if (err) { + if (err) {
+ free(fds); + free(fds);
@@ -1030,10 +1034,10 @@ index 0000000..990eca0
+#endif +#endif
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
new file mode 100644 new file mode 100644
index 0000000..7e6a56a index 0000000..6b2e7da
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -0,0 +1,98 @@ @@ -0,0 +1,99 @@
+#ifndef _SYSCALL_H_INCLUDE +#ifndef _SYSCALL_H_INCLUDE
+#define _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE
+ +
@@ -1112,6 +1116,7 @@ index 0000000..7e6a56a
+#define SYSCALL_GETPEERNAME 72 +#define SYSCALL_GETPEERNAME 72
+#define SYSCALL_CHROOT 73 +#define SYSCALL_CHROOT 73
+#define SYSCALL_PAUSE 74 +#define SYSCALL_PAUSE 74
+#define SYSCALL_PPOLL 75
+ +
+#include <stddef.h> +#include <stddef.h>
+#include <stdint.h> +#include <stdint.h>