1 /* $NetBSD: linux32_socket.c,v 1.2 2006/09/13 19:55:49 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.2 2006/09/13 19:55:49 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 #ifdef DEBUG_LINUX 255 printf("linux32_sys_connect: s = %d, name = %p, namelen = %d\n", 256 SCARG(&ua, s), SCARG(&ua, name), SCARG(&ua, namelen)); 257 #endif 258 259 return linux_sys_connect(l, &ua, retval); 260 } 261 262 int 263 linux32_sys_accept(l, v, retval) 264 struct lwp *l; 265 void *v; 266 register_t *retval; 267 { 268 struct linux32_sys_accept_args /* { 269 syscallarg(int) s; 270 syscallarg(netbsd32_osockaddrp_t) name; 271 syscallarg(netbsd32_intp) anamelen; 272 } */ *uap = v; 273 struct linux_sys_accept_args ua; 274 275 NETBSD32TO64_UAP(s); 276 NETBSD32TOP_UAP(name, struct osockaddr) 277 NETBSD32TOP_UAP(anamelen, int); 278 279 return linux_sys_accept(l, &ua, retval); 280 } 281 282 int 283 linux32_sys_getpeername(l, v, retval) 284 struct lwp *l; 285 void *v; 286 register_t *retval; 287 { 288 struct linux32_sys_getpeername_args /* { 289 syscallarg(int) fdes; 290 syscallarg(netbsd32_sockaddrp_t) asa; 291 syscallarg(netbsd32_intp) alen; 292 } */ *uap = v; 293 struct linux_sys_getpeername_args ua; 294 295 NETBSD32TO64_UAP(fdes); 296 NETBSD32TOP_UAP(asa, struct sockaddr) 297 NETBSD32TOP_UAP(alen, int); 298 299 return linux_sys_getpeername(l, &ua, retval); 300 } 301 302 int 303 linux32_sys_getsockname(l, v, retval) 304 struct lwp *l; 305 void *v; 306 register_t *retval; 307 { 308 struct linux32_sys_getsockname_args /* { 309 syscallarg(int) fdec; 310 syscallarg(netbsd32_charp) asa; 311 syscallarg(netbsd32_intp) alen; 312 } */ *uap = v; 313 struct linux_sys_getsockname_args ua; 314 315 NETBSD32TO64_UAP(fdec); 316 NETBSD32TOP_UAP(asa, char) 317 NETBSD32TOP_UAP(alen, int); 318 319 return linux_sys_getsockname(l, &ua, retval); 320 } 321 322 int 323 linux32_sys_sendmsg(l, v, retval) 324 struct lwp *l; 325 void *v; 326 register_t *retval; 327 { 328 struct linux32_sys_sendmsg_args /* { 329 syscallarg(int) s; 330 syscallarg(netbsd32_msghdrp_t) msg; 331 syscallarg(int) flags; 332 } */ *uap = v; 333 struct linux_sys_sendmsg_args ua; 334 335 NETBSD32TO64_UAP(s); 336 NETBSD32TOP_UAP(msg, struct msghdr); 337 NETBSD32TO64_UAP(flags); 338 339 return linux_sys_sendmsg(l, &ua, retval); 340 } 341 342 int 343 linux32_sys_recvmsg(l, v, retval) 344 struct lwp *l; 345 void *v; 346 register_t *retval; 347 { 348 struct linux32_sys_recvmsg_args /* { 349 syscallarg(int) s; 350 syscallarg(netbsd32_msghdrp_t) msg; 351 syscallarg(int) flags; 352 } */ *uap = v; 353 struct linux_sys_recvmsg_args ua; 354 355 NETBSD32TO64_UAP(s); 356 NETBSD32TOP_UAP(msg, struct msghdr); 357 NETBSD32TO64_UAP(flags); 358 359 return linux_sys_recvmsg(l, &ua, retval); 360 } 361 362 int 363 linux32_sys_send(l, v, retval) 364 struct lwp *l; 365 void *v; 366 register_t *retval; 367 { 368 struct linux32_sys_send_args /* { 369 syscallarg(int) s; 370 syscallarg(netbsd32_voidp) buf; 371 syscallarg(int) len; 372 syscallarg(int) flags; 373 } */ *uap = v; 374 struct sys_sendto_args ua; 375 376 NETBSD32TO64_UAP(s); 377 NETBSD32TOP_UAP(buf, void); 378 NETBSD32TO64_UAP(len); 379 NETBSD32TO64_UAP(flags); 380 SCARG(&ua, to) = NULL; 381 SCARG(&ua, tolen) = 0; 382 383 return sys_sendto(l, &ua, retval); 384 } 385 386 int 387 linux32_sys_recv(l, v, retval) 388 struct lwp *l; 389 void *v; 390 register_t *retval; 391 { 392 struct linux32_sys_recv_args /* { 393 syscallarg(int) s; 394 syscallarg(netbsd32_voidp) buf; 395 syscallarg(int) len; 396 syscallarg(int) flags; 397 } */ *uap = v; 398 struct sys_recvfrom_args ua; 399 400 NETBSD32TO64_UAP(s); 401 NETBSD32TOP_UAP(buf, void); 402 NETBSD32TO64_UAP(len); 403 NETBSD32TO64_UAP(flags); 404 SCARG(&ua, from) = NULL; 405 SCARG(&ua, fromlenaddr) = NULL; 406 407 return sys_recvfrom(l, &ua, retval); 408 } 409