netbsd32_select.c revision 1.7 1 /* $NetBSD: netbsd32_select.c,v 1.7 2005/07/09 22:40:13 cube 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.7 2005/07/09 22:40:13 cube 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
45 #include <sys/proc.h>
46
47 #include <net/if.h>
48
49 #include <compat/netbsd32/netbsd32.h>
50 #include <compat/netbsd32/netbsd32_syscall.h>
51 #include <compat/netbsd32/netbsd32_syscallargs.h>
52 #include <compat/netbsd32/netbsd32_conv.h>
53
54 int
55 netbsd32_select(struct lwp *l, void *v, register_t *retval)
56 {
57 struct netbsd32_select_args /* {
58 syscallarg(int) nd;
59 syscallarg(netbsd32_fd_setp_t) in;
60 syscallarg(netbsd32_fd_setp_t) ou;
61 syscallarg(netbsd32_fd_setp_t) ex;
62 syscallarg(netbsd32_timevalp_t) tv;
63 } */ *uap = v;
64 int error;
65 struct netbsd32_timeval tv32;
66 struct timeval atv, *tv = NULL;
67
68 if (SCARG(uap, tv)) {
69 if ((error = copyin(NETBSD32PTR64(SCARG(uap, tv)),
70 (caddr_t)&tv32, sizeof(tv32))) != 0)
71 return error;
72 netbsd32_to_timeval(&tv32, &atv);
73 tv = &atv;
74 }
75
76 return selcommon(l, retval, SCARG(uap, nd), NETBSD32PTR64(SCARG(uap, in)),
77 NETBSD32PTR64(SCARG(uap, ou)), NETBSD32PTR64(SCARG(uap, ex)), tv,
78 NULL);
79 }
80
81 int
82 netbsd32_pselect(l, v, retval)
83 struct lwp *l;
84 void *v;
85 register_t *retval;
86 {
87 struct netbsd32_pselect_args /* {
88 syscallarg(int) nd;
89 syscallarg(netbsd32_fd_setp_t) in;
90 syscallarg(netbsd32_fd_setp_t) ou;
91 syscallarg(netbsd32_fd_setp_t) ex;
92 syscallarg(const netbsd32_timespecp_t) ts;
93 syscallarg(const netbsd32_sigsetp_t) mask;
94 } */ *uap = v;
95 int error;
96 struct netbsd32_timespec ts32;
97 struct timespec ts;
98 struct timeval atv, *tv = NULL;
99 sigset_t amask, *mask = NULL;
100
101 if (SCARG(uap, ts)) {
102 if ((error = copyin(NETBSD32PTR64(SCARG(uap, ts)),
103 (caddr_t)&ts32, sizeof(ts32))) != 0)
104 return error;
105 netbsd32_to_timespec(&ts32, &ts);
106 atv.tv_sec = ts.tv_sec;
107 atv.tv_usec = ts.tv_nsec / 1000;
108 tv = &atv;
109 }
110 if (SCARG(uap, mask)) {
111 if ((error = copyin(NETBSD32PTR64(SCARG(uap, mask)),
112 (caddr_t)&amask, sizeof(amask))) != 0)
113 return error;
114 mask = &amask;
115 }
116
117 return selcommon(l, retval, SCARG(uap, nd), NETBSD32PTR64(SCARG(uap, in)),
118 NETBSD32PTR64(SCARG(uap, ou)), NETBSD32PTR64(SCARG(uap, ex)), tv,
119 mask);
120 }
121
122 int
123 netbsd32_pollts(l, v, retval)
124 struct lwp *l;
125 void *v;
126 register_t *retval;
127 {
128 struct netbsd32_pollts_args /* {
129 syscallarg(struct netbsd32_pollfdp_t) fds;
130 syscallarg(u_int) nfds;
131 syscallarg(const netbsd32_timespecp_t) ts;
132 syscallarg(const netbsd32_sigsetp_t) mask;
133 } */ *uap = v;
134 int error;
135 struct netbsd32_timespec ts32;
136 struct timespec ts;
137 struct timeval atv, *tv = NULL;
138 sigset_t amask, *mask = NULL;
139
140 if (SCARG(uap, ts)) {
141 if ((error = copyin(NETBSD32PTR64(SCARG(uap, ts)),
142 (caddr_t)&ts32, sizeof(ts32))) != 0)
143 return error;
144 netbsd32_to_timespec(&ts32, &ts);
145 atv.tv_sec = ts.tv_sec;
146 atv.tv_usec = ts.tv_nsec / 1000;
147 tv = &atv;
148 }
149 if (SCARG(uap, mask)) {
150 if ((error = copyin(NETBSD32PTR64(SCARG(uap, mask)),
151 (caddr_t)&amask, sizeof(amask))) != 0)
152 return error;
153 mask = &amask;
154 }
155
156 return pollcommon(l, retval, NETBSD32PTR64(SCARG(uap, fds)),
157 SCARG(uap, nfds), tv, mask);
158 }
159