Module Name:    src
Committed By:   rin
Date:           Sun Jul 30 06:52:21 UTC 2023

Modified Files:
        src/sys/compat/netbsd32: files.netbsd32 netbsd32.h netbsd32_conv.h
            syscalls.master
Added Files:
        src/sys/compat/netbsd32: netbsd32_epoll.c

Log Message:
COMPAT_NETBSD32: Add support for epoll(2).


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/compat/netbsd32/files.netbsd32
cvs rdiff -u -r1.142 -r1.143 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.47 -r1.48 src/sys/compat/netbsd32/netbsd32_conv.h
cvs rdiff -u -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_epoll.c
cvs rdiff -u -r1.143 -r1.144 src/sys/compat/netbsd32/syscalls.master

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/netbsd32/files.netbsd32
diff -u src/sys/compat/netbsd32/files.netbsd32:1.54 src/sys/compat/netbsd32/files.netbsd32:1.55
--- src/sys/compat/netbsd32/files.netbsd32:1.54	Mon Dec 19 23:19:51 2022
+++ src/sys/compat/netbsd32/files.netbsd32	Sun Jul 30 06:52:20 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: files.netbsd32,v 1.54 2022/12/19 23:19:51 pgoyette Exp $
+#	$NetBSD: files.netbsd32,v 1.55 2023/07/30 06:52:20 rin Exp $
 #
 # config file description for machine-independent netbsd32 compat code.
 # included by ports that need it.
@@ -16,6 +16,7 @@ file	compat/netbsd32/netbsd32_exec_elf32
 file	compat/netbsd32/netbsd32_exec_aout.c	compat_netbsd32 & exec_aout
 file	compat/netbsd32/netbsd32_netbsd.c	compat_netbsd32
 #file	compat/netbsd32/netbsd32_drm.c		compat_netbsd32 & drmkms
+file	compat/netbsd32/netbsd32_epoll.c	compat_netbsd32
 file	compat/netbsd32/netbsd32_event.c	compat_netbsd32
 file	compat/netbsd32/netbsd32_execve.c	compat_netbsd32
 file	compat/netbsd32/netbsd32_fd.c		compat_netbsd32

Index: src/sys/compat/netbsd32/netbsd32.h
diff -u src/sys/compat/netbsd32/netbsd32.h:1.142 src/sys/compat/netbsd32/netbsd32.h:1.143
--- src/sys/compat/netbsd32/netbsd32.h:1.142	Sat Jul 29 12:38:25 2023
+++ src/sys/compat/netbsd32/netbsd32.h	Sun Jul 30 06:52:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32.h,v 1.142 2023/07/29 12:38:25 rin Exp $	*/
+/*	$NetBSD: netbsd32.h,v 1.143 2023/07/30 06:52:20 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -208,6 +208,15 @@ typedef netbsd32_int64 netbsd32_off_t;
 typedef netbsd32_uint64 netbsd32_ino_t;
 typedef netbsd32_int64 netbsd32_blkcnt_t;
 
+/* from <sys/epoll.h> */
+typedef netbsd32_uint64 netbsd32_epoll_data_t;
+
+typedef netbsd32_pointer_t netbsd32_epoll_eventp_t;
+struct netbsd32_epoll_event {
+	uint32_t		events;
+	netbsd32_epoll_data_t	data;
+};
+
 /* from <sys/spawn.h> */
 typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actionsp;
 typedef netbsd32_pointer_t netbsd32_posix_spawnattrp;

Index: src/sys/compat/netbsd32/netbsd32_conv.h
diff -u src/sys/compat/netbsd32/netbsd32_conv.h:1.47 src/sys/compat/netbsd32/netbsd32_conv.h:1.48
--- src/sys/compat/netbsd32/netbsd32_conv.h:1.47	Sat Jul 29 12:38:25 2023
+++ src/sys/compat/netbsd32/netbsd32_conv.h	Sun Jul 30 06:52:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_conv.h,v 1.47 2023/07/29 12:38:25 rin Exp $	*/
+/*	$NetBSD: netbsd32_conv.h,v 1.48 2023/07/30 06:52:20 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -43,6 +43,7 @@
 #include <sys/time.h>
 #include <sys/timex.h>
 #include <sys/event.h>
+#include <sys/epoll.h>
 
 #include <compat/sys/dirent.h>
 
@@ -956,4 +957,24 @@ netbsd32_from_mq_attr(const struct mq_at
 	a32->mq_curmsgs = attr->mq_curmsgs;
 }
 
+static __inline void
+netbsd32_to_epoll_event(const struct netbsd32_epoll_event *ee32,
+    struct epoll_event *ee)
+{
+
+	memset(ee, 0, sizeof(*ee));
+	ee->events = ee32->events;
+	ee->data = ee32->data;
+}
+
+static __inline void
+netbsd32_from_epoll_event(const struct epoll_event *ee,
+    struct netbsd32_epoll_event *ee32)
+{
+
+	memset(ee32, 0, sizeof(*ee32));
+	ee32->events = ee->events;
+	ee32->data = ee->data;
+}
+
 #endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */

Index: src/sys/compat/netbsd32/syscalls.master
diff -u src/sys/compat/netbsd32/syscalls.master:1.143 src/sys/compat/netbsd32/syscalls.master:1.144
--- src/sys/compat/netbsd32/syscalls.master:1.143	Sun Jul 30 05:30:45 2023
+++ src/sys/compat/netbsd32/syscalls.master	Sun Jul 30 06:52:20 2023
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.143 2023/07/30 05:30:45 rin Exp $
+	$NetBSD: syscalls.master,v 1.144 2023/07/30 06:52:20 rin Exp $
 
 ;	from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp
 ;	@(#)syscalls.master	8.2 (Berkeley) 1/13/94
@@ -1222,6 +1222,10 @@
 			    netbsd32_keventp_t eventlist, \
 			    netbsd32_size_t nevents, \
 			    const netbsd32_timespecp_t timeout); }
-502	UNIMPL		epoll_create1
-503	UNIMPL		epoll_ctl
-504	UNIMPL		epoll_pwait2
+502	STD		{ int|netbsd32||epoll_create1(int flags); }
+503	STD		{ int|netbsd32||epoll_ctl(int epfd, int op, int fd, \
+			    netbsd32_epoll_eventp_t event); }
+504	STD		{ int|netbsd32||epoll_pwait2(int epfd, \
+			    netbsd32_epoll_eventp_t events, int maxevents, \
+			    netbsd32_timespecp_t timeout, \
+			    netbsd32_sigsetp_t sigmask); }

Added files:

Index: src/sys/compat/netbsd32/netbsd32_epoll.c
diff -u /dev/null src/sys/compat/netbsd32/netbsd32_epoll.c:1.1
--- /dev/null	Sun Jul 30 06:52:21 2023
+++ src/sys/compat/netbsd32/netbsd32_epoll.c	Sun Jul 30 06:52:20 2023
@@ -0,0 +1,151 @@
+/*	$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 <dcha...@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;
+}

Reply via email to