From e4ec9311e280a92a8adafa1b7302e573339aeabf Mon Sep 17 00:00:00 2001 From: Matheus Date: Fri, 14 Jun 2024 17:05:31 -0300 Subject: [PATCH] syscalls: pause --- kernel-src/arch/x86-64/syscall.asm | 4 +++- kernel-src/arch/x86-64/syscalllog.c | 8 +++++--- kernel-src/sys/syscalls/pause.c | 13 +++++++++++++ patches/mlibc/jinx-working-patch.patch | 22 ++++++++++++++-------- 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 kernel-src/sys/syscalls/pause.c diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index a281e967..a994c02f 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -73,6 +73,7 @@ extern syscall_socketpair extern syscall_getsockname extern syscall_getpeername extern syscall_chroot +extern syscall_pause syscalltab: dq syscall_print dq syscall_mmap @@ -148,7 +149,8 @@ dq syscall_socketpair dq syscall_getsockname dq syscall_getpeername dq syscall_chroot -syscallcount equ 74 +dq syscall_pause +syscallcount equ 75 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 70b551f0..bf51fdc1 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 74 +#define SYSCALL_COUNT 75 #define LOGSTR(x) arch_e9_puts(x) static char *name[] = { @@ -82,7 +82,8 @@ static char *name[] = { "socketpair", "getsockname", "getpeername", - "chroot" + "chroot", + "pause" }; static char *args[] = { @@ -159,7 +160,8 @@ static char *args[] = { "domain %d type %d protocol %d", // socketpair "fd %d addr %p addrlen %p", // getsockname "fd %d addr %p addrlen %p", // getpeername - "path %s" // chroot + "path %s", // chroot + "N/A" }; #endif diff --git a/kernel-src/sys/syscalls/pause.c b/kernel-src/sys/syscalls/pause.c new file mode 100644 index 00000000..7e812bc9 --- /dev/null +++ b/kernel-src/sys/syscalls/pause.c @@ -0,0 +1,13 @@ +#include + +syscallret_t syscall_pause(context_t *) { + syscallret_t ret = { + .errno = EINTR, + .ret = -1 + }; + + sched_preparesleep(true); + sched_yield(); + + return ret; +} diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index 15180b98..b1796a8b 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -13,7 +13,7 @@ index eb7be7b..eb83b56 100644 #define IPPROTO_HOPOPTS 0 #define IPPROTO_ICMP 1 diff --git mlibc-clean/meson.build mlibc-workdir/meson.build -index 6db3421..40887ba 100644 +index bb8928f..7fd3280 100644 --- mlibc-clean/meson.build +++ mlibc-workdir/meson.build @@ -256,6 +256,13 @@ elif host_machine.system() == 'dripos' @@ -101,10 +101,10 @@ index fc34a3b..b1a95a9 100644 #include diff --git mlibc-clean/options/posix/generic/unistd-stubs.cpp mlibc-workdir/options/posix/generic/unistd-stubs.cpp -index 3beb692..a7bbfaa 100644 +index a40c6dc..acbe0ba 100644 --- mlibc-clean/options/posix/generic/unistd-stubs.cpp +++ mlibc-workdir/options/posix/generic/unistd-stubs.cpp -@@ -1251,6 +1251,7 @@ void encrypt(char[64], int) { +@@ -1254,6 +1254,7 @@ void encrypt(char[64], int) { } #endif @@ -112,7 +112,7 @@ index 3beb692..a7bbfaa 100644 #if __MLIBC_BSD_OPTION void *sbrk(intptr_t increment) { if(increment) { -@@ -1267,3 +1268,4 @@ void *sbrk(intptr_t increment) { +@@ -1270,3 +1271,4 @@ void *sbrk(intptr_t increment) { return out; } #endif @@ -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..f0facf5 +index 0000000..476ae95 --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp -@@ -0,0 +1,795 @@ +@@ -0,0 +1,800 @@ +#include +#include +#include @@ -326,6 +326,11 @@ index 0000000..f0facf5 + mlibc::infoLogger() << "getsockopt: " << fd << " " << layer << " " << number << frg::endlog; + return 0; + } ++ ++ int sys_pause() { ++ long ret; ++ return syscall(SYSCALL_PAUSE, &ret); ++ } + + int sys_chroot(const char *path) { + long ret; @@ -1025,10 +1030,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..d1d26ed +index 0000000..7e6a56a --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h -@@ -0,0 +1,97 @@ +@@ -0,0 +1,98 @@ +#ifndef _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE + @@ -1106,6 +1111,7 @@ index 0000000..d1d26ed +#define SYSCALL_GETSOCKNAME 71 +#define SYSCALL_GETPEERNAME 72 +#define SYSCALL_CHROOT 73 ++#define SYSCALL_PAUSE 74 + +#include +#include