Home | History | Annotate | Line # | Download | only in common
uipc_syscalls_43.c revision 1.2
      1  1.2   thorpej /*	$NetBSD: uipc_syscalls_43.c,v 1.2 1995/09/19 22:02:04 thorpej Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1982, 1986, 1989, 1990, 1993
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1  christos  * modification, are permitted provided that the following conditions
      9  1.1  christos  * are met:
     10  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  christos  *    documentation and/or other materials provided with the distribution.
     15  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     16  1.1  christos  *    must display the following acknowledgement:
     17  1.1  christos  *	This product includes software developed by the University of
     18  1.1  christos  *	California, Berkeley and its contributors.
     19  1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  christos  *    may be used to endorse or promote products derived from this software
     21  1.1  christos  *    without specific prior written permission.
     22  1.1  christos  *
     23  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  christos  * SUCH DAMAGE.
     34  1.1  christos  *
     35  1.1  christos  *	@(#)uipc_syscalls.c	8.4 (Berkeley) 2/21/94
     36  1.1  christos  */
     37  1.1  christos 
     38  1.1  christos #include <sys/param.h>
     39  1.1  christos #include <sys/systm.h>
     40  1.1  christos #include <sys/filedesc.h>
     41  1.1  christos #include <sys/kernel.h>
     42  1.1  christos #include <sys/proc.h>
     43  1.1  christos #include <sys/file.h>
     44  1.1  christos #include <sys/socket.h>
     45  1.1  christos #include <sys/socketvar.h>
     46  1.1  christos #include <sys/stat.h>
     47  1.1  christos #include <sys/ioctl.h>
     48  1.1  christos #include <sys/fcntl.h>
     49  1.1  christos #include <sys/malloc.h>
     50  1.1  christos #include <sys/syslog.h>
     51  1.1  christos #include <sys/unistd.h>
     52  1.1  christos #include <sys/resourcevar.h>
     53  1.1  christos 
     54  1.1  christos #include <sys/mount.h>
     55  1.1  christos #include <sys/syscallargs.h>
     56  1.1  christos 
     57  1.1  christos #define MSG_COMPAT	0x8000	/* XXX */
     58  1.1  christos 
     59  1.1  christos int
     60  1.2   thorpej compat_43_accept(p, v, retval)
     61  1.1  christos 	struct proc *p;
     62  1.2   thorpej 	void *v;
     63  1.2   thorpej 	register_t *retval;
     64  1.2   thorpej {
     65  1.1  christos 	struct accept_args /* {
     66  1.1  christos 		syscallarg(int) s;
     67  1.1  christos 		syscallarg(caddr_t) name;
     68  1.1  christos 		syscallarg(int *) anamelen;
     69  1.2   thorpej 	} */ *uap = v;
     70  1.1  christos 	int error;
     71  1.1  christos 
     72  1.1  christos 	if ((error = accept(p, uap, retval)) != 0)
     73  1.1  christos 		return error;
     74  1.1  christos 
     75  1.1  christos 	if (SCARG(uap, name)) {
     76  1.1  christos 		struct sockaddr sa;
     77  1.1  christos 
     78  1.1  christos 		if ((error = copyin(SCARG(uap, name), &sa, sizeof(sa))) != 0)
     79  1.1  christos 			return error;
     80  1.1  christos 
     81  1.1  christos 		((struct osockaddr*) &sa)->sa_family = sa.sa_family;
     82  1.1  christos 
     83  1.1  christos 		if ((error = copyout(&sa, SCARG(uap, name), sizeof(sa))) != 0)
     84  1.1  christos 			return error;
     85  1.1  christos 	}
     86  1.1  christos 	return 0;
     87  1.1  christos }
     88  1.1  christos 
     89  1.1  christos 
     90  1.1  christos int
     91  1.2   thorpej compat_43_getpeername(p, v, retval)
     92  1.1  christos 	struct proc *p;
     93  1.2   thorpej 	void *v;
     94  1.2   thorpej 	register_t *retval;
     95  1.2   thorpej {
     96  1.1  christos 	struct getpeername_args /* {
     97  1.1  christos 		syscallarg(int) fdes;
     98  1.1  christos 		syscallarg(caddr_t) asa;
     99  1.1  christos 		syscallarg(int *) alen;
    100  1.2   thorpej 	} */ *uap = v;
    101  1.1  christos 	struct sockaddr sa;
    102  1.1  christos 
    103  1.1  christos 	int error;
    104  1.1  christos 
    105  1.1  christos 	if ((error = getpeername(p, uap, retval)) != 0)
    106  1.1  christos 		return error;
    107  1.1  christos 
    108  1.1  christos 	if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
    109  1.1  christos 		return error;
    110  1.1  christos 
    111  1.1  christos 	((struct osockaddr*) &sa)->sa_family = sa.sa_family;
    112  1.1  christos 
    113  1.1  christos 	if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
    114  1.1  christos 		return error;
    115  1.1  christos 
    116  1.1  christos 	return 0;
    117  1.1  christos }
    118  1.1  christos 
    119  1.1  christos 
    120  1.1  christos int
    121  1.2   thorpej compat_43_getsockname(p, v, retval)
    122  1.1  christos 	struct proc *p;
    123  1.2   thorpej 	void *v;
    124  1.2   thorpej 	register_t *retval;
    125  1.2   thorpej {
    126  1.1  christos 	struct getsockname_args /* {
    127  1.1  christos 		syscallarg(int) fdes;
    128  1.1  christos 		syscallarg(caddr_t) asa;
    129  1.1  christos 		syscallarg(int *) alen;
    130  1.2   thorpej 	} */ *uap = v;
    131  1.1  christos 	struct sockaddr sa;
    132  1.1  christos 	int error;
    133  1.1  christos 
    134  1.1  christos 	if ((error = getsockname(p, uap, retval)) != 0)
    135  1.1  christos 		return error;
    136  1.1  christos 
    137  1.1  christos 	if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
    138  1.1  christos 		return error;
    139  1.1  christos 
    140  1.1  christos 	((struct osockaddr*) &sa)->sa_family = sa.sa_family;
    141  1.1  christos 
    142  1.1  christos 	if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
    143  1.1  christos 		return error;
    144  1.1  christos 
    145  1.1  christos 	return 0;
    146  1.1  christos }
    147  1.1  christos 
    148  1.1  christos 
    149  1.1  christos int
    150  1.2   thorpej compat_43_recv(p, v, retval)
    151  1.1  christos 	struct proc *p;
    152  1.2   thorpej 	void *v;
    153  1.2   thorpej 	register_t *retval;
    154  1.2   thorpej {
    155  1.1  christos 	register struct compat_43_recv_args /* {
    156  1.1  christos 		syscallarg(int) s;
    157  1.1  christos 		syscallarg(caddr_t) buf;
    158  1.1  christos 		syscallarg(int) len;
    159  1.1  christos 		syscallarg(int) flags;
    160  1.2   thorpej 	} */ *uap = v;
    161  1.1  christos 	struct msghdr msg;
    162  1.1  christos 	struct iovec aiov;
    163  1.1  christos 
    164  1.1  christos 	msg.msg_name = 0;
    165  1.1  christos 	msg.msg_namelen = 0;
    166  1.1  christos 	msg.msg_iov = &aiov;
    167  1.1  christos 	msg.msg_iovlen = 1;
    168  1.1  christos 	aiov.iov_base = SCARG(uap, buf);
    169  1.1  christos 	aiov.iov_len = SCARG(uap, len);
    170  1.1  christos 	msg.msg_control = 0;
    171  1.1  christos 	msg.msg_flags = SCARG(uap, flags);
    172  1.1  christos 	return (recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval));
    173  1.1  christos }
    174  1.1  christos 
    175  1.1  christos 
    176  1.1  christos int
    177  1.2   thorpej compat_43_recvfrom(p, v, retval)
    178  1.1  christos 	struct proc *p;
    179  1.2   thorpej 	void *v;
    180  1.2   thorpej 	register_t *retval;
    181  1.2   thorpej {
    182  1.1  christos 	struct recvfrom_args /* {
    183  1.1  christos 		syscallarg(int) s;
    184  1.1  christos 		syscallarg(caddr_t) buf;
    185  1.1  christos 		syscallarg(size_t) len;
    186  1.1  christos 		syscallarg(int) flags;
    187  1.1  christos 		syscallarg(caddr_t) from;
    188  1.1  christos 		syscallarg(int *) fromlenaddr;
    189  1.2   thorpej 	} */ *uap = v;
    190  1.1  christos 
    191  1.1  christos 	SCARG(uap, flags) |= MSG_COMPAT;
    192  1.1  christos 	return (recvfrom(p, uap, retval));
    193  1.1  christos }
    194  1.1  christos 
    195  1.1  christos 
    196  1.1  christos /*
    197  1.1  christos  * Old recvmsg.  This code takes advantage of the fact that the old msghdr
    198  1.1  christos  * overlays the new one, missing only the flags, and with the (old) access
    199  1.1  christos  * rights where the control fields are now.
    200  1.1  christos  */
    201  1.1  christos int
    202  1.2   thorpej compat_43_recvmsg(p, v, retval)
    203  1.1  christos 	struct proc *p;
    204  1.2   thorpej 	void *v;
    205  1.2   thorpej 	register_t *retval;
    206  1.2   thorpej {
    207  1.1  christos 	register struct compat_43_recvmsg_args /* {
    208  1.1  christos 		syscallarg(int) s;
    209  1.1  christos 		syscallarg(struct omsghdr *) msg;
    210  1.1  christos 		syscallarg(int) flags;
    211  1.2   thorpej 	} */ *uap = v;
    212  1.1  christos 	struct msghdr msg;
    213  1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    214  1.1  christos 	int error;
    215  1.1  christos 
    216  1.1  christos 	if (error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
    217  1.1  christos 	    sizeof (struct omsghdr)))
    218  1.1  christos 		return (error);
    219  1.1  christos 	if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
    220  1.1  christos 		if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
    221  1.1  christos 			return (EMSGSIZE);
    222  1.1  christos 		MALLOC(iov, struct iovec *,
    223  1.1  christos 		      sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
    224  1.1  christos 		      M_WAITOK);
    225  1.1  christos 	} else
    226  1.1  christos 		iov = aiov;
    227  1.1  christos 	msg.msg_flags = SCARG(uap, flags) | MSG_COMPAT;
    228  1.1  christos 	if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
    229  1.1  christos 	    (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))
    230  1.1  christos 		goto done;
    231  1.1  christos 	msg.msg_iov = iov;
    232  1.1  christos 	error = recvit(p, SCARG(uap, s), &msg,
    233  1.1  christos 	    (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
    234  1.1  christos 
    235  1.1  christos 	if (msg.msg_controllen && error == 0)
    236  1.1  christos 		error = copyout((caddr_t)&msg.msg_controllen,
    237  1.1  christos 		    (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
    238  1.1  christos done:
    239  1.1  christos 	if (iov != aiov)
    240  1.1  christos 		FREE(iov, M_IOV);
    241  1.1  christos 	return (error);
    242  1.1  christos }
    243  1.1  christos 
    244  1.1  christos int
    245  1.2   thorpej compat_43_send(p, v, retval)
    246  1.1  christos 	struct proc *p;
    247  1.2   thorpej 	void *v;
    248  1.2   thorpej 	register_t *retval;
    249  1.2   thorpej {
    250  1.1  christos 	register struct compat_43_send_args /* {
    251  1.1  christos 		syscallarg(int) s;
    252  1.1  christos 		syscallarg(caddr_t) buf;
    253  1.1  christos 		syscallarg(int) len;
    254  1.1  christos 		syscallarg(int) flags;
    255  1.2   thorpej 	} */ *uap = v;
    256  1.1  christos 	struct msghdr msg;
    257  1.1  christos 	struct iovec aiov;
    258  1.1  christos 
    259  1.1  christos 	msg.msg_name = 0;
    260  1.1  christos 	msg.msg_namelen = 0;
    261  1.1  christos 	msg.msg_iov = &aiov;
    262  1.1  christos 	msg.msg_iovlen = 1;
    263  1.1  christos 	aiov.iov_base = SCARG(uap, buf);
    264  1.1  christos 	aiov.iov_len = SCARG(uap, len);
    265  1.1  christos 	msg.msg_control = 0;
    266  1.1  christos 	msg.msg_flags = 0;
    267  1.1  christos 	return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
    268  1.1  christos }
    269  1.1  christos 
    270  1.1  christos int
    271  1.2   thorpej compat_43_sendmsg(p, v, retval)
    272  1.1  christos 	struct proc *p;
    273  1.2   thorpej 	void *v;
    274  1.2   thorpej 	register_t *retval;
    275  1.2   thorpej {
    276  1.1  christos 	register struct compat_43_sendmsg_args /* {
    277  1.1  christos 		syscallarg(int) s;
    278  1.1  christos 		syscallarg(caddr_t) msg;
    279  1.1  christos 		syscallarg(int) flags;
    280  1.2   thorpej 	} */ *uap = v;
    281  1.1  christos 	struct msghdr msg;
    282  1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    283  1.1  christos 	int error;
    284  1.1  christos 
    285  1.1  christos 	if (error = copyin(SCARG(uap, msg), (caddr_t)&msg,
    286  1.1  christos 	    sizeof (struct omsghdr)))
    287  1.1  christos 		return (error);
    288  1.1  christos 	if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
    289  1.1  christos 		if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
    290  1.1  christos 			return (EMSGSIZE);
    291  1.1  christos 		MALLOC(iov, struct iovec *,
    292  1.1  christos 		      sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
    293  1.1  christos 		      M_WAITOK);
    294  1.1  christos 	} else
    295  1.1  christos 		iov = aiov;
    296  1.1  christos 	if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
    297  1.1  christos 	    (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))
    298  1.1  christos 		goto done;
    299  1.1  christos 	msg.msg_flags = MSG_COMPAT;
    300  1.1  christos 	msg.msg_iov = iov;
    301  1.1  christos 	error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
    302  1.1  christos done:
    303  1.1  christos 	if (iov != aiov)
    304  1.1  christos 		FREE(iov, M_IOV);
    305  1.1  christos 	return (error);
    306  1.1  christos }
    307