xref: /netbsd-src/sys/compat/netbsd32/netbsd32_select.c (revision 267197ec1eebfcb9810ea27a89625b6ddf68e3e7)
1 /*	$NetBSD: netbsd32_select.c,v 1.14 2007/12/20 23:03:02 dsl Exp $	*/
2 
3 /*
4  * Copyright (c) 1998, 2001 Matthew R. Green
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_select.c,v 1.14 2007/12/20 23:03:02 dsl Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/malloc.h>
37 #include <sys/mount.h>
38 #include <sys/time.h>
39 #include <sys/vnode.h>
40 #include <sys/file.h>
41 #include <sys/filedesc.h>
42 #include <sys/poll.h>
43 #include <sys/select.h>
44 #include <sys/dirent.h>
45 
46 #include <sys/proc.h>
47 
48 #include <net/if.h>
49 
50 #include <compat/netbsd32/netbsd32.h>
51 #include <compat/netbsd32/netbsd32_syscall.h>
52 #include <compat/netbsd32/netbsd32_syscallargs.h>
53 #include <compat/netbsd32/netbsd32_conv.h>
54 
55 int
56 netbsd32_select(struct lwp *l, const struct netbsd32_select_args *uap, register_t *retval)
57 {
58 	/* {
59 		syscallarg(int) nd;
60 		syscallarg(netbsd32_fd_setp_t) in;
61 		syscallarg(netbsd32_fd_setp_t) ou;
62 		syscallarg(netbsd32_fd_setp_t) ex;
63 		syscallarg(netbsd32_timevalp_t) tv;
64 	} */
65 	int error;
66 	struct netbsd32_timeval tv32;
67 	struct timeval atv, *tv = NULL;
68 
69 	if (SCARG_P32(uap, tv)) {
70 		error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32));
71 		if (error != 0)
72 			return error;
73 		netbsd32_to_timeval(&tv32, &atv);
74 		tv = &atv;
75 	}
76 
77 	return selcommon(l, retval, SCARG(uap, nd), SCARG_P32(uap, in),
78 	    SCARG_P32(uap, ou), SCARG_P32(uap, ex), tv, NULL);
79 }
80 
81 int
82 netbsd32_pselect(struct lwp *l, const struct netbsd32_pselect_args *uap, register_t *retval)
83 {
84 	/* {
85 		syscallarg(int) nd;
86 		syscallarg(netbsd32_fd_setp_t) in;
87 		syscallarg(netbsd32_fd_setp_t) ou;
88 		syscallarg(netbsd32_fd_setp_t) ex;
89 		syscallarg(const netbsd32_timespecp_t) ts;
90 		syscallarg(const netbsd32_sigsetp_t) mask;
91 	} */
92 	int error;
93 	struct netbsd32_timespec ts32;
94 	struct timespec ts;
95 	struct timeval atv, *tv = NULL;
96 	sigset_t amask, *mask = NULL;
97 
98 	if (SCARG_P32(uap, ts)) {
99 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
100 		if (error != 0)
101 			return error;
102 		netbsd32_to_timespec(&ts32, &ts);
103 		atv.tv_sec = ts.tv_sec;
104 		atv.tv_usec = ts.tv_nsec / 1000;
105 		tv = &atv;
106 	}
107 	if (SCARG_P32(uap, mask)) {
108 		error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
109 		if (error != 0)
110 			return error;
111 		mask = &amask;
112 	}
113 
114 	return selcommon(l, retval, SCARG(uap, nd), SCARG_P32(uap, in),
115 	    SCARG_P32(uap, ou), SCARG_P32(uap, ex), tv, mask);
116 }
117 
118 int
119 netbsd32_pollts(struct lwp *l, const struct netbsd32_pollts_args *uap, register_t *retval)
120 {
121 	/* {
122 		syscallarg(struct netbsd32_pollfdp_t) fds;
123 		syscallarg(u_int) nfds;
124 		syscallarg(const netbsd32_timespecp_t) ts;
125 		syscallarg(const netbsd32_sigsetp_t) mask;
126 	} */
127 	int error;
128 	struct netbsd32_timespec ts32;
129 	struct timespec ts;
130 	struct timeval atv, *tv = NULL;
131 	sigset_t amask, *mask = NULL;
132 
133 	if (SCARG_P32(uap, ts)) {
134 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
135 		if (error != 0)
136 			return error;
137 		netbsd32_to_timespec(&ts32, &ts);
138 		atv.tv_sec = ts.tv_sec;
139 		atv.tv_usec = ts.tv_nsec / 1000;
140 		tv = &atv;
141 	}
142 	if (NETBSD32PTR64( SCARG(uap, mask))) {
143 		error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
144 		if (error != 0)
145 			return error;
146 		mask = &amask;
147 	}
148 
149 	return pollcommon(l, retval, SCARG_P32(uap, fds),
150 	    SCARG(uap, nfds), tv, mask);
151 }
152