Add linux waitid(2) from GSoC 2023 (Theodore Preduta)
This commit is contained in:
parent
95fb0c166b
commit
69e4d6a089
|
@ -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
|
||||
|
|
|
@ -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 compat_90
|
|||
# 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.
|
||||
|
|
|
@ -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, \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(struct sys_mmap_args *,
|
|||
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 struct linux_sys_wait4_args *uap, register_
|
|||
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);
|
||||
|
@ -273,6 +263,100 @@ linux_sys_wait4(struct lwp *l, const struct linux_sys_wait4_args *uap, register_
|
|||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
|
|
@ -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_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_WAIT4_WNOHANG | \
|
||||
LINUX_WAIT4_WUNTRACED | \
|
||||
LINUX_WAIT4_WCONTINUED | \
|
||||
LINUX_WAIT4_WNOTHREAD | \
|
||||
LINUX_WAIT4_WALL | \
|
||||
LINUX_WAIT4_WCLONE)
|
||||
#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 {
|
||||
|
|
|
@ -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 status)
|
|||
sts = LINUX_SIGCONT;
|
||||
break;
|
||||
case CLD_EXITED:
|
||||
sts = WEXITSTATUS(status);
|
||||
sts = status;
|
||||
break;
|
||||
case CLD_STOPPED:
|
||||
case CLD_TRAPPED:
|
||||
|
|
|
@ -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 struct linux32_sys_wait4_args *uap, regis
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue