Sun Jul 30 06:52:21 2023 UTC ()
COMPAT_NETBSD32: Add support for epoll(2).


(rin)
diff -r1.54 -r1.55 src/sys/compat/netbsd32/files.netbsd32
diff -r1.142 -r1.143 src/sys/compat/netbsd32/netbsd32.h
diff -r1.47 -r1.48 src/sys/compat/netbsd32/netbsd32_conv.h
diff -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_epoll.c
diff -r1.143 -r1.144 src/sys/compat/netbsd32/syscalls.master

cvs diff -r1.54 -r1.55 src/sys/compat/netbsd32/files.netbsd32 (expand / switch to unified diff)

--- src/sys/compat/netbsd32/files.netbsd32 2022/12/19 23:19:51 1.54
+++ src/sys/compat/netbsd32/files.netbsd32 2023/07/30 06:52:20 1.55
@@ -1,31 +1,32 @@ @@ -1,31 +1,32 @@
1# $NetBSD: files.netbsd32,v 1.54 2022/12/19 23:19:51 pgoyette Exp $ 1# $NetBSD: files.netbsd32,v 1.55 2023/07/30 06:52:20 rin Exp $
2# 2#
3# config file description for machine-independent netbsd32 compat code. 3# config file description for machine-independent netbsd32 compat code.
4# included by ports that need it. 4# included by ports that need it.
5 5
6# ports should define any machine-specific files they need in their 6# ports should define any machine-specific files they need in their
7# own file lists. 7# own file lists.
8 8
9define compat_netbsd32 9define compat_netbsd32
10 10
11#makeoptions drmkms CPPFLAGS+="-DNETBSD32_DRMKMS" 11#makeoptions drmkms CPPFLAGS+="-DNETBSD32_DRMKMS"
12 12
13file compat/netbsd32/netbsd32_acl.c compat_netbsd32 13file compat/netbsd32/netbsd32_acl.c compat_netbsd32
14file compat/netbsd32/netbsd32_core.c compat_netbsd32 & coredump 14file compat/netbsd32/netbsd32_core.c compat_netbsd32 & coredump
15file compat/netbsd32/netbsd32_exec_elf32.c compat_netbsd32 & exec_elf32 15file compat/netbsd32/netbsd32_exec_elf32.c compat_netbsd32 & exec_elf32
16file compat/netbsd32/netbsd32_exec_aout.c compat_netbsd32 & exec_aout 16file compat/netbsd32/netbsd32_exec_aout.c compat_netbsd32 & exec_aout
17file compat/netbsd32/netbsd32_netbsd.c compat_netbsd32 17file compat/netbsd32/netbsd32_netbsd.c compat_netbsd32
18#file compat/netbsd32/netbsd32_drm.c compat_netbsd32 & drmkms 18#file compat/netbsd32/netbsd32_drm.c compat_netbsd32 & drmkms
 19file compat/netbsd32/netbsd32_epoll.c compat_netbsd32
19file compat/netbsd32/netbsd32_event.c compat_netbsd32 20file compat/netbsd32/netbsd32_event.c compat_netbsd32
20file compat/netbsd32/netbsd32_execve.c compat_netbsd32 21file compat/netbsd32/netbsd32_execve.c compat_netbsd32
21file compat/netbsd32/netbsd32_fd.c compat_netbsd32 22file compat/netbsd32/netbsd32_fd.c compat_netbsd32
22file compat/netbsd32/netbsd32_fs.c compat_netbsd32 23file compat/netbsd32/netbsd32_fs.c compat_netbsd32
23file compat/netbsd32/netbsd32_futex.c compat_netbsd32 24file compat/netbsd32/netbsd32_futex.c compat_netbsd32
24file compat/netbsd32/netbsd32_kern_proc.c compat_netbsd32 25file compat/netbsd32/netbsd32_kern_proc.c compat_netbsd32
25file compat/netbsd32/netbsd32_ioctl.c compat_netbsd32 26file compat/netbsd32/netbsd32_ioctl.c compat_netbsd32
26file compat/netbsd32/netbsd32_ipc.c compat_netbsd32 27file compat/netbsd32/netbsd32_ipc.c compat_netbsd32
27file compat/netbsd32/netbsd32_lwp.c compat_netbsd32 28file compat/netbsd32/netbsd32_lwp.c compat_netbsd32
28file compat/netbsd32/netbsd32_module.c compat_netbsd32 29file compat/netbsd32/netbsd32_module.c compat_netbsd32
29file compat/netbsd32/netbsd32_mod.c compat_netbsd32 30file compat/netbsd32/netbsd32_mod.c compat_netbsd32
30file compat/netbsd32/netbsd32_mqueue.c compat_netbsd32 & mqueue 31file compat/netbsd32/netbsd32_mqueue.c compat_netbsd32 & mqueue
31file compat/netbsd32/netbsd32_nfssvc.c compat_netbsd32 & nfsserver 32file compat/netbsd32/netbsd32_nfssvc.c compat_netbsd32 & nfsserver

cvs diff -r1.142 -r1.143 src/sys/compat/netbsd32/netbsd32.h (expand / switch to unified diff)

--- src/sys/compat/netbsd32/netbsd32.h 2023/07/29 12:38:25 1.142
+++ src/sys/compat/netbsd32/netbsd32.h 2023/07/30 06:52:20 1.143
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: netbsd32.h,v 1.142 2023/07/29 12:38:25 rin Exp $ */ 1/* $NetBSD: netbsd32.h,v 1.143 2023/07/30 06:52:20 rin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green 4 * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -198,26 +198,35 @@ typedef netbsd32_pointer_t netbsd32_aclp @@ -198,26 +198,35 @@ typedef netbsd32_pointer_t netbsd32_aclp
198/* 198/*
199 * now, the compatibility structures and their fake pointer types. 199 * now, the compatibility structures and their fake pointer types.
200 */ 200 */
201 201
202/* from <sys/types.h> */ 202/* from <sys/types.h> */
203typedef netbsd32_pointer_t netbsd32_fd_setp_t; 203typedef netbsd32_pointer_t netbsd32_fd_setp_t;
204typedef netbsd32_intptr_t netbsd32_semid_t; 204typedef netbsd32_intptr_t netbsd32_semid_t;
205typedef netbsd32_pointer_t netbsd32_semidp_t; 205typedef netbsd32_pointer_t netbsd32_semidp_t;
206typedef netbsd32_uint64 netbsd32_dev_t; 206typedef netbsd32_uint64 netbsd32_dev_t;
207typedef netbsd32_int64 netbsd32_off_t; 207typedef netbsd32_int64 netbsd32_off_t;
208typedef netbsd32_uint64 netbsd32_ino_t; 208typedef netbsd32_uint64 netbsd32_ino_t;
209typedef netbsd32_int64 netbsd32_blkcnt_t; 209typedef netbsd32_int64 netbsd32_blkcnt_t;
210 210
 211/* from <sys/epoll.h> */
 212typedef netbsd32_uint64 netbsd32_epoll_data_t;
 213
 214typedef netbsd32_pointer_t netbsd32_epoll_eventp_t;
 215struct netbsd32_epoll_event {
 216 uint32_t events;
 217 netbsd32_epoll_data_t data;
 218};
 219
211/* from <sys/spawn.h> */ 220/* from <sys/spawn.h> */
212typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actionsp; 221typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actionsp;
213typedef netbsd32_pointer_t netbsd32_posix_spawnattrp; 222typedef netbsd32_pointer_t netbsd32_posix_spawnattrp;
214typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actions_entryp; 223typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actions_entryp;
215 224
216/* from <sys/uio.h> */ 225/* from <sys/uio.h> */
217typedef netbsd32_pointer_t netbsd32_iovecp_t; 226typedef netbsd32_pointer_t netbsd32_iovecp_t;
218struct netbsd32_iovec { 227struct netbsd32_iovec {
219 netbsd32_voidp iov_base; /* Base address. */ 228 netbsd32_voidp iov_base; /* Base address. */
220 netbsd32_size_t iov_len; /* Length. */ 229 netbsd32_size_t iov_len; /* Length. */
221}; 230};
222 231
223/* from <sys/time.h> */ 232/* from <sys/time.h> */

cvs diff -r1.47 -r1.48 src/sys/compat/netbsd32/netbsd32_conv.h (expand / switch to unified diff)

--- src/sys/compat/netbsd32/netbsd32_conv.h 2023/07/29 12:38:25 1.47
+++ src/sys/compat/netbsd32/netbsd32_conv.h 2023/07/30 06:52:20 1.48
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: netbsd32_conv.h,v 1.47 2023/07/29 12:38:25 rin Exp $ */ 1/* $NetBSD: netbsd32_conv.h,v 1.48 2023/07/30 06:52:20 rin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001 Matthew R. Green 4 * Copyright (c) 1998, 2001 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -33,26 +33,27 @@ @@ -33,26 +33,27 @@
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/kernel.h> 34#include <sys/kernel.h>
35#include <sys/dirent.h> 35#include <sys/dirent.h>
36#include <sys/ipc.h> 36#include <sys/ipc.h>
37#include <sys/msg.h> 37#include <sys/msg.h>
38#define msg __msg /* Don't ask me! */ 38#define msg __msg /* Don't ask me! */
39#include <sys/sem.h> 39#include <sys/sem.h>
40#include <sys/shm.h> 40#include <sys/shm.h>
41#include <sys/socket.h> 41#include <sys/socket.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <sys/time.h> 43#include <sys/time.h>
44#include <sys/timex.h> 44#include <sys/timex.h>
45#include <sys/event.h> 45#include <sys/event.h>
 46#include <sys/epoll.h>
46 47
47#include <compat/sys/dirent.h> 48#include <compat/sys/dirent.h>
48 49
49#include <prop/plistref.h> 50#include <prop/plistref.h>
50 51
51#include <nv.h> 52#include <nv.h>
52 53
53#include <compat/netbsd32/netbsd32.h> 54#include <compat/netbsd32/netbsd32.h>
54 55
55/* converters for structures that we need */ 56/* converters for structures that we need */
56static __inline void 57static __inline void
57netbsd32_from_timeval50(const struct timeval *tv, 58netbsd32_from_timeval50(const struct timeval *tv,
58 struct netbsd32_timeval50 *tv32) 59 struct netbsd32_timeval50 *tv32)
@@ -946,14 +947,34 @@ netbsd32_to_mq_attr(const struct netbsd3 @@ -946,14 +947,34 @@ netbsd32_to_mq_attr(const struct netbsd3
946 947
947static __inline void 948static __inline void
948netbsd32_from_mq_attr(const struct mq_attr *attr, 949netbsd32_from_mq_attr(const struct mq_attr *attr,
949 struct netbsd32_mq_attr *a32) 950 struct netbsd32_mq_attr *a32)
950{ 951{
951 952
952 memset(a32, 0, sizeof(*a32)); 953 memset(a32, 0, sizeof(*a32));
953 a32->mq_flags = attr->mq_flags; 954 a32->mq_flags = attr->mq_flags;
954 a32->mq_maxmsg = attr->mq_maxmsg; 955 a32->mq_maxmsg = attr->mq_maxmsg;
955 a32->mq_msgsize = attr->mq_msgsize; 956 a32->mq_msgsize = attr->mq_msgsize;
956 a32->mq_curmsgs = attr->mq_curmsgs; 957 a32->mq_curmsgs = attr->mq_curmsgs;
957} 958}
958 959
 960static __inline void
 961netbsd32_to_epoll_event(const struct netbsd32_epoll_event *ee32,
 962 struct epoll_event *ee)
 963{
 964
 965 memset(ee, 0, sizeof(*ee));
 966 ee->events = ee32->events;
 967 ee->data = ee32->data;
 968}
 969
 970static __inline void
 971netbsd32_from_epoll_event(const struct epoll_event *ee,
 972 struct netbsd32_epoll_event *ee32)
 973{
 974
 975 memset(ee32, 0, sizeof(*ee32));
 976 ee32->events = ee->events;
 977 ee32->data = ee->data;
 978}
 979
959#endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */ 980#endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */

File Added: src/sys/compat/netbsd32/netbsd32_epoll.c
/*	$NetBSD: netbsd32_epoll.c,v 1.1 2023/07/30 06:52:20 rin Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2007 Roman Divacky
 * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_epoll.c,v 1.1 2023/07/30 06:52:20 rin Exp $");

#include <sys/types.h>
#include <sys/epoll.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <sys/syscall.h>
#include <sys/syscallargs.h>

#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_conv.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>

int
netbsd32_epoll_create1(struct lwp *l,
    const struct netbsd32_epoll_create1_args *uap, register_t *retval)
{
	/* {
		syscallarg(int)		flags;
	} */
	struct sys_epoll_create1_args ua;

	NETBSD32TO64_UAP(flags);
	return sys_epoll_create1(l, &ua, retval);
}

int
netbsd32_epoll_ctl(struct lwp *l, const struct netbsd32_epoll_ctl_args *uap,
    register_t *retval)
{
	/* {
		syscallarg(int) epfd;
		syscallarg(int) op;
		syscallarg(int) fd;
		syscallarg(netbsd32_epoll_eventp_t) event;
	} */
	struct epoll_event ee, *eep;
	int error;

	if (SCARG(uap, op) != EPOLL_CTL_DEL) {
		struct netbsd32_epoll_event ee32;

		error = copyin(SCARG_P32(uap, event), &ee32, sizeof(ee32));
		if (error != 0)
			return error;

		netbsd32_to_epoll_event(&ee32, &ee);
		eep = &ee;
	} else
		eep = NULL;

	return epoll_ctl_common(l, retval, SCARG(uap, epfd), SCARG(uap, op),
	    SCARG(uap, fd), eep);
}

int
netbsd32_epoll_pwait2(struct lwp *l,
    const struct netbsd32_epoll_pwait2_args *uap, register_t *retval)
{
	/* {
		syscallarg(int) epfd;
		syscallarg(netbsd32_epoll_eventp_t) events;
		syscallarg(int) maxevents;
		syscallarg(netbsd32_timespecp_t) timeout;
		syscallarg(netbsd32_sigsetp_t) sigmask;
	} */
	struct epoll_event *events;
	struct timespec ts, *tsp;
	sigset_t ss, *ssp;
	int error;
	const int maxevents = SCARG(uap, maxevents);

	if (maxevents <= 0 || maxevents >= EPOLL_MAX_EVENTS)
		return EINVAL;

	if (SCARG_P32(uap, timeout) != NULL) {
		struct netbsd32_timespec ts32;

		error = copyin(SCARG_P32(uap, timeout), &ts32, sizeof(ts32));
		if (error != 0)
			return error;

		netbsd32_to_timespec(&ts32, &ts);
		tsp = &ts;
	} else
		tsp = NULL;

	if (SCARG_P32(uap, sigmask) != NULL) {
		error = copyin(SCARG_P32(uap, sigmask), &ss, sizeof(ss));
		if (error != 0)
			return error;

		ssp = &ss;
	} else
		ssp = NULL;

	events = kmem_alloc(maxevents * sizeof(*events), KM_SLEEP);

	error = epoll_wait_common(l, retval, SCARG(uap, epfd), events,
	    maxevents, tsp, ssp);
	if (error != 0) {
		kmem_free(events, maxevents * sizeof(*events));
		return error;
	}

	struct netbsd32_epoll_event *events32 =
	    kmem_alloc(*retval * sizeof(*events32), KM_SLEEP);

	for (int i = 0; i < *retval; i++)
		netbsd32_from_epoll_event(&events[i], &events32[i]);

	kmem_free(events, maxevents * sizeof(*events));

	error = copyout(events, SCARG_P32(uap, events),
	    *retval * sizeof(*events32));

	kmem_free(events32, *retval * sizeof(*events32));

	return error;
}

cvs diff -r1.143 -r1.144 src/sys/compat/netbsd32/syscalls.master (expand / switch to unified diff)

--- src/sys/compat/netbsd32/syscalls.master 2023/07/30 05:30:45 1.143
+++ src/sys/compat/netbsd32/syscalls.master 2023/07/30 06:52:20 1.144
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1 $NetBSD: syscalls.master,v 1.143 2023/07/30 05:30:45 rin Exp $ 1 $NetBSD: syscalls.master,v 1.144 2023/07/30 06:52:20 rin Exp $
2 2
3; from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp 3; from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp
4; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 4; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
5 5
6; NetBSD system call name/number "master" file. 6; NetBSD system call name/number "master" file.
7; (See syscalls.conf to see what it is processed into.) 7; (See syscalls.conf to see what it is processed into.)
8; 8;
9; Fields: number type [type-dependent ...] 9; Fields: number type [type-dependent ...]
10; number system call number, must be in order 10; number system call number, must be in order
11; type one of STD, OBSOL, UNIMPL, IGNORED, NODEF, NOARGS, or one of 11; type one of STD, OBSOL, UNIMPL, IGNORED, NODEF, NOARGS, or one of
12; the compatibility options defined in syscalls.conf. 12; the compatibility options defined in syscalls.conf.
13; 13;
14; types: 14; types:
@@ -1212,16 +1212,20 @@ @@ -1212,16 +1212,20 @@
1212 acl_type_t type, netbsd32_aclp_t aclp); } 1212 acl_type_t type, netbsd32_aclp_t aclp); }
1213498 STD { int|netbsd32||__acl_aclcheck_fd(int filedes, \ 1213498 STD { int|netbsd32||__acl_aclcheck_fd(int filedes, \
1214 acl_type_t type, netbsd32_aclp_t aclp); } 1214 acl_type_t type, netbsd32_aclp_t aclp); }
1215499 STD { long|netbsd32||lpathconf(const netbsd32_charp path, \ 1215499 STD { long|netbsd32||lpathconf(const netbsd32_charp path, \
1216 int name); } 1216 int name); }
1217500 STD { int|netbsd32||memfd_create( \ 1217500 STD { int|netbsd32||memfd_create( \
1218 const netbsd32_charp name, unsigned int flags); } 1218 const netbsd32_charp name, unsigned int flags); }
1219501 STD { int|netbsd32|100|kevent(int fd, \ 1219501 STD { int|netbsd32|100|kevent(int fd, \
1220 const netbsd32_keventp_t changelist, \ 1220 const netbsd32_keventp_t changelist, \
1221 netbsd32_size_t nchanges, \ 1221 netbsd32_size_t nchanges, \
1222 netbsd32_keventp_t eventlist, \ 1222 netbsd32_keventp_t eventlist, \
1223 netbsd32_size_t nevents, \ 1223 netbsd32_size_t nevents, \
1224 const netbsd32_timespecp_t timeout); } 1224 const netbsd32_timespecp_t timeout); }
1225502 UNIMPL epoll_create1 1225502 STD { int|netbsd32||epoll_create1(int flags); }
1226503 UNIMPL epoll_ctl 1226503 STD { int|netbsd32||epoll_ctl(int epfd, int op, int fd, \
1227504 UNIMPL epoll_pwait2 1227 netbsd32_epoll_eventp_t event); }
 1228504 STD { int|netbsd32||epoll_pwait2(int epfd, \
 1229 netbsd32_epoll_eventp_t events, int maxevents, \
 1230 netbsd32_timespecp_t timeout, \
 1231 netbsd32_sigsetp_t sigmask); }