linux32_socket.c revision 1.5.12.1 1 1.5.12.1 wrstuden /* $NetBSD: linux32_socket.c,v 1.5.12.1 2008/05/10 23:48:56 wrstuden Exp $ */
2 1.1 manu
3 1.1 manu /*-
4 1.1 manu * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 1.1 manu *
6 1.1 manu * Redistribution and use in source and binary forms, with or without
7 1.1 manu * modification, are permitted provided that the following conditions
8 1.1 manu * are met:
9 1.1 manu * 1. Redistributions of source code must retain the above copyright
10 1.1 manu * notice, this list of conditions and the following disclaimer.
11 1.1 manu * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 manu * notice, this list of conditions and the following disclaimer in the
13 1.1 manu * documentation and/or other materials provided with the distribution.
14 1.1 manu * 3. All advertising materials mentioning features or use of this software
15 1.1 manu * must display the following acknowledgement:
16 1.1 manu * This product includes software developed by Emmanuel Dreyfus
17 1.1 manu * 4. The name of the author may not be used to endorse or promote
18 1.1 manu * products derived from this software without specific prior written
19 1.1 manu * permission.
20 1.1 manu *
21 1.1 manu * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 1.1 manu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 1.1 manu * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 manu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 1.1 manu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 manu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 manu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 manu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 manu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 manu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 manu * POSSIBILITY OF SUCH DAMAGE.
32 1.1 manu */
33 1.1 manu
34 1.1 manu #include <sys/cdefs.h>
35 1.1 manu
36 1.5.12.1 wrstuden __KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.5.12.1 2008/05/10 23:48:56 wrstuden Exp $");
37 1.1 manu
38 1.1 manu #include <sys/types.h>
39 1.1 manu #include <sys/param.h>
40 1.1 manu #include <sys/fstypes.h>
41 1.1 manu #include <sys/signal.h>
42 1.1 manu #include <sys/dirent.h>
43 1.1 manu #include <sys/kernel.h>
44 1.1 manu #include <sys/fcntl.h>
45 1.1 manu #include <sys/select.h>
46 1.1 manu #include <sys/proc.h>
47 1.1 manu #include <sys/ucred.h>
48 1.1 manu #include <sys/swap.h>
49 1.1 manu
50 1.1 manu #include <machine/types.h>
51 1.1 manu
52 1.5.12.1 wrstuden #include <sys/sa.h>
53 1.1 manu #include <sys/syscallargs.h>
54 1.1 manu
55 1.1 manu #include <compat/netbsd32/netbsd32.h>
56 1.1 manu #include <compat/netbsd32/netbsd32_conv.h>
57 1.1 manu #include <compat/netbsd32/netbsd32_syscallargs.h>
58 1.1 manu
59 1.1 manu #include <compat/linux/common/linux_types.h>
60 1.1 manu #include <compat/linux/common/linux_signal.h>
61 1.1 manu #include <compat/linux/common/linux_machdep.h>
62 1.1 manu #include <compat/linux/common/linux_misc.h>
63 1.1 manu #include <compat/linux/common/linux_oldolduname.h>
64 1.1 manu #include <compat/linux/linux_syscallargs.h>
65 1.1 manu
66 1.1 manu #include <compat/linux32/common/linux32_types.h>
67 1.1 manu #include <compat/linux32/common/linux32_signal.h>
68 1.1 manu #include <compat/linux32/common/linux32_machdep.h>
69 1.1 manu #include <compat/linux32/common/linux32_sysctl.h>
70 1.1 manu #include <compat/linux32/common/linux32_socketcall.h>
71 1.1 manu #include <compat/linux32/linux32_syscallargs.h>
72 1.1 manu
73 1.1 manu int
74 1.5 dsl linux32_sys_socketpair(struct lwp *l, const struct linux32_sys_socketpair_args *uap, register_t *retval)
75 1.1 manu {
76 1.5 dsl /* {
77 1.1 manu syscallarg(int) domain;
78 1.1 manu syscallarg(int) type;
79 1.1 manu syscallarg(int) protocol;
80 1.1 manu syscallarg(netbsd32_intp) rsv;
81 1.5 dsl } */
82 1.1 manu struct linux_sys_socketpair_args ua;
83 1.1 manu
84 1.1 manu NETBSD32TO64_UAP(domain);
85 1.1 manu NETBSD32TO64_UAP(type);
86 1.1 manu NETBSD32TO64_UAP(protocol);
87 1.1 manu NETBSD32TOP_UAP(rsv, int)
88 1.1 manu
89 1.1 manu return linux_sys_socketpair(l, &ua, retval);
90 1.1 manu }
91 1.1 manu
92 1.1 manu int
93 1.5 dsl linux32_sys_sendto(struct lwp *l, const struct linux32_sys_sendto_args *uap, register_t *retval)
94 1.1 manu {
95 1.5 dsl /* {
96 1.1 manu syscallarg(int) s;
97 1.5 dsl syscallarg(netbsd32_voidp) msg;
98 1.1 manu syscallarg(int) len;
99 1.1 manu syscallarg(int) flags;
100 1.1 manu syscallarg(netbsd32_osockaddrp_t) to;
101 1.1 manu syscallarg(int) tolen;
102 1.5 dsl } */
103 1.1 manu struct linux_sys_sendto_args ua;
104 1.1 manu
105 1.1 manu NETBSD32TO64_UAP(s);
106 1.1 manu NETBSD32TOP_UAP(msg, void);
107 1.1 manu NETBSD32TO64_UAP(len);
108 1.1 manu NETBSD32TO64_UAP(flags);
109 1.1 manu NETBSD32TOP_UAP(to, struct osockaddr);
110 1.1 manu NETBSD32TO64_UAP(tolen);
111 1.1 manu
112 1.1 manu return linux_sys_sendto(l, &ua, retval);
113 1.1 manu }
114 1.1 manu
115 1.1 manu
116 1.1 manu int
117 1.5 dsl linux32_sys_recvfrom(struct lwp *l, const struct linux32_sys_recvfrom_args *uap, register_t *retval)
118 1.1 manu {
119 1.5 dsl /* {
120 1.1 manu syscallarg(int) s;
121 1.5 dsl syscallarg(netbsd32_voidp) buf;
122 1.1 manu syscallarg(netbsd32_size_t) len;
123 1.1 manu syscallarg(int) flags;
124 1.1 manu syscallarg(netbsd32_osockaddrp_t) from;
125 1.1 manu syscallarg(netbsd32_intp) fromlenaddr;
126 1.5 dsl } */
127 1.1 manu struct linux_sys_recvfrom_args ua;
128 1.1 manu
129 1.1 manu NETBSD32TO64_UAP(s);
130 1.1 manu NETBSD32TOP_UAP(buf, void);
131 1.1 manu NETBSD32TO64_UAP(len);
132 1.1 manu NETBSD32TO64_UAP(flags);
133 1.1 manu NETBSD32TOP_UAP(from, struct osockaddr);
134 1.1 manu NETBSD32TOP_UAP(fromlenaddr, unsigned int);
135 1.1 manu
136 1.1 manu return linux_sys_recvfrom(l, &ua, retval);
137 1.1 manu }
138 1.1 manu
139 1.1 manu int
140 1.5 dsl linux32_sys_setsockopt(struct lwp *l, const struct linux32_sys_setsockopt_args *uap, register_t *retval)
141 1.1 manu {
142 1.5 dsl /* {
143 1.1 manu syscallarg(int) s;
144 1.1 manu syscallarg(int) level;
145 1.1 manu syscallarg(int) optname;
146 1.1 manu syscallarg(netbsd32_voidp) optval;
147 1.1 manu syscallarg(int) optlen;
148 1.5 dsl } */
149 1.1 manu struct linux_sys_setsockopt_args ua;
150 1.1 manu
151 1.1 manu NETBSD32TO64_UAP(s);
152 1.1 manu NETBSD32TO64_UAP(level);
153 1.1 manu NETBSD32TO64_UAP(optname);
154 1.1 manu NETBSD32TOP_UAP(optval, void);
155 1.1 manu NETBSD32TO64_UAP(optlen);
156 1.1 manu
157 1.1 manu return linux_sys_setsockopt(l, &ua, retval);
158 1.1 manu }
159 1.1 manu
160 1.1 manu
161 1.1 manu int
162 1.5 dsl linux32_sys_getsockopt(struct lwp *l, const struct linux32_sys_getsockopt_args *uap, register_t *retval)
163 1.1 manu {
164 1.5 dsl /* {
165 1.1 manu syscallarg(int) s;
166 1.1 manu syscallarg(int) level;
167 1.1 manu syscallarg(int) optname;
168 1.1 manu syscallarg(netbsd32_voidp) optval;
169 1.1 manu syscallarg(netbsd32_intp) optlen;
170 1.5 dsl } */
171 1.1 manu struct linux_sys_getsockopt_args ua;
172 1.1 manu
173 1.1 manu NETBSD32TO64_UAP(s);
174 1.1 manu NETBSD32TO64_UAP(level);
175 1.1 manu NETBSD32TO64_UAP(optname);
176 1.1 manu NETBSD32TOP_UAP(optval, void);
177 1.1 manu NETBSD32TOP_UAP(optlen, int);
178 1.1 manu
179 1.1 manu return linux_sys_getsockopt(l, &ua, retval);
180 1.1 manu }
181 1.1 manu
182 1.1 manu int
183 1.5 dsl linux32_sys_socket(struct lwp *l, const struct linux32_sys_socket_args *uap, register_t *retval)
184 1.1 manu {
185 1.5 dsl /* {
186 1.1 manu syscallarg(int) domain;
187 1.1 manu syscallarg(int) type;
188 1.1 manu syscallarg(int) protocol;
189 1.5 dsl } */
190 1.1 manu struct linux_sys_socket_args ua;
191 1.1 manu
192 1.1 manu NETBSD32TO64_UAP(domain);
193 1.1 manu NETBSD32TO64_UAP(type);
194 1.1 manu NETBSD32TO64_UAP(protocol);
195 1.1 manu
196 1.1 manu return linux_sys_socket(l, &ua, retval);
197 1.1 manu }
198 1.1 manu
199 1.1 manu int
200 1.5 dsl linux32_sys_bind(struct lwp *l, const struct linux32_sys_bind_args *uap, register_t *retval)
201 1.1 manu {
202 1.5 dsl /* {
203 1.1 manu syscallarg(int) s;
204 1.1 manu syscallarg(netbsd32_osockaddrp_t) name;
205 1.1 manu syscallarg(int) namelen;
206 1.5 dsl } */
207 1.1 manu struct linux_sys_bind_args ua;
208 1.1 manu
209 1.1 manu NETBSD32TO64_UAP(s);
210 1.1 manu NETBSD32TOP_UAP(name, struct osockaddr)
211 1.1 manu NETBSD32TO64_UAP(namelen);
212 1.1 manu
213 1.1 manu return linux_sys_bind(l, &ua, retval);
214 1.1 manu }
215 1.1 manu
216 1.1 manu int
217 1.5 dsl linux32_sys_connect(struct lwp *l, const struct linux32_sys_connect_args *uap, register_t *retval)
218 1.1 manu {
219 1.5 dsl /* {
220 1.1 manu syscallarg(int) s;
221 1.1 manu syscallarg(netbsd32_osockaddrp_t) name;
222 1.1 manu syscallarg(int) namelen;
223 1.5 dsl } */
224 1.1 manu struct linux_sys_connect_args ua;
225 1.1 manu
226 1.1 manu NETBSD32TO64_UAP(s);
227 1.1 manu NETBSD32TOP_UAP(name, struct osockaddr)
228 1.1 manu NETBSD32TO64_UAP(namelen);
229 1.1 manu
230 1.2 manu #ifdef DEBUG_LINUX
231 1.1 manu printf("linux32_sys_connect: s = %d, name = %p, namelen = %d\n",
232 1.1 manu SCARG(&ua, s), SCARG(&ua, name), SCARG(&ua, namelen));
233 1.2 manu #endif
234 1.1 manu
235 1.1 manu return linux_sys_connect(l, &ua, retval);
236 1.1 manu }
237 1.1 manu
238 1.1 manu int
239 1.5 dsl linux32_sys_accept(struct lwp *l, const struct linux32_sys_accept_args *uap, register_t *retval)
240 1.1 manu {
241 1.5 dsl /* {
242 1.1 manu syscallarg(int) s;
243 1.1 manu syscallarg(netbsd32_osockaddrp_t) name;
244 1.1 manu syscallarg(netbsd32_intp) anamelen;
245 1.5 dsl } */
246 1.1 manu struct linux_sys_accept_args ua;
247 1.1 manu
248 1.1 manu NETBSD32TO64_UAP(s);
249 1.1 manu NETBSD32TOP_UAP(name, struct osockaddr)
250 1.1 manu NETBSD32TOP_UAP(anamelen, int);
251 1.1 manu
252 1.1 manu return linux_sys_accept(l, &ua, retval);
253 1.1 manu }
254 1.1 manu
255 1.1 manu int
256 1.5 dsl linux32_sys_getpeername(struct lwp *l, const struct linux32_sys_getpeername_args *uap, register_t *retval)
257 1.1 manu {
258 1.5 dsl /* {
259 1.1 manu syscallarg(int) fdes;
260 1.1 manu syscallarg(netbsd32_sockaddrp_t) asa;
261 1.1 manu syscallarg(netbsd32_intp) alen;
262 1.5 dsl } */
263 1.1 manu struct linux_sys_getpeername_args ua;
264 1.1 manu
265 1.1 manu NETBSD32TO64_UAP(fdes);
266 1.1 manu NETBSD32TOP_UAP(asa, struct sockaddr)
267 1.1 manu NETBSD32TOP_UAP(alen, int);
268 1.1 manu
269 1.1 manu return linux_sys_getpeername(l, &ua, retval);
270 1.1 manu }
271 1.1 manu
272 1.1 manu int
273 1.5 dsl linux32_sys_getsockname(struct lwp *l, const struct linux32_sys_getsockname_args *uap, register_t *retval)
274 1.1 manu {
275 1.5 dsl /* {
276 1.1 manu syscallarg(int) fdec;
277 1.1 manu syscallarg(netbsd32_charp) asa;
278 1.1 manu syscallarg(netbsd32_intp) alen;
279 1.5 dsl } */
280 1.1 manu struct linux_sys_getsockname_args ua;
281 1.1 manu
282 1.1 manu NETBSD32TO64_UAP(fdec);
283 1.1 manu NETBSD32TOP_UAP(asa, char)
284 1.1 manu NETBSD32TOP_UAP(alen, int);
285 1.1 manu
286 1.1 manu return linux_sys_getsockname(l, &ua, retval);
287 1.1 manu }
288 1.1 manu
289 1.1 manu int
290 1.5 dsl linux32_sys_sendmsg(struct lwp *l, const struct linux32_sys_sendmsg_args *uap, register_t *retval)
291 1.1 manu {
292 1.5 dsl /* {
293 1.1 manu syscallarg(int) s;
294 1.1 manu syscallarg(netbsd32_msghdrp_t) msg;
295 1.1 manu syscallarg(int) flags;
296 1.5 dsl } */
297 1.1 manu struct linux_sys_sendmsg_args ua;
298 1.1 manu
299 1.1 manu NETBSD32TO64_UAP(s);
300 1.1 manu NETBSD32TOP_UAP(msg, struct msghdr);
301 1.1 manu NETBSD32TO64_UAP(flags);
302 1.1 manu
303 1.1 manu return linux_sys_sendmsg(l, &ua, retval);
304 1.1 manu }
305 1.1 manu
306 1.1 manu int
307 1.5 dsl linux32_sys_recvmsg(struct lwp *l, const struct linux32_sys_recvmsg_args *uap, register_t *retval)
308 1.1 manu {
309 1.5 dsl /* {
310 1.1 manu syscallarg(int) s;
311 1.1 manu syscallarg(netbsd32_msghdrp_t) msg;
312 1.1 manu syscallarg(int) flags;
313 1.5 dsl } */
314 1.1 manu struct linux_sys_recvmsg_args ua;
315 1.1 manu
316 1.1 manu NETBSD32TO64_UAP(s);
317 1.1 manu NETBSD32TOP_UAP(msg, struct msghdr);
318 1.1 manu NETBSD32TO64_UAP(flags);
319 1.1 manu
320 1.1 manu return linux_sys_recvmsg(l, &ua, retval);
321 1.1 manu }
322 1.1 manu
323 1.1 manu int
324 1.5 dsl linux32_sys_send(struct lwp *l, const struct linux32_sys_send_args *uap, register_t *retval)
325 1.1 manu {
326 1.5 dsl /* {
327 1.1 manu syscallarg(int) s;
328 1.1 manu syscallarg(netbsd32_voidp) buf;
329 1.1 manu syscallarg(int) len;
330 1.1 manu syscallarg(int) flags;
331 1.5 dsl } */
332 1.1 manu struct sys_sendto_args ua;
333 1.1 manu
334 1.1 manu NETBSD32TO64_UAP(s);
335 1.1 manu NETBSD32TOP_UAP(buf, void);
336 1.1 manu NETBSD32TO64_UAP(len);
337 1.1 manu NETBSD32TO64_UAP(flags);
338 1.1 manu SCARG(&ua, to) = NULL;
339 1.1 manu SCARG(&ua, tolen) = 0;
340 1.1 manu
341 1.1 manu return sys_sendto(l, &ua, retval);
342 1.1 manu }
343 1.1 manu
344 1.1 manu int
345 1.5 dsl linux32_sys_recv(struct lwp *l, const struct linux32_sys_recv_args *uap, register_t *retval)
346 1.1 manu {
347 1.5 dsl /* {
348 1.1 manu syscallarg(int) s;
349 1.1 manu syscallarg(netbsd32_voidp) buf;
350 1.1 manu syscallarg(int) len;
351 1.1 manu syscallarg(int) flags;
352 1.5 dsl } */
353 1.1 manu struct sys_recvfrom_args ua;
354 1.1 manu
355 1.1 manu NETBSD32TO64_UAP(s);
356 1.1 manu NETBSD32TOP_UAP(buf, void);
357 1.1 manu NETBSD32TO64_UAP(len);
358 1.1 manu NETBSD32TO64_UAP(flags);
359 1.1 manu SCARG(&ua, from) = NULL;
360 1.1 manu SCARG(&ua, fromlenaddr) = NULL;
361 1.1 manu
362 1.1 manu return sys_recvfrom(l, &ua, retval);
363 1.1 manu }
364