Module Name: src Committed By: christos Date: Fri Aug 18 19:41:20 UTC 2023
Modified Files: src/sys/compat/common: compat_mod.h files.common 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/mips: syscalls.master src/sys/compat/linux/arch/powerpc: syscalls.master src/sys/compat/linux/common: linux_misc.c linux_misc.h linux_signal.c src/sys/compat/linux32/common: linux32_wait.c Log Message: Add linux waitid(2) from GSoC 2023 (Theodore Preduta) To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/compat/common/compat_mod.h cvs rdiff -u -r1.9 -r1.10 src/sys/compat/common/files.common cvs rdiff -u -r1.9 -r1.10 src/sys/compat/linux/arch/aarch64/syscalls.master cvs rdiff -u -r1.104 -r1.105 src/sys/compat/linux/arch/alpha/syscalls.master cvs rdiff -u -r1.70 -r1.71 src/sys/compat/linux/arch/amd64/syscalls.master cvs rdiff -u -r1.77 -r1.78 src/sys/compat/linux/arch/arm/syscalls.master cvs rdiff -u -r1.132 -r1.133 src/sys/compat/linux/arch/i386/syscalls.master cvs rdiff -u -r1.77 -r1.78 src/sys/compat/linux/arch/mips/syscalls.master cvs rdiff -u -r1.82 -r1.83 src/sys/compat/linux/arch/powerpc/syscalls.master cvs rdiff -u -r1.261 -r1.262 src/sys/compat/linux/common/linux_misc.c cvs rdiff -u -r1.28 -r1.29 src/sys/compat/linux/common/linux_misc.h cvs rdiff -u -r1.88 -r1.89 src/sys/compat/linux/common/linux_signal.c cvs rdiff -u -r1.12 -r1.13 src/sys/compat/linux32/common/linux32_wait.c 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/common/compat_mod.h diff -u src/sys/compat/common/compat_mod.h:1.8 src/sys/compat/common/compat_mod.h:1.9 --- src/sys/compat/common/compat_mod.h:1.8 Fri Jul 28 14:19:00 2023 +++ src/sys/compat/common/compat_mod.h Fri Aug 18 15:41:18 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: compat_mod.h,v 1.8 2023/07/28 18:19:00 christos Exp $ */ +/* $NetBSD: compat_mod.h,v 1.9 2023/08/18 19:41:18 christos Exp $ */ /*- * Copyright (c) 2013, 2019 The NetBSD Foundation, Inc. @@ -37,6 +37,8 @@ int compat_100_init(void); int compat_100_fini(void); int kern_event_100_init(void); int kern_event_100_fini(void); +void usb_100_init(void); +void usb_100_fini(void); #endif #ifdef COMPAT_90 Index: src/sys/compat/common/files.common diff -u src/sys/compat/common/files.common:1.9 src/sys/compat/common/files.common:1.10 --- src/sys/compat/common/files.common:1.9 Fri Jul 28 14:19:00 2023 +++ src/sys/compat/common/files.common Fri Aug 18 15:41:18 2023 @@ -1,4 +1,4 @@ -# $NetBSD: files.common,v 1.9 2023/07/28 18:19:00 christos Exp $ +# $NetBSD: files.common,v 1.10 2023/08/18 19:41:18 christos Exp $ # # Generic utility files, used by various compat options. @@ -113,6 +113,7 @@ file compat/common/vfs_syscalls_90.c co # Compatibility code for NetBSD 10.0 file compat/common/compat_100_mod.c compat_100 file compat/common/kern_event_100.c compat_100 +#file compat/common/usb_subr_100.c compat_100 # # Sources for sysv ipc compatibility across the versions. Index: src/sys/compat/linux/arch/aarch64/syscalls.master diff -u src/sys/compat/linux/arch/aarch64/syscalls.master:1.9 src/sys/compat/linux/arch/aarch64/syscalls.master:1.10 --- src/sys/compat/linux/arch/aarch64/syscalls.master:1.9 Sat Jul 29 11:04:28 2023 +++ src/sys/compat/linux/arch/aarch64/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.9 2023/07/29 15:04:28 christos Exp $ + $NetBSD: syscalls.master,v 1.10 2023/08/18 19:41:19 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -216,7 +216,9 @@ 92 STD { int|linux_sys||personality(unsigned long per); } 93 STD { int|linux_sys||exit(int rval); } 94 STD { int|linux_sys||exit_group(int error_code); } -95 UNIMPL waitid +95 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 96 STD { int|linux_sys||set_tid_address(int *tid); } 97 UNIMPL unshare 98 STD { int|linux_sys||futex(int *uaddr, int op, int val, \ Index: src/sys/compat/linux/arch/alpha/syscalls.master diff -u src/sys/compat/linux/arch/alpha/syscalls.master:1.104 src/sys/compat/linux/arch/alpha/syscalls.master:1.105 --- src/sys/compat/linux/arch/alpha/syscalls.master:1.104 Sat Jul 29 11:04:28 2023 +++ src/sys/compat/linux/arch/alpha/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.104 2023/07/29 15:04:28 christos Exp $ + $NetBSD: syscalls.master,v 1.105 2023/08/18 19:41:19 christos Exp $ ; ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -703,7 +703,9 @@ 435 UNIMPL mq_timedreceive 436 UNIMPL mq_notify 437 UNIMPL mq_getsetattr -438 UNIMPL waitid +438 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 439 UNIMPL add_key 440 UNIMPL request_key 441 UNIMPL keyctl Index: src/sys/compat/linux/arch/amd64/syscalls.master diff -u src/sys/compat/linux/arch/amd64/syscalls.master:1.70 src/sys/compat/linux/arch/amd64/syscalls.master:1.71 --- src/sys/compat/linux/arch/amd64/syscalls.master:1.70 Sat Jul 29 11:04:28 2023 +++ src/sys/compat/linux/arch/amd64/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.70 2023/07/29 15:04:28 christos Exp $ + $NetBSD: syscalls.master,v 1.71 2023/08/18 19:41:19 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -463,7 +463,9 @@ 244 UNIMPL mq_notify 245 UNIMPL mq_getsetattr 246 UNIMPL kexec_load -247 UNIMPL waitid +247 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 248 UNIMPL add_key 249 UNIMPL request_key 250 UNIMPL keyctl Index: src/sys/compat/linux/arch/arm/syscalls.master diff -u src/sys/compat/linux/arch/arm/syscalls.master:1.77 src/sys/compat/linux/arch/arm/syscalls.master:1.78 --- src/sys/compat/linux/arch/arm/syscalls.master:1.77 Sat Jul 29 11:04:28 2023 +++ src/sys/compat/linux/arch/arm/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.77 2023/07/29 15:04:28 christos Exp $ + $NetBSD: syscalls.master,v 1.78 2023/08/18 19:41:19 christos Exp $ ; Derived from sys/compat/linux/arch/*/syscalls.master ; and from Linux 2.4.12 arch/arm/kernel/calls.S @@ -471,7 +471,9 @@ 277 UNIMPL mq_timedreceive 278 UNIMPL mq_notify 279 UNIMPL mq_getsetattr -280 UNIMPL waitid +280 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 281 UNIMPL socket 282 UNIMPL bind 283 UNIMPL connect Index: src/sys/compat/linux/arch/i386/syscalls.master diff -u src/sys/compat/linux/arch/i386/syscalls.master:1.132 src/sys/compat/linux/arch/i386/syscalls.master:1.133 --- src/sys/compat/linux/arch/i386/syscalls.master:1.132 Sat Jul 29 11:04:28 2023 +++ src/sys/compat/linux/arch/i386/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.132 2023/07/29 15:04:28 christos Exp $ + $NetBSD: syscalls.master,v 1.133 2023/08/18 19:41:19 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -475,7 +475,9 @@ 281 UNIMPL mq_notify 282 UNIMPL mq_getsetattr 283 UNIMPL sys_kexec_load -284 UNIMPL waitid +284 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 285 UNIMPL /* unused */ 286 UNIMPL add_key 287 UNIMPL request_key Index: src/sys/compat/linux/arch/mips/syscalls.master diff -u src/sys/compat/linux/arch/mips/syscalls.master:1.77 src/sys/compat/linux/arch/mips/syscalls.master:1.78 --- src/sys/compat/linux/arch/mips/syscalls.master:1.77 Sat Jul 29 11:05:31 2023 +++ src/sys/compat/linux/arch/mips/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.77 2023/07/29 15:05:31 christos Exp $ + $NetBSD: syscalls.master,v 1.78 2023/08/18 19:41:19 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -474,7 +474,9 @@ 275 UNIMPL mq_notify 276 UNIMPL mq_getsetattr 277 UNIMPL vserve -278 UNIMPL waitid +278 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 279 UNIMPL setaltroot 280 UNIMPL add_key 281 UNIMPL request_key Index: src/sys/compat/linux/arch/powerpc/syscalls.master diff -u src/sys/compat/linux/arch/powerpc/syscalls.master:1.82 src/sys/compat/linux/arch/powerpc/syscalls.master:1.83 --- src/sys/compat/linux/arch/powerpc/syscalls.master:1.82 Sat Jul 29 11:04:29 2023 +++ src/sys/compat/linux/arch/powerpc/syscalls.master Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.82 2023/07/29 15:04:29 christos Exp $ + $NetBSD: syscalls.master,v 1.83 2023/08/18 19:41:19 christos Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -478,7 +478,9 @@ 269 UNIMPL add_key 270 UNIMPL request_key 271 UNIMPL keyctl -272 UNIMPL waitid +272 STD { int|linux_sys||waitid(int idtype, id_t id, \ + linux_siginfo_t *infop, int options, \ + struct rusage50 *rusage); } 273 UNIMPL ioprio_set 274 UNIMPL ioprio_get 275 UNIMPL inotify_init Index: src/sys/compat/linux/common/linux_misc.c diff -u src/sys/compat/linux/common/linux_misc.c:1.261 src/sys/compat/linux/common/linux_misc.c:1.262 --- src/sys/compat/linux/common/linux_misc.c:1.261 Sun Jul 30 14:31:13 2023 +++ src/sys/compat/linux/common/linux_misc.c Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_misc.c,v 1.261 2023/07/30 18:31:13 christos Exp $ */ +/* $NetBSD: linux_misc.c,v 1.262 2023/08/18 19:41:19 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.261 2023/07/30 18:31:13 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.262 2023/08/18 19:41:19 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -180,7 +180,7 @@ static void linux_to_bsd_mmap_args(struc const struct linux_sys_mmap_args *); static int linux_mmap(struct lwp *, const struct linux_sys_mmap_args *, register_t *, off_t); - +static int linux_to_native_wait_options(int); /* * The information on a terminated (or stopped) process needs @@ -229,19 +229,9 @@ linux_sys_wait4(struct lwp *l, const str if (linux_options & ~(LINUX_WAIT4_KNOWNFLAGS)) return (EINVAL); - options = 0; - if (linux_options & LINUX_WAIT4_WNOHANG) - options |= WNOHANG; - if (linux_options & LINUX_WAIT4_WUNTRACED) - options |= WUNTRACED; - if (linux_options & LINUX_WAIT4_WCONTINUED) - options |= WCONTINUED; - if (linux_options & LINUX_WAIT4_WALL) - options |= WALLSIG; - if (linux_options & LINUX_WAIT4_WCLONE) - options |= WALTSIG; + options = linux_to_native_wait_options(linux_options); # ifdef DIAGNOSTIC - if (linux_options & LINUX_WAIT4_WNOTHREAD) + if (linux_options & LINUX_WNOTHREAD) printf("WARNING: %s: linux process %d.%d called " "waitpid with __WNOTHREAD set!\n", __FILE__, l->l_proc->p_pid, l->l_lid); @@ -274,6 +264,100 @@ linux_sys_wait4(struct lwp *l, const str } /* + * waitid(2). Converting arguments to the NetBSD equivalent and + * calling it. + */ +int +linux_sys_waitid(struct lwp *l, const struct linux_sys_waitid_args *uap, register_t *retval) +{ + /* { + syscallarg(int) idtype; + syscallarg(id_t) id; + syscallarg(linux_siginfo_t *) infop; + syscallarg(int) options; + syscallarg(struct rusage50 *) rusage; + } */ + int error, linux_options, options, linux_idtype, status; + pid_t pid; + idtype_t idtype; + id_t id; + siginfo_t info; + linux_siginfo_t linux_info; + struct wrusage wru; + struct rusage50 ru50; + + linux_idtype = SCARG(uap, idtype); + switch (linux_idtype) { + case LINUX_P_ALL: + idtype = P_ALL; + break; + case LINUX_P_PID: + idtype = P_PID; + break; + case LINUX_P_PGID: + idtype = P_PGID; + break; + case LINUX_P_PIDFD: + return EOPNOTSUPP; + default: + return EINVAL; + } + + linux_options = SCARG(uap, options); + if (linux_options & ~(LINUX_WAITID_KNOWNFLAGS)) + return EINVAL; + + options = linux_to_native_wait_options(linux_options); + id = SCARG(uap, id); + + error = do_sys_waitid(idtype, id, &pid, &status, options, &wru, &info); + if (pid == 0 && options & WNOHANG) { + info.si_signo = 0; + info.si_pid = 0; + } + + if (error == 0 && SCARG(uap, infop) != NULL) { + /* POSIX says that this NULL check is a bug, but Linux does this. */ + native_to_linux_siginfo(&linux_info, &info._info); + error = copyout(&linux_info, SCARG(uap, infop), sizeof(linux_info)); + } + + if (error == 0 && SCARG(uap, rusage) != NULL) { + rusage_to_rusage50(&wru.wru_children, &ru50); + error = copyout(&ru50, SCARG(uap, rusage), sizeof(ru50)); + } + + return error; +} + +/* + * Convert the opttions argument for wait4(2) and waitid(2) from what + * Linux wants to what NetBSD wants. + */ +static int +linux_to_native_wait_options(int linux_options) +{ + int options = 0; + + if (linux_options & LINUX_WNOHANG) + options |= WNOHANG; + if (linux_options & LINUX_WUNTRACED) + options |= WUNTRACED; + if (linux_options & LINUX_WEXITED) + options |= WEXITED; + if (linux_options & LINUX_WCONTINUED) + options |= WCONTINUED; + if (linux_options & LINUX_WNOWAIT) + options |= WNOWAIT; + if (linux_options & LINUX_WALL) + options |= WALLSIG; + if (linux_options & LINUX_WCLONE) + options |= WALTSIG; + + return options; +} + +/* * Linux brk(2). Like native, but always return the new break value. */ int Index: src/sys/compat/linux/common/linux_misc.h diff -u src/sys/compat/linux/common/linux_misc.h:1.28 src/sys/compat/linux/common/linux_misc.h:1.29 --- src/sys/compat/linux/common/linux_misc.h:1.28 Sat Jul 29 08:58:51 2023 +++ src/sys/compat/linux/common/linux_misc.h Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_misc.h,v 1.28 2023/07/29 12:58:51 rin Exp $ */ +/* $NetBSD: linux_misc.h,v 1.29 2023/08/18 19:41:19 christos Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -33,21 +33,37 @@ #define _LINUX_MISC_H /* - * Options passed to the Linux wait4() system call. + * Options passed to the Linux wait4() and waitid() system calls. */ -#define LINUX_WAIT4_WNOHANG 0x00000001 -#define LINUX_WAIT4_WUNTRACED 0x00000002 -#define LINUX_WAIT4_WCONTINUED 0x00000008 -#define LINUX_WAIT4_WNOTHREAD 0x20000000 -#define LINUX_WAIT4_WALL 0x40000000 -#define LINUX_WAIT4_WCLONE 0x80000000 - -#define LINUX_WAIT4_KNOWNFLAGS (LINUX_WAIT4_WNOHANG | \ - LINUX_WAIT4_WUNTRACED | \ - LINUX_WAIT4_WCONTINUED | \ - LINUX_WAIT4_WNOTHREAD | \ - LINUX_WAIT4_WALL | \ - LINUX_WAIT4_WCLONE) +#define LINUX_WNOHANG 0x00000001 +#define LINUX_WUNTRACED 0x00000002 +#define LINUX_WEXITED 0x00000004 +#define LINUX_WCONTINUED 0x00000008 +#define LINUX_WNOWAIT 0x01000000 +#define LINUX_WNOTHREAD 0x20000000 +#define LINUX_WALL 0x40000000 +#define LINUX_WCLONE 0x80000000 + +#define LINUX_WAIT4_KNOWNFLAGS (LINUX_WNOHANG | \ + LINUX_WUNTRACED | \ + LINUX_WCONTINUED | \ + LINUX_WNOTHREAD | \ + LINUX_WALL | \ + LINUX_WCLONE) + +#define LINUX_WAITID_KNOWNFLAGS (LINUX_WNOHANG | \ + LINUX_WEXITED | \ + LINUX_WUNTRACED | \ + LINUX_WCONTINUED | \ + LINUX_WNOWAIT) + +/* + * Passed as the first argument of waitid(2). + */ +#define LINUX_P_ALL 0 +#define LINUX_P_PID 1 +#define LINUX_P_PGID 2 +#define LINUX_P_PIDFD 3 /* This looks very unportable to me, but this is how Linux defines it. */ struct linux_sysinfo { Index: src/sys/compat/linux/common/linux_signal.c diff -u src/sys/compat/linux/common/linux_signal.c:1.88 src/sys/compat/linux/common/linux_signal.c:1.89 --- src/sys/compat/linux/common/linux_signal.c:1.88 Mon Nov 1 01:07:16 2021 +++ src/sys/compat/linux/common/linux_signal.c Fri Aug 18 15:41:19 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_signal.c,v 1.88 2021/11/01 05:07:16 thorpej Exp $ */ +/* $NetBSD: linux_signal.c,v 1.89 2023/08/18 19:41:19 christos Exp $ */ /*- * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. @@ -48,7 +48,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.88 2021/11/01 05:07:16 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.89 2023/08/18 19:41:19 christos Exp $"); #define COMPAT_LINUX 1 @@ -845,7 +845,7 @@ native_to_linux_si_status(int code, int sts = LINUX_SIGCONT; break; case CLD_EXITED: - sts = WEXITSTATUS(status); + sts = status; break; case CLD_STOPPED: case CLD_TRAPPED: Index: src/sys/compat/linux32/common/linux32_wait.c diff -u src/sys/compat/linux32/common/linux32_wait.c:1.12 src/sys/compat/linux32/common/linux32_wait.c:1.13 --- src/sys/compat/linux32/common/linux32_wait.c:1.12 Thu Nov 10 12:00:51 2016 +++ src/sys/compat/linux32/common/linux32_wait.c Fri Aug 18 15:41:20 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_wait.c,v 1.12 2016/11/10 17:00:51 christos Exp $ */ +/* $NetBSD: linux32_wait.c,v 1.13 2023/08/18 19:41:20 christos Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_wait.c,v 1.12 2016/11/10 17:00:51 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_wait.c,v 1.13 2023/08/18 19:41:20 christos Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -109,13 +109,13 @@ linux32_sys_wait4(struct lwp *l, const s return EINVAL; options = 0; - if (linux_options & LINUX_WAIT4_WNOHANG) + if (linux_options & LINUX_WNOHANG) options |= WNOHANG; - if (linux_options & LINUX_WAIT4_WUNTRACED) + if (linux_options & LINUX_WUNTRACED) options |= WUNTRACED; - if (linux_options & LINUX_WAIT4_WALL) + if (linux_options & LINUX_WALL) options |= WALLSIG; - if (linux_options & LINUX_WAIT4_WCLONE) + if (linux_options & LINUX_WCLONE) options |= WALTSIG; pid = SCARG(uap, pid);