1 /* $NetBSD: linux32_socket.c,v 1.3 2007/02/09 21:55:21 ad 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.3 2007/02/09 21:55:21 ad 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/proc.h> 47 #include <sys/ucred.h> 48 #include <sys/swap.h> 49 50 #include <machine/types.h> 51 52 #include <sys/syscallargs.h> 53 54 #include <compat/netbsd32/netbsd32.h> 55 #include <compat/netbsd32/netbsd32_conv.h> 56 #include <compat/netbsd32/netbsd32_syscallargs.h> 57 58 #include <compat/linux/common/linux_types.h> 59 #include <compat/linux/common/linux_signal.h> 60 #include <compat/linux/common/linux_machdep.h> 61 #include <compat/linux/common/linux_misc.h> 62 #include <compat/linux/common/linux_oldolduname.h> 63 #include <compat/linux/linux_syscallargs.h> 64 65 #include <compat/linux32/common/linux32_types.h> 66 #include <compat/linux32/common/linux32_signal.h> 67 #include <compat/linux32/common/linux32_machdep.h> 68 #include <compat/linux32/common/linux32_sysctl.h> 69 #include <compat/linux32/common/linux32_socketcall.h> 70 #include <compat/linux32/linux32_syscallargs.h> 71 72 int 73 linux32_sys_socketpair(l, v, retval) 74 struct lwp *l; 75 void *v; 76 register_t *retval; 77 { 78 struct linux32_sys_socketpair_args /* { 79 syscallarg(int) domain; 80 syscallarg(int) type; 81 syscallarg(int) protocol; 82 syscallarg(netbsd32_intp) rsv; 83 } */ *uap = v; 84 struct linux_sys_socketpair_args ua; 85 86 NETBSD32TO64_UAP(domain); 87 NETBSD32TO64_UAP(type); 88 NETBSD32TO64_UAP(protocol); 89 NETBSD32TOP_UAP(rsv, int) 90 91 return linux_sys_socketpair(l, &ua, retval); 92 } 93 94 int 95 linux32_sys_sendto(l, v, retval) 96 struct lwp *l; 97 void *v; 98 register_t *retval; 99 { 100 struct linux32_sys_sendto_args /* { 101 syscallarg(int) s; 102 syscallarg(netbsd32_voidp) msg; 103 syscallarg(int) len; 104 syscallarg(int) flags; 105 syscallarg(netbsd32_osockaddrp_t) to; 106 syscallarg(int) tolen; 107 } */ *uap = v; 108 struct linux_sys_sendto_args ua; 109 110 NETBSD32TO64_UAP(s); 111 NETBSD32TOP_UAP(msg, void); 112 NETBSD32TO64_UAP(len); 113 NETBSD32TO64_UAP(flags); 114 NETBSD32TOP_UAP(to, struct osockaddr); 115 NETBSD32TO64_UAP(tolen); 116 117 return linux_sys_sendto(l, &ua, retval); 118 } 119 120 121 int 122 linux32_sys_recvfrom(l, v, retval) 123 struct lwp *l; 124 void *v; 125 register_t *retval; 126 { 127 struct linux32_sys_recvfrom_args /* { 128 syscallarg(int) s; 129 syscallarg(netbsd32_voidp) buf; 130 syscallarg(netbsd32_size_t) len; 131 syscallarg(int) flags; 132 syscallarg(netbsd32_osockaddrp_t) from; 133 syscallarg(netbsd32_intp) fromlenaddr; 134 } */ *uap = v; 135 struct linux_sys_recvfrom_args ua; 136 137 NETBSD32TO64_UAP(s); 138 NETBSD32TOP_UAP(buf, void); 139 NETBSD32TO64_UAP(len); 140 NETBSD32TO64_UAP(flags); 141 NETBSD32TOP_UAP(from, struct osockaddr); 142 NETBSD32TOP_UAP(fromlenaddr, unsigned int); 143 144 return linux_sys_recvfrom(l, &ua, retval); 145 } 146 147 int 148 linux32_sys_setsockopt(l, v, retval) 149 struct lwp *l; 150 void *v; 151 register_t *retval; 152 { 153 struct linux32_sys_setsockopt_args /* { 154 syscallarg(int) s; 155 syscallarg(int) level; 156 syscallarg(int) optname; 157 syscallarg(netbsd32_voidp) optval; 158 syscallarg(int) optlen; 159 } */ *uap = v; 160 struct linux_sys_setsockopt_args ua; 161 162 NETBSD32TO64_UAP(s); 163 NETBSD32TO64_UAP(level); 164 NETBSD32TO64_UAP(optname); 165 NETBSD32TOP_UAP(optval, void); 166 NETBSD32TO64_UAP(optlen); 167 168 return linux_sys_setsockopt(l, &ua, retval); 169 } 170 171 172 int 173 linux32_sys_getsockopt(l, v, retval) 174 struct lwp *l; 175 void *v; 176 register_t *retval; 177 { 178 struct linux32_sys_getsockopt_args /* { 179 syscallarg(int) s; 180 syscallarg(int) level; 181 syscallarg(int) optname; 182 syscallarg(netbsd32_voidp) optval; 183 syscallarg(netbsd32_intp) optlen; 184 } */ *uap = v; 185 struct linux_sys_getsockopt_args ua; 186 187 NETBSD32TO64_UAP(s); 188 NETBSD32TO64_UAP(level); 189 NETBSD32TO64_UAP(optname); 190 NETBSD32TOP_UAP(optval, void); 191 NETBSD32TOP_UAP(optlen, int); 192 193 return linux_sys_getsockopt(l, &ua, retval); 194 } 195 196 int 197 linux32_sys_socket(l, v, retval) 198 struct lwp *l; 199 void *v; 200 register_t *retval; 201 { 202 struct linux32_sys_socket_args /* { 203 syscallarg(int) domain; 204 syscallarg(int) type; 205 syscallarg(int) protocol; 206 } */ *uap = v; 207 struct linux_sys_socket_args ua; 208 209 NETBSD32TO64_UAP(domain); 210 NETBSD32TO64_UAP(type); 211 NETBSD32TO64_UAP(protocol); 212 213 return linux_sys_socket(l, &ua, retval); 214 } 215 216 int 217 linux32_sys_bind(l, v, retval) 218 struct lwp *l; 219 void *v; 220 register_t *retval; 221 { 222 struct linux32_sys_bind_args /* { 223 syscallarg(int) s; 224 syscallarg(netbsd32_osockaddrp_t) name; 225 syscallarg(int) namelen; 226 } */ *uap = v; 227 struct linux_sys_bind_args ua; 228 229 NETBSD32TO64_UAP(s); 230 NETBSD32TOP_UAP(name, struct osockaddr) 231 NETBSD32TO64_UAP(namelen); 232 233 return linux_sys_bind(l, &ua, retval); 234 } 235 236 int 237 linux32_sys_connect(l, v, retval) 238 struct lwp *l; 239 void *v; 240 register_t *retval; 241 { 242 struct linux32_sys_connect_args /* { 243 syscallarg(int) s; 244 syscallarg(netbsd32_osockaddrp_t) name; 245 syscallarg(int) namelen; 246 } */ *uap = v; 247 struct linux_sys_connect_args ua; 248 249 NETBSD32TO64_UAP(s); 250 NETBSD32TOP_UAP(name, struct osockaddr) 251 NETBSD32TO64_UAP(namelen); 252 253 #ifdef DEBUG_LINUX 254 printf("linux32_sys_connect: s = %d, name = %p, namelen = %d\n", 255 SCARG(&ua, s), SCARG(&ua, name), SCARG(&ua, namelen)); 256 #endif 257 258 return linux_sys_connect(l, &ua, retval); 259 } 260 261 int 262 linux32_sys_accept(l, v, retval) 263 struct lwp *l; 264 void *v; 265 register_t *retval; 266 { 267 struct linux32_sys_accept_args /* { 268 syscallarg(int) s; 269 syscallarg(netbsd32_osockaddrp_t) name; 270 syscallarg(netbsd32_intp) anamelen; 271 } */ *uap = v; 272 struct linux_sys_accept_args ua; 273 274 NETBSD32TO64_UAP(s); 275 NETBSD32TOP_UAP(name, struct osockaddr) 276 NETBSD32TOP_UAP(anamelen, int); 277 278 return linux_sys_accept(l, &ua, retval); 279 } 280 281 int 282 linux32_sys_getpeername(l, v, retval) 283 struct lwp *l; 284 void *v; 285 register_t *retval; 286 { 287 struct linux32_sys_getpeername_args /* { 288 syscallarg(int) fdes; 289 syscallarg(netbsd32_sockaddrp_t) asa; 290 syscallarg(netbsd32_intp) alen; 291 } */ *uap = v; 292 struct linux_sys_getpeername_args ua; 293 294 NETBSD32TO64_UAP(fdes); 295 NETBSD32TOP_UAP(asa, struct sockaddr) 296 NETBSD32TOP_UAP(alen, int); 297 298 return linux_sys_getpeername(l, &ua, retval); 299 } 300 301 int 302 linux32_sys_getsockname(l, v, retval) 303 struct lwp *l; 304 void *v; 305 register_t *retval; 306 { 307 struct linux32_sys_getsockname_args /* { 308 syscallarg(int) fdec; 309 syscallarg(netbsd32_charp) asa; 310 syscallarg(netbsd32_intp) alen; 311 } */ *uap = v; 312 struct linux_sys_getsockname_args ua; 313 314 NETBSD32TO64_UAP(fdec); 315 NETBSD32TOP_UAP(asa, char) 316 NETBSD32TOP_UAP(alen, int); 317 318 return linux_sys_getsockname(l, &ua, retval); 319 } 320 321 int 322 linux32_sys_sendmsg(l, v, retval) 323 struct lwp *l; 324 void *v; 325 register_t *retval; 326 { 327 struct linux32_sys_sendmsg_args /* { 328 syscallarg(int) s; 329 syscallarg(netbsd32_msghdrp_t) msg; 330 syscallarg(int) flags; 331 } */ *uap = v; 332 struct linux_sys_sendmsg_args ua; 333 334 NETBSD32TO64_UAP(s); 335 NETBSD32TOP_UAP(msg, struct msghdr); 336 NETBSD32TO64_UAP(flags); 337 338 return linux_sys_sendmsg(l, &ua, retval); 339 } 340 341 int 342 linux32_sys_recvmsg(l, v, retval) 343 struct lwp *l; 344 void *v; 345 register_t *retval; 346 { 347 struct linux32_sys_recvmsg_args /* { 348 syscallarg(int) s; 349 syscallarg(netbsd32_msghdrp_t) msg; 350 syscallarg(int) flags; 351 } */ *uap = v; 352 struct linux_sys_recvmsg_args ua; 353 354 NETBSD32TO64_UAP(s); 355 NETBSD32TOP_UAP(msg, struct msghdr); 356 NETBSD32TO64_UAP(flags); 357 358 return linux_sys_recvmsg(l, &ua, retval); 359 } 360 361 int 362 linux32_sys_send(l, v, retval) 363 struct lwp *l; 364 void *v; 365 register_t *retval; 366 { 367 struct linux32_sys_send_args /* { 368 syscallarg(int) s; 369 syscallarg(netbsd32_voidp) buf; 370 syscallarg(int) len; 371 syscallarg(int) flags; 372 } */ *uap = v; 373 struct sys_sendto_args ua; 374 375 NETBSD32TO64_UAP(s); 376 NETBSD32TOP_UAP(buf, void); 377 NETBSD32TO64_UAP(len); 378 NETBSD32TO64_UAP(flags); 379 SCARG(&ua, to) = NULL; 380 SCARG(&ua, tolen) = 0; 381 382 return sys_sendto(l, &ua, retval); 383 } 384 385 int 386 linux32_sys_recv(l, v, retval) 387 struct lwp *l; 388 void *v; 389 register_t *retval; 390 { 391 struct linux32_sys_recv_args /* { 392 syscallarg(int) s; 393 syscallarg(netbsd32_voidp) buf; 394 syscallarg(int) len; 395 syscallarg(int) flags; 396 } */ *uap = v; 397 struct sys_recvfrom_args ua; 398 399 NETBSD32TO64_UAP(s); 400 NETBSD32TOP_UAP(buf, void); 401 NETBSD32TO64_UAP(len); 402 NETBSD32TO64_UAP(flags); 403 SCARG(&ua, from) = NULL; 404 SCARG(&ua, fromlenaddr) = NULL; 405 406 return sys_recvfrom(l, &ua, retval); 407 } 408