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