diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index b13707c8..5e3c80c0 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -23,6 +23,7 @@ extern syscall_fcntl extern syscall_chdir extern syscall_pipe2 extern syscall_isatty +extern syscall_faccessat syscalltab: dq syscall_print dq syscall_mmap @@ -48,7 +49,8 @@ dq syscall_fcntl dq syscall_chdir dq syscall_pipe2 dq syscall_isatty -syscallcount equ 24 +dq syscall_faccessat +syscallcount equ 25 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 78fd2f9c..24000f99 100644 --- a/kernel-src/arch/x86-64/syscalllog.c +++ b/kernel-src/arch/x86-64/syscalllog.c @@ -2,7 +2,7 @@ #include #include -#define SYSCALL_COUNT 24 +#define SYSCALL_COUNT 25 #define LOGSTR(x) arch_e9_puts(x) static char *name[] = { @@ -29,7 +29,8 @@ static char *name[] = { "fcntl", "chdir", "pipe2", - "isatty" + "isatty", + "faccessat" }; static char *args[] = { @@ -57,6 +58,7 @@ static char *args[] = { "path %s", // chdir "flags %d", // pipe2 "fd %d", // isatty + "dirfd %d pathname %s mode %d flags %d" // faccessat }; __attribute__((no_caller_saved_registers)) void arch_syscall_log(int syscall, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6) { diff --git a/kernel-src/sys/syscalls/faccessat.c b/kernel-src/sys/syscalls/faccessat.c new file mode 100644 index 00000000..47663053 --- /dev/null +++ b/kernel-src/sys/syscalls/faccessat.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include + +#define AT_SYMLINK_NOFOLLOW 0x100 + +syscallret_t syscall_faccessat(context_t *, int dirfd, const char *upath, int mode, int flags) { + syscallret_t ret = { + .ret = -1 + }; + + char *path = alloc(strlen(upath) + 1); + if (path == NULL) { + ret.errno = ENOMEM; + return ret; + } + + // TODO safe strcopy + strcpy(path, upath); + + vnode_t *dirnode = NULL; + file_t *file = NULL; + if (*path == '/') { + dirnode = sched_getroot(); + } else if (dirfd == AT_FDCWD) { + dirnode = sched_getcwd(); + } else { + file = fd_get(dirfd); + if (file == NULL) { + ret.errno = EBADF; + goto cleanup; + } + + dirnode = file->vnode; + + if (dirnode->type != V_TYPE_DIR) { + ret.errno = ENOTDIR; + goto cleanup; + } + } + + vnode_t *node = NULL; + ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0); + if (ret.errno) + goto cleanup; + + ret.errno = VOP_ACCESS(node, mode, &_cpu()->thread->proc->cred); + ret.ret = 0; + + cleanup: + if (node) + VOP_RELEASE(node); + + if (file) + fd_release(file); + else + VOP_RELEASE(dirnode); + + free(path); + + return ret; +} diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index af049d6c..c94e4004 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..6b6d167 +index 0000000..f931e99 --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp -@@ -0,0 +1,246 @@ +@@ -0,0 +1,255 @@ +#include +#include +#include @@ -192,6 +192,15 @@ index 0000000..6b6d167 + return 0; + } + ++ int sys_faccessat(int dirfd, const char *pathname, int mode, int flags){ ++ long ret; ++ return syscall(SYSCALL_FACCESSAT, &ret, dirfd, (uint64_t)pathname, mode, flags); ++ } ++ ++ int sys_access(const char *path, int mode){ ++ return sys_faccessat(AT_FDCWD, path, mode, 0); ++ } ++ + int sys_pipe(int *fds, int flags) { + long ret = 0; + long err = syscall(SYSCALL_PIPE2, &ret, flags); @@ -402,10 +411,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..09c7dd4 +index 0000000..3a71f84 --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h -@@ -0,0 +1,47 @@ +@@ -0,0 +1,48 @@ +#ifndef _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE + @@ -433,6 +442,7 @@ index 0000000..09c7dd4 +#define SYSCALL_CHDIR 21 +#define SYSCALL_PIPE2 22 +#define SYSCALL_ISATTY 23 ++#define SYSCALL_FACCESSAT 24 + +#include +#include