From 0bb9ed191a5674c5afffab9011b7808a572daf06 Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 26 Jun 2023 23:19:18 -0300 Subject: [PATCH] syscall: allow userspace to call new system calls --- kernel-src/arch/x86-64/syscall.asm | 10 +++++++- patches/mlibc/jinx-working-patch.patch | 32 ++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index ac7d9e8a..43bee3f7 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -16,6 +16,10 @@ extern syscall_exit extern syscall_waitpid extern syscall_munmap extern syscall_getdents +extern syscall_dup +extern syscall_dup2 +extern syscall_dup3 +extern syscall_fcntl syscalltab: dq syscall_print dq syscall_mmap @@ -34,7 +38,11 @@ dq syscall_exit dq syscall_waitpid dq syscall_munmap dq syscall_getdents -syscallcount equ 17 +dq syscall_dup +dq syscall_dup2 +dq syscall_dup3 +dq syscall_fcntl +syscallcount equ 21 section .text global arch_syscall_entry ; on entry: diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index d5b80c56..dae0ee74 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -133,10 +133,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..c177a55 +index 0000000..74b6be1 --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp -@@ -0,0 +1,206 @@ +@@ -0,0 +1,226 @@ +#include +#include +#include @@ -192,6 +192,26 @@ index 0000000..c177a55 + return 0; + } + ++ int sys_fcntl(int fd, int request, va_list args, int *result) { ++ long arg = va_arg(args, uint64_t); ++ long ret; ++ long err = syscall(SYSCALL_FCNTL, &ret, fd, request, arg); ++ *result = ret; ++ return err; ++ } ++ ++ int sys_dup(int fd, int flags, int *newfd) { ++ long ret; ++ long err = syscall(SYSCALL_DUP, &ret, fd); ++ *newfd = ret; ++ return err; ++ } ++ ++ int sys_dup2(int fd, int flags, int newfd) { ++ long ret; ++ return syscall(SYSCALL_DUP2, &ret, fd, newfd); ++ } ++ + int sys_read_entries(int handle, void *buffer, size_t max_size, size_t *bytes_read) { + long ret; + long err = syscall(SYSCALL_GETDENTS, &ret, handle, (uint64_t)buffer, max_size); @@ -362,10 +382,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..6b0e993 +index 0000000..f884f36 --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h -@@ -0,0 +1,40 @@ +@@ -0,0 +1,44 @@ +#ifndef _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE + @@ -386,6 +406,10 @@ index 0000000..6b0e993 +#define SYSCALL_WAITPID 14 +#define SYSCALL_MUNMAP 15 +#define SYSCALL_GETDENTS 16 ++#define SYSCALL_DUP 17 ++#define SYSCALL_DUP2 18 ++#define SYSCALL_DUP3 19 ++#define SYSCALL_FCNTL 20 + +#include +#include