Home | History | Annotate | Line # | Download | only in common
linux32_socket.c revision 1.5.12.1
      1 /*	$NetBSD: linux32_socket.c,v 1.5.12.1 2008/05/10 23:48:56 wrstuden 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.5.12.1 2008/05/10 23:48:56 wrstuden 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/sa.h>
     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(struct lwp *l, const struct linux32_sys_socketpair_args *uap, register_t *retval)
     75 {
     76 	/* {
     77 		syscallarg(int) domain;
     78 		syscallarg(int) type;
     79 		syscallarg(int) protocol;
     80 		syscallarg(netbsd32_intp) rsv;
     81 	} */
     82 	struct linux_sys_socketpair_args ua;
     83 
     84 	NETBSD32TO64_UAP(domain);
     85 	NETBSD32TO64_UAP(type);
     86 	NETBSD32TO64_UAP(protocol);
     87 	NETBSD32TOP_UAP(rsv, int)
     88 
     89 	return linux_sys_socketpair(l, &ua, retval);
     90 }
     91 
     92 int
     93 linux32_sys_sendto(struct lwp *l, const struct linux32_sys_sendto_args *uap, register_t *retval)
     94 {
     95 	/* {
     96 		syscallarg(int) s;
     97 		syscallarg(netbsd32_voidp) msg;
     98 		syscallarg(int) len;
     99 		syscallarg(int) flags;
    100 		syscallarg(netbsd32_osockaddrp_t) to;
    101 		syscallarg(int) tolen;
    102 	} */
    103 	struct linux_sys_sendto_args ua;
    104 
    105 	NETBSD32TO64_UAP(s);
    106 	NETBSD32TOP_UAP(msg, void);
    107 	NETBSD32TO64_UAP(len);
    108 	NETBSD32TO64_UAP(flags);
    109 	NETBSD32TOP_UAP(to, struct osockaddr);
    110 	NETBSD32TO64_UAP(tolen);
    111 
    112 	return linux_sys_sendto(l, &ua, retval);
    113 }
    114 
    115 
    116 int
    117 linux32_sys_recvfrom(struct lwp *l, const struct linux32_sys_recvfrom_args *uap, register_t *retval)
    118 {
    119 	/* {
    120 		syscallarg(int) s;
    121 		syscallarg(netbsd32_voidp) buf;
    122 		syscallarg(netbsd32_size_t) len;
    123 		syscallarg(int) flags;
    124 		syscallarg(netbsd32_osockaddrp_t) from;
    125 		syscallarg(netbsd32_intp) fromlenaddr;
    126 	} */
    127 	struct linux_sys_recvfrom_args ua;
    128 
    129 	NETBSD32TO64_UAP(s);
    130 	NETBSD32TOP_UAP(buf, void);
    131 	NETBSD32TO64_UAP(len);
    132 	NETBSD32TO64_UAP(flags);
    133 	NETBSD32TOP_UAP(from, struct osockaddr);
    134 	NETBSD32TOP_UAP(fromlenaddr, unsigned int);
    135 
    136 	return linux_sys_recvfrom(l, &ua, retval);
    137 }
    138 
    139 int
    140 linux32_sys_setsockopt(struct lwp *l, const struct linux32_sys_setsockopt_args *uap, register_t *retval)
    141 {
    142 	/* {
    143 		syscallarg(int) s;
    144 		syscallarg(int) level;
    145 		syscallarg(int) optname;
    146 		syscallarg(netbsd32_voidp) optval;
    147 		syscallarg(int) optlen;
    148 	} */
    149 	struct linux_sys_setsockopt_args ua;
    150 
    151 	NETBSD32TO64_UAP(s);
    152 	NETBSD32TO64_UAP(level);
    153 	NETBSD32TO64_UAP(optname);
    154 	NETBSD32TOP_UAP(optval, void);
    155 	NETBSD32TO64_UAP(optlen);
    156 
    157 	return linux_sys_setsockopt(l, &ua, retval);
    158 }
    159 
    160 
    161 int
    162 linux32_sys_getsockopt(struct lwp *l, const struct linux32_sys_getsockopt_args *uap, register_t *retval)
    163 {
    164 	/* {
    165 		syscallarg(int) s;
    166 		syscallarg(int) level;
    167 		syscallarg(int) optname;
    168 		syscallarg(netbsd32_voidp) optval;
    169 		syscallarg(netbsd32_intp) optlen;
    170 	} */
    171 	struct linux_sys_getsockopt_args ua;
    172 
    173 	NETBSD32TO64_UAP(s);
    174 	NETBSD32TO64_UAP(level);
    175 	NETBSD32TO64_UAP(optname);
    176 	NETBSD32TOP_UAP(optval, void);
    177 	NETBSD32TOP_UAP(optlen, int);
    178 
    179 	return linux_sys_getsockopt(l, &ua, retval);
    180 }
    181 
    182 int
    183 linux32_sys_socket(struct lwp *l, const struct linux32_sys_socket_args *uap, register_t *retval)
    184 {
    185 	/* {
    186 		syscallarg(int) domain;
    187 		syscallarg(int) type;
    188 		syscallarg(int) protocol;
    189 	} */
    190 	struct linux_sys_socket_args ua;
    191 
    192 	NETBSD32TO64_UAP(domain);
    193 	NETBSD32TO64_UAP(type);
    194 	NETBSD32TO64_UAP(protocol);
    195 
    196 	return linux_sys_socket(l, &ua, retval);
    197 }
    198 
    199 int
    200 linux32_sys_bind(struct lwp *l, const struct linux32_sys_bind_args *uap, register_t *retval)
    201 {
    202 	/* {
    203 		syscallarg(int) s;
    204 		syscallarg(netbsd32_osockaddrp_t) name;
    205 		syscallarg(int) namelen;
    206 	} */
    207 	struct linux_sys_bind_args ua;
    208 
    209 	NETBSD32TO64_UAP(s);
    210 	NETBSD32TOP_UAP(name, struct osockaddr)
    211 	NETBSD32TO64_UAP(namelen);
    212 
    213 	return linux_sys_bind(l, &ua, retval);
    214 }
    215 
    216 int
    217 linux32_sys_connect(struct lwp *l, const struct linux32_sys_connect_args *uap, register_t *retval)
    218 {
    219 	/* {
    220 		syscallarg(int) s;
    221 		syscallarg(netbsd32_osockaddrp_t) name;
    222 		syscallarg(int) namelen;
    223 	} */
    224 	struct linux_sys_connect_args ua;
    225 
    226 	NETBSD32TO64_UAP(s);
    227 	NETBSD32TOP_UAP(name, struct osockaddr)
    228 	NETBSD32TO64_UAP(namelen);
    229 
    230 #ifdef DEBUG_LINUX
    231 	printf("linux32_sys_connect: s = %d, name = %p, namelen = %d\n",
    232 		SCARG(&ua, s), SCARG(&ua, name), SCARG(&ua, namelen));
    233 #endif
    234 
    235 	return linux_sys_connect(l, &ua, retval);
    236 }
    237 
    238 int
    239 linux32_sys_accept(struct lwp *l, const struct linux32_sys_accept_args *uap, register_t *retval)
    240 {
    241 	/* {
    242 		syscallarg(int) s;
    243 		syscallarg(netbsd32_osockaddrp_t) name;
    244 		syscallarg(netbsd32_intp) anamelen;
    245 	} */
    246 	struct linux_sys_accept_args ua;
    247 
    248 	NETBSD32TO64_UAP(s);
    249 	NETBSD32TOP_UAP(name, struct osockaddr)
    250 	NETBSD32TOP_UAP(anamelen, int);
    251 
    252 	return linux_sys_accept(l, &ua, retval);
    253 }
    254 
    255 int
    256 linux32_sys_getpeername(struct lwp *l, const struct linux32_sys_getpeername_args *uap, register_t *retval)
    257 {
    258 	/* {
    259 		syscallarg(int) fdes;
    260 		syscallarg(netbsd32_sockaddrp_t) asa;
    261 		syscallarg(netbsd32_intp) alen;
    262 	} */
    263 	struct linux_sys_getpeername_args ua;
    264 
    265 	NETBSD32TO64_UAP(fdes);
    266 	NETBSD32TOP_UAP(asa, struct sockaddr)
    267 	NETBSD32TOP_UAP(alen, int);
    268 
    269 	return linux_sys_getpeername(l, &ua, retval);
    270 }
    271 
    272 int
    273 linux32_sys_getsockname(struct lwp *l, const struct linux32_sys_getsockname_args *uap, register_t *retval)
    274 {
    275 	/* {
    276 		syscallarg(int) fdec;
    277 		syscallarg(netbsd32_charp) asa;
    278 		syscallarg(netbsd32_intp) alen;
    279 	} */
    280 	struct linux_sys_getsockname_args ua;
    281 
    282 	NETBSD32TO64_UAP(fdec);
    283 	NETBSD32TOP_UAP(asa, char)
    284 	NETBSD32TOP_UAP(alen, int);
    285 
    286 	return linux_sys_getsockname(l, &ua, retval);
    287 }
    288 
    289 int
    290 linux32_sys_sendmsg(struct lwp *l, const struct linux32_sys_sendmsg_args *uap, register_t *retval)
    291 {
    292 	/* {
    293 		syscallarg(int) s;
    294 		syscallarg(netbsd32_msghdrp_t) msg;
    295 		syscallarg(int) flags;
    296 	} */
    297 	struct linux_sys_sendmsg_args ua;
    298 
    299 	NETBSD32TO64_UAP(s);
    300 	NETBSD32TOP_UAP(msg, struct msghdr);
    301 	NETBSD32TO64_UAP(flags);
    302 
    303 	return linux_sys_sendmsg(l, &ua, retval);
    304 }
    305 
    306 int
    307 linux32_sys_recvmsg(struct lwp *l, const struct linux32_sys_recvmsg_args *uap, register_t *retval)
    308 {
    309 	/* {
    310 		syscallarg(int) s;
    311 		syscallarg(netbsd32_msghdrp_t) msg;
    312 		syscallarg(int) flags;
    313 	} */
    314 	struct linux_sys_recvmsg_args ua;
    315 
    316 	NETBSD32TO64_UAP(s);
    317 	NETBSD32TOP_UAP(msg, struct msghdr);
    318 	NETBSD32TO64_UAP(flags);
    319 
    320 	return linux_sys_recvmsg(l, &ua, retval);
    321 }
    322 
    323 int
    324 linux32_sys_send(struct lwp *l, const struct linux32_sys_send_args *uap, register_t *retval)
    325 {
    326 	/* {
    327 		syscallarg(int) s;
    328 		syscallarg(netbsd32_voidp) buf;
    329 		syscallarg(int) len;
    330 		syscallarg(int) flags;
    331 	} */
    332 	struct sys_sendto_args ua;
    333 
    334 	NETBSD32TO64_UAP(s);
    335 	NETBSD32TOP_UAP(buf, void);
    336 	NETBSD32TO64_UAP(len);
    337 	NETBSD32TO64_UAP(flags);
    338 	SCARG(&ua, to) = NULL;
    339 	SCARG(&ua, tolen) = 0;
    340 
    341 	return sys_sendto(l, &ua, retval);
    342 }
    343 
    344 int
    345 linux32_sys_recv(struct lwp *l, const struct linux32_sys_recv_args *uap, register_t *retval)
    346 {
    347 	/* {
    348 		syscallarg(int) s;
    349 		syscallarg(netbsd32_voidp) buf;
    350 		syscallarg(int) len;
    351 		syscallarg(int) flags;
    352 	} */
    353 	struct sys_recvfrom_args ua;
    354 
    355 	NETBSD32TO64_UAP(s);
    356 	NETBSD32TOP_UAP(buf, void);
    357 	NETBSD32TO64_UAP(len);
    358 	NETBSD32TO64_UAP(flags);
    359 	SCARG(&ua, from) = NULL;
    360 	SCARG(&ua, fromlenaddr) = NULL;
    361 
    362 	return sys_recvfrom(l, &ua, retval);
    363 }
    364