xref: /netbsd-src/sys/compat/netbsd32/netbsd32_select.c (revision a13c9853a06b563a66bb24f50e23ccc2287615ee)
1*a13c9853Skamil /*	$NetBSD: netbsd32_select.c,v 1.20 2019/09/20 15:16:41 kamil Exp $	*/
2da9e4bd3Smrg 
3da9e4bd3Smrg /*
4da9e4bd3Smrg  * Copyright (c) 1998, 2001 Matthew R. Green
5da9e4bd3Smrg  * All rights reserved.
6da9e4bd3Smrg  *
7da9e4bd3Smrg  * Redistribution and use in source and binary forms, with or without
8da9e4bd3Smrg  * modification, are permitted provided that the following conditions
9da9e4bd3Smrg  * are met:
10da9e4bd3Smrg  * 1. Redistributions of source code must retain the above copyright
11da9e4bd3Smrg  *    notice, this list of conditions and the following disclaimer.
12da9e4bd3Smrg  * 2. Redistributions in binary form must reproduce the above copyright
13da9e4bd3Smrg  *    notice, this list of conditions and the following disclaimer in the
14da9e4bd3Smrg  *    documentation and/or other materials provided with the distribution.
15da9e4bd3Smrg  *
16da9e4bd3Smrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17da9e4bd3Smrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18da9e4bd3Smrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19da9e4bd3Smrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20da9e4bd3Smrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21da9e4bd3Smrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22da9e4bd3Smrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23da9e4bd3Smrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24da9e4bd3Smrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25da9e4bd3Smrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26da9e4bd3Smrg  * SUCH DAMAGE.
27da9e4bd3Smrg  */
28da9e4bd3Smrg 
29dab6ef8bSlukem #include <sys/cdefs.h>
30*a13c9853Skamil __KERNEL_RCSID(0, "$NetBSD: netbsd32_select.c,v 1.20 2019/09/20 15:16:41 kamil Exp $");
31dab6ef8bSlukem 
32da9e4bd3Smrg #include <sys/param.h>
33da9e4bd3Smrg #include <sys/systm.h>
34da9e4bd3Smrg #include <sys/mount.h>
35da9e4bd3Smrg #include <sys/time.h>
36da9e4bd3Smrg #include <sys/vnode.h>
37da9e4bd3Smrg #include <sys/file.h>
38da9e4bd3Smrg #include <sys/filedesc.h>
3957017881Scube #include <sys/poll.h>
400056ee71Scube #include <sys/select.h>
41b041fac9Schristos #include <sys/dirent.h>
42da9e4bd3Smrg 
43da9e4bd3Smrg #include <sys/proc.h>
44da9e4bd3Smrg 
45da9e4bd3Smrg #include <net/if.h>
46da9e4bd3Smrg 
47da9e4bd3Smrg #include <compat/netbsd32/netbsd32.h>
48da9e4bd3Smrg #include <compat/netbsd32/netbsd32_syscall.h>
49da9e4bd3Smrg #include <compat/netbsd32/netbsd32_syscallargs.h>
50da9e4bd3Smrg #include <compat/netbsd32/netbsd32_conv.h>
51da9e4bd3Smrg 
52da9e4bd3Smrg int
netbsd32___select50(struct lwp * l,const struct netbsd32___select50_args * uap,register_t * retval)5312839500Srmind netbsd32___select50(struct lwp *l,
5412839500Srmind     const struct netbsd32___select50_args *uap, register_t *retval)
55da9e4bd3Smrg {
567e2790cfSdsl 	/* {
57da9e4bd3Smrg 		syscallarg(int) nd;
58da9e4bd3Smrg 		syscallarg(netbsd32_fd_setp_t) in;
59da9e4bd3Smrg 		syscallarg(netbsd32_fd_setp_t) ou;
60da9e4bd3Smrg 		syscallarg(netbsd32_fd_setp_t) ex;
61da9e4bd3Smrg 		syscallarg(netbsd32_timevalp_t) tv;
627e2790cfSdsl 	} */
630056ee71Scube 	int error;
64da9e4bd3Smrg 	struct netbsd32_timeval tv32;
652b1b4bc6Schristos 	struct timespec ats, *ts = NULL;
66da9e4bd3Smrg 
67d364d308Sdsl 	if (SCARG_P32(uap, tv)) {
68d364d308Sdsl 		error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32));
69d364d308Sdsl 		if (error != 0)
700056ee71Scube 			return error;
71*a13c9853Skamil 
72*a13c9853Skamil 		if (tv32.tv_usec < 0 || tv32.tv_usec >= 1000000)
73*a13c9853Skamil 			return EINVAL;
74*a13c9853Skamil 
752b1b4bc6Schristos 		ats.tv_sec = tv32.tv_sec;
762b1b4bc6Schristos 		ats.tv_nsec = tv32.tv_usec * 1000;
772b1b4bc6Schristos 		ts = &ats;
78da9e4bd3Smrg 	}
790056ee71Scube 
8012839500Srmind 	return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
812b1b4bc6Schristos 	    SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, NULL);
82da9e4bd3Smrg }
8357017881Scube 
8457017881Scube int
netbsd32___pselect50(struct lwp * l,const struct netbsd32___pselect50_args * uap,register_t * retval)8512839500Srmind netbsd32___pselect50(struct lwp *l,
8612839500Srmind     const struct netbsd32___pselect50_args *uap, register_t *retval)
8757017881Scube {
887e2790cfSdsl 	/* {
8957017881Scube 		syscallarg(int) nd;
9057017881Scube 		syscallarg(netbsd32_fd_setp_t) in;
9157017881Scube 		syscallarg(netbsd32_fd_setp_t) ou;
9257017881Scube 		syscallarg(netbsd32_fd_setp_t) ex;
9357017881Scube 		syscallarg(const netbsd32_timespecp_t) ts;
9457017881Scube 		syscallarg(const netbsd32_sigsetp_t) mask;
957e2790cfSdsl 	} */
9657017881Scube 	int error;
9757017881Scube 	struct netbsd32_timespec ts32;
982b1b4bc6Schristos 	struct timespec ats, *ts = NULL;
9957017881Scube 	sigset_t amask, *mask = NULL;
10057017881Scube 
101d364d308Sdsl 	if (SCARG_P32(uap, ts)) {
102d364d308Sdsl 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
103d364d308Sdsl 		if (error != 0)
10457017881Scube 			return error;
1052b1b4bc6Schristos 		netbsd32_to_timespec(&ts32, &ats);
1062b1b4bc6Schristos 		ts = &ats;
10757017881Scube 	}
108d364d308Sdsl 	if (SCARG_P32(uap, mask)) {
109d364d308Sdsl 		error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
110d364d308Sdsl 		if (error != 0)
11157017881Scube 			return error;
11257017881Scube 		mask = &amask;
11357017881Scube 	}
11457017881Scube 
11512839500Srmind 	return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
1162b1b4bc6Schristos 	    SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, mask);
11757017881Scube }
11857017881Scube 
11957017881Scube int
netbsd32___pollts50(struct lwp * l,const struct netbsd32___pollts50_args * uap,register_t * retval)12012839500Srmind netbsd32___pollts50(struct lwp *l, const struct netbsd32___pollts50_args *uap,
12112839500Srmind     register_t *retval)
12257017881Scube {
1237e2790cfSdsl 	/* {
12457017881Scube 		syscallarg(struct netbsd32_pollfdp_t) fds;
12557017881Scube 		syscallarg(u_int) nfds;
12657017881Scube 		syscallarg(const netbsd32_timespecp_t) ts;
12757017881Scube 		syscallarg(const netbsd32_sigsetp_t) mask;
1287e2790cfSdsl 	} */
12957017881Scube 	int error;
13057017881Scube 	struct netbsd32_timespec ts32;
1312b1b4bc6Schristos 	struct timespec ats, *ts = NULL;
13257017881Scube 	sigset_t amask, *mask = NULL;
13357017881Scube 
134d364d308Sdsl 	if (SCARG_P32(uap, ts)) {
135d364d308Sdsl 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
136d364d308Sdsl 		if (error != 0)
13757017881Scube 			return error;
1382b1b4bc6Schristos 		netbsd32_to_timespec(&ts32, &ats);
1392b1b4bc6Schristos 		ts = &ats;
14057017881Scube 	}
141a065e516Sdsl 	if (NETBSD32PTR64( SCARG(uap, mask))) {
142d364d308Sdsl 		error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
143d364d308Sdsl 		if (error != 0)
14457017881Scube 			return error;
14557017881Scube 		mask = &amask;
14657017881Scube 	}
14757017881Scube 
14812839500Srmind 	return pollcommon(retval, SCARG_P32(uap, fds),
1492b1b4bc6Schristos 	    SCARG(uap, nfds), ts, mask);
15057017881Scube }
151