Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/uipc_syscalls.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/uipc_syscalls.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.92 retrieving revision 1.92.2.1 diff -u -p -r1.92 -r1.92.2.1 --- src/sys/kern/uipc_syscalls.c 2005/05/30 11:21:11 1.92 +++ src/sys/kern/uipc_syscalls.c 2006/06/21 15:09:39 1.92.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.92 2005/05/30 11:21:11 martin Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.92.2.1 2006/06/21 15:09:39 yamt Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1990, 1993 @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.92 2005/05/30 11:21:11 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.92.2.1 2006/06/21 15:09:39 yamt Exp $"); #include "opt_ktrace.h" #include "opt_pipe.h" @@ -61,7 +61,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_syscall #include -static void adjust_rights(struct mbuf *m, int len, struct proc *p); +static void adjust_rights(struct mbuf *m, int len, struct lwp *l); /* * System call interface to the socket abstraction. @@ -92,15 +92,15 @@ sys_socket(struct lwp *l, void *v, regis fp->f_type = DTYPE_SOCKET; fp->f_ops = &socketops; error = socreate(SCARG(uap, domain), &so, SCARG(uap, type), - SCARG(uap, protocol), p); + SCARG(uap, protocol), l); if (error) { - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); fdremove(fdp, fd); ffree(fp); } else { fp->f_data = (caddr_t)so; FILE_SET_MATURE(fp); - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); *retval = fd; } return (error); @@ -127,13 +127,13 @@ sys_bind(struct lwp *l, void *v, registe error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen), MT_SONAME); if (error) { - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } MCLAIM(nam, ((struct socket *)fp->f_data)->so_mowner); - error = sobind((struct socket *)fp->f_data, nam, p); + error = sobind((struct socket *)fp->f_data, nam, l); m_freem(nam); - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -154,7 +154,7 @@ sys_listen(struct lwp *l, void *v, regis if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); error = solisten((struct socket *)fp->f_data, SCARG(uap, backlog)); - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -186,7 +186,7 @@ sys_accept(struct lwp *l, void *v, regis return (error); s = splsoftnet(); so = (struct socket *)fp->f_data; - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); if (!(so->so_proto->pr_flags & PR_LISTEN)) { splx(s); return (EOPNOTSUPP); @@ -237,7 +237,7 @@ sys_accept(struct lwp *l, void *v, regis fp->f_flag = fflag; fp->f_ops = &socketops; fp->f_data = (caddr_t)so; - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); nam = m_get(M_WAIT, MT_SONAME); if ((error = soaccept(so, nam)) == 0 && SCARG(uap, name)) { if (namelen > nam->m_len) @@ -253,10 +253,11 @@ sys_accept(struct lwp *l, void *v, regis if (error) { fdremove(fdp, fd); ffree(fp); + } else { + FILE_SET_MATURE(fp); } m_freem(nam); splx(s); - FILE_SET_MATURE(fp); return (error); } @@ -290,7 +291,7 @@ sys_connect(struct lwp *l, void *v, regi if (error) goto out; MCLAIM(nam, so->so_mowner); - error = soconnect(so, nam, p); + error = soconnect(so, nam, l); if (error) goto bad; if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) { @@ -320,7 +321,7 @@ sys_connect(struct lwp *l, void *v, regi if (error == ERESTART) error = EINTR; out: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -342,11 +343,11 @@ sys_socketpair(struct lwp *l, void *v, r p = l->l_proc; fdp = p->p_fd; error = socreate(SCARG(uap, domain), &so1, SCARG(uap, type), - SCARG(uap, protocol), p); + SCARG(uap, protocol), l); if (error) return (error); error = socreate(SCARG(uap, domain), &so2, SCARG(uap, type), - SCARG(uap, protocol), p); + SCARG(uap, protocol), l); if (error) goto free1; /* falloc() will use the descriptor for us */ @@ -377,15 +378,15 @@ sys_socketpair(struct lwp *l, void *v, r 2 * sizeof(int)); FILE_SET_MATURE(fp1); FILE_SET_MATURE(fp2); - FILE_UNUSE(fp1, p); - FILE_UNUSE(fp2, p); + FILE_UNUSE(fp1, l); + FILE_UNUSE(fp2, l); return (error); free4: - FILE_UNUSE(fp2, p); + FILE_UNUSE(fp2, l); ffree(fp2); fdremove(fdp, sv[1]); free3: - FILE_UNUSE(fp1, p); + FILE_UNUSE(fp1, l); ffree(fp1); fdremove(fdp, sv[0]); free2: @@ -406,11 +407,9 @@ sys_sendto(struct lwp *l, void *v, regis syscallarg(const struct sockaddr *) to; syscallarg(unsigned int) tolen; } */ *uap = v; - struct proc *p; struct msghdr msg; struct iovec aiov; - p = l->l_proc; msg.msg_name = __UNCONST(SCARG(uap, to)); /* XXXUNCONST kills const */ msg.msg_namelen = SCARG(uap, tolen); msg.msg_iov = &aiov; @@ -419,7 +418,7 @@ sys_sendto(struct lwp *l, void *v, regis msg.msg_flags = 0; aiov.iov_base = __UNCONST(SCARG(uap, buf)); /* XXXUNCONST kills const */ aiov.iov_len = SCARG(uap, len); - return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval)); + return (sendit(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval)); } int @@ -430,7 +429,6 @@ sys_sendmsg(struct lwp *l, void *v, regi syscallarg(const struct msghdr *) msg; syscallarg(int) flags; } */ *uap = v; - struct proc *p; struct msghdr msg; struct iovec aiov[UIO_SMALLIOV], *iov; int error; @@ -453,8 +451,7 @@ sys_sendmsg(struct lwp *l, void *v, regi } msg.msg_iov = iov; msg.msg_flags = 0; - p = l->l_proc; - error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval); + error = sendit(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval); done: if (iov != aiov) free(iov, M_IOV); @@ -462,8 +459,9 @@ done: } int -sendit(struct proc *p, int s, struct msghdr *mp, int flags, register_t *retsize) +sendit(struct lwp *l, int s, struct msghdr *mp, int flags, register_t *retsize) { + struct proc *p; struct file *fp; struct uio auio; struct iovec *iov; @@ -477,17 +475,18 @@ sendit(struct proc *p, int s, struct msg #ifdef KTRACE ktriov = NULL; #endif + p = l->l_proc; /* getsock() will use the descriptor for us */ if ((error = getsock(p->p_fd, s, &fp)) != 0) return (error); so = (struct socket *)fp->f_data; auio.uio_iov = mp->msg_iov; auio.uio_iovcnt = mp->msg_iovlen; - auio.uio_segflg = UIO_USERSPACE; auio.uio_rw = UIO_WRITE; - auio.uio_procp = p; auio.uio_offset = 0; /* XXX */ auio.uio_resid = 0; + KASSERT(l == curlwp); + auio.uio_vmspace = l->l_proc->p_vmspace; iov = mp->msg_iov; for (i = 0; i < mp->msg_iovlen; i++, iov++) { #if 0 @@ -537,12 +536,12 @@ sendit(struct proc *p, int s, struct msg } #endif len = auio.uio_resid; - error = (*so->so_send)(so, to, &auio, NULL, control, flags, p); + error = (*so->so_send)(so, to, &auio, NULL, control, flags, l); if (error) { if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + if (error == EPIPE && (flags & MSG_NOSIGNAL) == 0) psignal(p, SIGPIPE); } if (error == 0) @@ -550,7 +549,7 @@ sendit(struct proc *p, int s, struct msg #ifdef KTRACE if (ktriov != NULL) { if (error == 0) - ktrgenio(p, s, UIO_WRITE, ktriov, *retsize, error); + ktrgenio(l, s, UIO_WRITE, ktriov, *retsize, error); free(ktriov, M_TEMP); } #endif @@ -558,7 +557,7 @@ sendit(struct proc *p, int s, struct msg if (to) m_freem(to); out: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -573,7 +572,6 @@ sys_recvfrom(struct lwp *l, void *v, reg syscallarg(struct sockaddr *) from; syscallarg(unsigned int *) fromlenaddr; } */ *uap = v; - struct proc *p; struct msghdr msg; struct iovec aiov; int error; @@ -593,8 +591,7 @@ sys_recvfrom(struct lwp *l, void *v, reg aiov.iov_len = SCARG(uap, len); msg.msg_control = 0; msg.msg_flags = SCARG(uap, flags); - p = l->l_proc; - return (recvit(p, SCARG(uap, s), &msg, + return (recvit(l, SCARG(uap, s), &msg, (caddr_t)SCARG(uap, fromlenaddr), retval)); } @@ -606,9 +603,8 @@ sys_recvmsg(struct lwp *l, void *v, regi syscallarg(struct msghdr *) msg; syscallarg(int) flags; } */ *uap = v; - struct proc *p; - struct msghdr msg; struct iovec aiov[UIO_SMALLIOV], *uiov, *iov; + struct msghdr msg; int error; error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg, @@ -631,8 +627,7 @@ sys_recvmsg(struct lwp *l, void *v, regi uiov = msg.msg_iov; msg.msg_iov = iov; msg.msg_flags = SCARG(uap, flags); - p = l->l_proc; - if ((error = recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval)) == 0) { + if ((error = recvit(l, SCARG(uap, s), &msg, (caddr_t)0, retval)) == 0) { msg.msg_iov = uiov; error = copyout((caddr_t)&msg, (caddr_t)SCARG(uap, msg), sizeof(msg)); @@ -650,25 +645,27 @@ done: * SCM_RIGHTS message; len is the length it is being truncated to. p * is the affected process. */ -static -void adjust_rights(struct mbuf *m, int len, struct proc *p) +static void +adjust_rights(struct mbuf *m, int len, struct lwp *l) { int nfd; int i; int nok; int *fdv; - nfd = (m->m_len - CMSG_LEN(0)) / sizeof(int); + nfd = m->m_len < CMSG_SPACE(sizeof(int)) ? 0 + : (m->m_len - CMSG_SPACE(sizeof(int))) / sizeof(int) + 1; nok = (len < CMSG_LEN(0)) ? 0 : ((len - CMSG_LEN(0)) / sizeof(int)); fdv = (int *) CMSG_DATA(mtod(m,struct cmsghdr *)); for (i = nok; i < nfd; i++) - fdrelease(p,fdv[i]); + fdrelease(l,fdv[i]); } int -recvit(struct proc *p, int s, struct msghdr *mp, caddr_t namelenp, +recvit(struct lwp *l, int s, struct msghdr *mp, caddr_t namelenp, register_t *retsize) { + struct proc *p; struct file *fp; struct uio auio; struct iovec *iov; @@ -679,6 +676,7 @@ recvit(struct proc *p, int s, struct msg struct iovec *ktriov; #endif + p = l->l_proc; from = 0; control = 0; #ifdef KTRACE @@ -691,11 +689,11 @@ recvit(struct proc *p, int s, struct msg so = (struct socket *)fp->f_data; auio.uio_iov = mp->msg_iov; auio.uio_iovcnt = mp->msg_iovlen; - auio.uio_segflg = UIO_USERSPACE; auio.uio_rw = UIO_READ; - auio.uio_procp = p; auio.uio_offset = 0; /* XXX */ auio.uio_resid = 0; + KASSERT(l == curlwp); + auio.uio_vmspace = l->l_proc->p_vmspace; iov = mp->msg_iov; for (i = 0; i < mp->msg_iovlen; i++, iov++) { #if 0 @@ -735,7 +733,7 @@ recvit(struct proc *p, int s, struct msg #ifdef KTRACE if (ktriov != NULL) { if (error == 0) - ktrgenio(p, s, UIO_READ, ktriov, + ktrgenio(l, s, UIO_READ, ktriov, len - auio.uio_resid, error); free(ktriov, M_TEMP); } @@ -776,7 +774,7 @@ recvit(struct proc *p, int s, struct msg i = len; if (mtod(m, struct cmsghdr *)-> cmsg_type == SCM_RIGHTS) - adjust_rights(m, len, p); + adjust_rights(m, len, l); } error = copyout(mtod(m, caddr_t), q, (unsigned)i); @@ -791,7 +789,7 @@ recvit(struct proc *p, int s, struct msg while (m) { if (mtod(m, struct cmsghdr *)-> cmsg_type == SCM_RIGHTS) - adjust_rights(m, 0, p); + adjust_rights(m, 0, l); m = m->m_next; } len = q - (caddr_t)mp->msg_control; @@ -804,7 +802,7 @@ recvit(struct proc *p, int s, struct msg if (control) m_freem(control); out1: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -825,7 +823,7 @@ sys_shutdown(struct lwp *l, void *v, reg if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); error = soshutdown((struct socket *)fp->f_data, SCARG(uap, how)); - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -872,7 +870,7 @@ sys_setsockopt(struct lwp *l, void *v, r } error = sosetopt(so, SCARG(uap, level), SCARG(uap, name), m); out: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -913,7 +911,7 @@ sys_getsockopt(struct lwp *l, void *v, r i = min(m->m_len, (valsize - op)); error = copyout(mtod(m, caddr_t), SCARG(uap, val), i); op += i; - SCARG(uap, val) = ((u_int8_t *)SCARG(uap, val)) + i; + SCARG(uap, val) = ((uint8_t *)SCARG(uap, val)) + i; m = m_free(m); } valsize = op; @@ -924,7 +922,7 @@ sys_getsockopt(struct lwp *l, void *v, r if (m != NULL) (void) m_freem(m); out: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -941,9 +939,9 @@ sys_pipe(struct lwp *l, void *v, registe p = l->l_proc; fdp = p->p_fd; - if ((error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0, p)) != 0) + if ((error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0, l)) != 0) return (error); - if ((error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0, p)) != 0) + if ((error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0, l)) != 0) goto free1; /* remember this socket pair implements a pipe */ wso->so_state |= SS_ISAPIPE; @@ -967,15 +965,15 @@ sys_pipe(struct lwp *l, void *v, registe goto free4; FILE_SET_MATURE(rf); FILE_SET_MATURE(wf); - FILE_UNUSE(rf, p); - FILE_UNUSE(wf, p); + FILE_UNUSE(rf, l); + FILE_UNUSE(wf, l); return (0); free4: - FILE_UNUSE(wf, p); + FILE_UNUSE(wf, l); ffree(wf); fdremove(fdp, retval[1]); free3: - FILE_UNUSE(rf, p); + FILE_UNUSE(rf, l); ffree(rf); fdremove(fdp, retval[0]); free2: @@ -1016,7 +1014,7 @@ sys_getsockname(struct lwp *l, void *v, m = m_getclr(M_WAIT, MT_SONAME); MCLAIM(m, so->so_mowner); error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, (struct mbuf *)0, - m, (struct mbuf *)0, (struct proc *)0); + m, (struct mbuf *)0, (struct lwp *)0); if (error) goto bad; if (len > m->m_len) @@ -1028,7 +1026,7 @@ sys_getsockname(struct lwp *l, void *v, bad: m_freem(m); out: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); } @@ -1066,7 +1064,7 @@ sys_getpeername(struct lwp *l, void *v, m = m_getclr(M_WAIT, MT_SONAME); MCLAIM(m, so->so_mowner); error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, (struct mbuf *)0, - m, (struct mbuf *)0, (struct proc *)0); + m, (struct mbuf *)0, (struct lwp *)0); if (error) goto bad; if (len > m->m_len) @@ -1078,7 +1076,7 @@ sys_getpeername(struct lwp *l, void *v, bad: m_freem(m); out: - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, l); return (error); }