Module Name: src Committed By: christos Date: Sat Jun 29 13:46:10 UTC 2024
Modified Files: src/sys/compat/linux/arch/aarch64: syscalls.master src/sys/compat/linux/arch/alpha: syscalls.master src/sys/compat/linux/arch/amd64: syscalls.master src/sys/compat/linux/arch/arm: syscalls.master src/sys/compat/linux/arch/i386: syscalls.master src/sys/compat/linux/arch/m68k: syscalls.master src/sys/compat/linux/arch/mips: syscalls.master src/sys/compat/linux/arch/powerpc: syscalls.master src/sys/compat/linux/common: linux_file.c linux_misc.c linux_misc.h Log Message: >From gsoc 2024: Implement faccessat2 and getcpu (Shivraz) To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/compat/linux/arch/aarch64/syscalls.master cvs rdiff -u -r1.106 -r1.107 src/sys/compat/linux/arch/alpha/syscalls.master cvs rdiff -u -r1.72 -r1.73 src/sys/compat/linux/arch/amd64/syscalls.master cvs rdiff -u -r1.79 -r1.80 src/sys/compat/linux/arch/arm/syscalls.master cvs rdiff -u -r1.134 -r1.135 src/sys/compat/linux/arch/i386/syscalls.master cvs rdiff -u -r1.104 -r1.105 src/sys/compat/linux/arch/m68k/syscalls.master cvs rdiff -u -r1.79 -r1.80 src/sys/compat/linux/arch/mips/syscalls.master cvs rdiff -u -r1.84 -r1.85 src/sys/compat/linux/arch/powerpc/syscalls.master cvs rdiff -u -r1.123 -r1.124 src/sys/compat/linux/common/linux_file.c cvs rdiff -u -r1.263 -r1.264 src/sys/compat/linux/common/linux_misc.c cvs rdiff -u -r1.32 -r1.33 src/sys/compat/linux/common/linux_misc.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/linux/arch/aarch64/syscalls.master diff -u src/sys/compat/linux/arch/aarch64/syscalls.master:1.11 src/sys/compat/linux/arch/aarch64/syscalls.master:1.12 --- src/sys/compat/linux/arch/aarch64/syscalls.master:1.11 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/aarch64/syscalls.master Sat Jun 29 09:46:09 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.11 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.12 2024/06/29 13:46:09 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -58,6 +58,7 @@ #include <compat/linux/common/linux_misc.h> #include <compat/linux/common/linux_mmap.h> #include <compat/linux/common/linux_msg.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/common/linux_sem.h> #include <compat/linux/common/linux_shm.h> #include <compat/linux/common/linux_siginfo.h> @@ -345,7 +346,9 @@ struct rusage50 *rusage); } 166 NOARGS { int|sys||umask(int newmask); } 167 UNIMPL prctl -168 UNIMPL getcpu +168 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 169 STD { int|linux_sys||gettimeofday(struct timeval50 *tp, \ struct timezone *tzp); } 170 STD { int|linux_sys||settimeofday(struct timeval50 *tp, \ @@ -683,7 +686,8 @@ unsigned int last, unsigned int flags); } 437 UNIMPL openat2 438 UNIMPL pidfd_getfd -439 UNIMPL faccessat2 +439 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } ; we want a "nosys" syscall, we'll just add an extra entry for it. 440 STD { int|linux_sys||nosys(void); } Index: src/sys/compat/linux/arch/alpha/syscalls.master diff -u src/sys/compat/linux/arch/alpha/syscalls.master:1.106 src/sys/compat/linux/arch/alpha/syscalls.master:1.107 --- src/sys/compat/linux/arch/alpha/syscalls.master:1.106 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/alpha/syscalls.master Sat Jun 29 09:46:09 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.106 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.107 2024/06/29 13:46:09 christos Exp $ ; ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -72,6 +72,7 @@ #include <compat/linux/common/linux_siginfo.h> #include <compat/linux/common/linux_ipc.h> #include <compat/linux/common/linux_msg.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/common/linux_sem.h> #include <compat/linux/common/linux_shm.h> #include <compat/linux/common/linux_mmap.h> @@ -765,7 +766,9 @@ 470 UNIMPL tee 471 UNIMPL vmsplice 472 UNIMPL move_pages -473 UNIMPL getcpu +473 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 474 STD { int|linux_sys||epoll_pwait(int epfd, \ struct linux_epoll_event *events, int maxevents, \ int timeout, const linux_sigset_t *sigmask); } @@ -864,7 +867,8 @@ unsigned int last, unsigned int flags); } 547 UNIMPL 548 UNIMPL -549 UNIMPL +549 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } 550 UNIMPL 551 STD { int|linux_sys||epoll_pwait2(int epfd, \ struct linux_epoll_event *events, int maxevents, \ Index: src/sys/compat/linux/arch/amd64/syscalls.master diff -u src/sys/compat/linux/arch/amd64/syscalls.master:1.72 src/sys/compat/linux/arch/amd64/syscalls.master:1.73 --- src/sys/compat/linux/arch/amd64/syscalls.master:1.72 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/amd64/syscalls.master Sat Jun 29 09:46:09 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.72 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.73 2024/06/29 13:46:09 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -55,6 +55,7 @@ #include <compat/linux/common/linux_mmap.h> #include <compat/linux/common/linux_ipc.h> #include <compat/linux/common/linux_msg.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/common/linux_sem.h> #include <compat/linux/common/linux_shm.h> #include <compat/linux/common/linux_signal.h> @@ -572,7 +573,9 @@ struct linux_mmsghdr *msgvec, unsigned int vlen, \ unsigned int flags); } 308 UNIMPL setns -309 UNIMPL getcpu +309 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 310 UNIMPL process_vm_readv 311 UNIMPL process_vm_writev 312 UNIMPL kcmp @@ -707,7 +710,8 @@ unsigned int last, unsigned int flags); } 437 UNIMPL openat2 438 UNIMPL pidfd_getfd -439 UNIMPL faccessat2 +439 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } 440 UNIMPL process_madvise 441 STD { int|linux_sys||epoll_pwait2(int epfd, \ struct linux_epoll_event *events, int maxevents, \ Index: src/sys/compat/linux/arch/arm/syscalls.master diff -u src/sys/compat/linux/arch/arm/syscalls.master:1.79 src/sys/compat/linux/arch/arm/syscalls.master:1.80 --- src/sys/compat/linux/arch/arm/syscalls.master:1.79 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/arm/syscalls.master Sat Jun 29 09:46:09 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.79 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.80 2024/06/29 13:46:09 christos Exp $ ; Derived from sys/compat/linux/arch/*/syscalls.master ; and from Linux 2.4.12 arch/arm/kernel/calls.S @@ -48,6 +48,8 @@ #include <compat/linux/common/linux_signal.h> #include <compat/linux/common/linux_siginfo.h> #include <compat/linux/common/linux_machdep.h> +#include <compat/linux/common/linux_sched.h> + #include <compat/linux/linux_syscallargs.h> @@ -563,7 +565,9 @@ 342 UNIMPL tee 343 UNIMPL vmsplice 344 UNIMPL move_pages -345 UNIMPL getcpu +345 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 346 STD { int|linux_sys||epoll_pwait(int epfd, \ struct linux_epoll_event *events, int maxevents, \ int timeout, const linux_sigset_t *sigmask); } @@ -693,7 +697,8 @@ unsigned int last, unsigned int flags); } 437 UNIMPL 438 UNIMPL -439 UNIMPL +439 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } 440 UNIMPL 441 STD { int|linux_sys||epoll_pwait2(int epfd, \ struct linux_epoll_event *events, int maxevents, \ Index: src/sys/compat/linux/arch/i386/syscalls.master diff -u src/sys/compat/linux/arch/i386/syscalls.master:1.134 src/sys/compat/linux/arch/i386/syscalls.master:1.135 --- src/sys/compat/linux/arch/i386/syscalls.master:1.134 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/i386/syscalls.master Sat Jun 29 09:46:09 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.134 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.135 2024/06/29 13:46:09 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -47,6 +47,7 @@ #include <compat/linux/common/linux_signal.h> #include <compat/linux/common/linux_siginfo.h> #include <compat/linux/common/linux_machdep.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/linux_syscallargs.h> @@ -531,7 +532,9 @@ 315 UNIMPL tee 316 UNIMPL vmsplice 317 UNIMPL move_pages -318 UNIMPL getcpu +318 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 319 STD { int|linux_sys||epoll_pwait(int epfd, \ struct linux_epoll_event *events, int maxevents, \ int timeout, const linux_sigset_t *sigmask); } @@ -671,7 +674,8 @@ unsigned int last, unsigned int flags); } 437 UNIMPL openat2 438 UNIMPL pidfd_getfd -439 UNIMPL faccessat2 +439 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } 440 UNIMPL process_madvise 441 STD { int|linux_sys||epoll_pwait2(int epfd, \ struct linux_epoll_event *events, int maxevents, \ Index: src/sys/compat/linux/arch/m68k/syscalls.master diff -u src/sys/compat/linux/arch/m68k/syscalls.master:1.104 src/sys/compat/linux/arch/m68k/syscalls.master:1.105 --- src/sys/compat/linux/arch/m68k/syscalls.master:1.104 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/m68k/syscalls.master Sat Jun 29 09:46:10 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.104 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.105 2024/06/29 13:46:10 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -51,6 +51,7 @@ #include <compat/linux/common/linux_siginfo.h> #include <compat/linux/common/linux_machdep.h> #include <compat/linux/common/linux_mmap.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/linux_syscallargs.h> @@ -547,7 +548,9 @@ 312 STD { int|linux_sys||sched_getaffinity(pid_t pid, \ unsigned int len, unsigned long *mask); } 313 UNIMPL kexec_load -314 UNIMPL getcpu +314 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 315 STD { int|linux_sys||epoll_pwait(int epfd, \ struct linux_epoll_event *events, int maxevents, \ int timeout, const linux_sigset_t *sigmask); } @@ -696,7 +699,8 @@ unsigned int last, unsigned int flags); } 437 UNIMPL 438 UNIMPL -439 UNIMPL +439 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } 440 UNIMPL 441 STD { int|linux_sys||epoll_pwait2(int epfd, \ struct linux_epoll_event *events, int maxevents, \ Index: src/sys/compat/linux/arch/mips/syscalls.master diff -u src/sys/compat/linux/arch/mips/syscalls.master:1.79 src/sys/compat/linux/arch/mips/syscalls.master:1.80 --- src/sys/compat/linux/arch/mips/syscalls.master:1.79 Sat Aug 19 13:49:49 2023 +++ src/sys/compat/linux/arch/mips/syscalls.master Sat Jun 29 09:46:10 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.79 2023/08/19 17:49:49 christos Exp $ + $NetBSD: syscalls.master,v 1.80 2024/06/29 13:46:10 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -53,6 +53,7 @@ #include <compat/linux/common/linux_machdep.h> #include <compat/linux/common/linux_mmap.h> #include <compat/linux/common/linux_socketcall.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/linux_syscallargs.h> @@ -535,7 +536,9 @@ 310 NOARGS { int|sys||__futex_get_robust_list(lwpid_t lwpid, \ void **headp, size_t *lenp); } 311 UNIMPL kexec_load -312 UNIMPL getcpu +312 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 313 STD { int|linux_sys||epoll_pwait(int epfd, \ struct linux_epoll_event *events, int maxevents, \ int timeout, const linux_sigset_t *sigmask); } Index: src/sys/compat/linux/arch/powerpc/syscalls.master diff -u src/sys/compat/linux/arch/powerpc/syscalls.master:1.84 src/sys/compat/linux/arch/powerpc/syscalls.master:1.85 --- src/sys/compat/linux/arch/powerpc/syscalls.master:1.84 Sat Aug 19 13:49:50 2023 +++ src/sys/compat/linux/arch/powerpc/syscalls.master Sat Jun 29 09:46:10 2024 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.84 2023/08/19 17:49:50 christos Exp $ + $NetBSD: syscalls.master,v 1.85 2024/06/29 13:46:10 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -74,6 +74,7 @@ #include <compat/linux/common/linux_siginfo.h> #include <compat/linux/common/linux_machdep.h> #include <compat/linux/common/linux_mmap.h> +#include <compat/linux/common/linux_sched.h> #include <compat/linux/linux_syscallargs.h> @@ -535,7 +536,9 @@ 300 NOARGS { int|sys||__futex_get_robust_list(lwpid_t lwpid, \ void **headp, size_t *lenp); } 301 UNIMPL move_pages -302 UNIMPL getcpu +302 STD { int|linux_sys||getcpu(unsigned int *cpu, \ + unsigned int *node, \ + struct linux_getcpu_cache *tcache); } 303 STD { int|linux_sys||epoll_pwait(int epfd, \ struct linux_epoll_event *events, int maxevents, \ int timeout, const linux_sigset_t *sigmask); } @@ -696,7 +699,8 @@ unsigned int last, unsigned int flags); } 437 UNIMPL 438 UNIMPL -439 UNIMPL +439 STD { int|linux_sys||faccessat2(int fd, const char *path, \ + int amode, int flags); } 440 UNIMPL 441 STD { int|linux_sys||epoll_pwait2(int epfd, \ struct linux_epoll_event *events, int maxevents, \ Index: src/sys/compat/linux/common/linux_file.c diff -u src/sys/compat/linux/common/linux_file.c:1.123 src/sys/compat/linux/common/linux_file.c:1.124 --- src/sys/compat/linux/common/linux_file.c:1.123 Sun Jul 9 22:31:55 2023 +++ src/sys/compat/linux/common/linux_file.c Sat Jun 29 09:46:10 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_file.c,v 1.123 2023/07/10 02:31:55 christos Exp $ */ +/* $NetBSD: linux_file.c,v 1.124 2024/06/29 13:46:10 christos Exp $ */ /*- * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.123 2023/07/10 02:31:55 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.124 2024/06/29 13:46:10 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -899,6 +899,24 @@ linux_to_bsd_atflags(int lflags) return bflags; } +int +linux_sys_faccessat2(lwp_t *l, const struct linux_sys_faccessat2_args *uap, + register_t *retval) +{ + /* { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) amode; + syscallarg(int) flags; + }*/ + int flag = linux_to_bsd_atflags(SCARG(uap, flags)); + int mode = SCARG(uap, amode); + int fd = SCARG(uap, fd); + const char *path = SCARG(uap, path); + + return do_sys_accessat(l, fd, path, mode, flag); +} + #define LINUX_NOT_SUPPORTED(fun) \ int \ Index: src/sys/compat/linux/common/linux_misc.c diff -u src/sys/compat/linux/common/linux_misc.c:1.263 src/sys/compat/linux/common/linux_misc.c:1.264 --- src/sys/compat/linux/common/linux_misc.c:1.263 Sat Feb 10 13:43:52 2024 +++ src/sys/compat/linux/common/linux_misc.c Sat Jun 29 09:46:10 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_misc.c,v 1.263 2024/02/10 18:43:52 andvar Exp $ */ +/* $NetBSD: linux_misc.c,v 1.264 2024/06/29 13:46:10 christos Exp $ */ /*- * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.263 2024/02/10 18:43:52 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.264 2024/06/29 13:46:10 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -2141,3 +2141,33 @@ linux_sys_readahead(struct lwp *l, const return do_posix_fadvise(fd, SCARG(uap, offset), SCARG(uap, count), POSIX_FADV_WILLNEED); } + +int +linux_sys_getcpu(lwp_t *l, const struct linux_sys_getcpu_args *uap, + register_t *retval) +{ + /* { + syscallarg(unsigned int *) cpu; + syscallarg(unsigned int *) node; + syscallarg(struct linux_getcpu_cache *) tcache; + }*/ + int error; + + if (SCARG(uap, cpu)) { + u_int cpu_id = l->l_cpu->ci_data.cpu_index; + error = copyout(&cpu_id, SCARG(uap, cpu), sizeof(cpu_id)); + if (error) + return error; + + } + + // TO-DO: Test on a NUMA machine if the node_id returned is correct + if (SCARG(uap, node)) { + u_int node_id = l->l_cpu->ci_data.cpu_numa_id; + error = copyout(&node_id, SCARG(uap, node), sizeof(node_id)); + if (error) + return error; + } + + return 0; +} Index: src/sys/compat/linux/common/linux_misc.h diff -u src/sys/compat/linux/common/linux_misc.h:1.32 src/sys/compat/linux/common/linux_misc.h:1.33 --- src/sys/compat/linux/common/linux_misc.h:1.32 Sun May 12 15:54:48 2024 +++ src/sys/compat/linux/common/linux_misc.h Sat Jun 29 09:46:10 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_misc.h,v 1.32 2024/05/12 19:54:48 christos Exp $ */ +/* $NetBSD: linux_misc.h,v 1.33 2024/06/29 13:46:10 christos Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -162,10 +162,15 @@ extern const int linux_fstypes_cnt; */ #define linux_to_bsd_posix_fadv(advice) (advice) +struct linux_getcpu_cache{ + unsigned long blob[128 / sizeof(long)]; +}; + struct linux_epoll_event { uint32_t events; uint64_t data; } + #if defined(__amd64__) /* Only for x86_64. See include/uapi/linux/eventpoll.h. */ __packed