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