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