p_devtmp => p_dupfd; eliminate u.u_error from RETURN macro
[unix-history] / usr / src / sys / kern / sys_generic.c
index bd9171e..9934b16 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)sys_generic.c       7.15 (Berkeley) %G%
+ *     @(#)sys_generic.c       7.20 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 /*
  * Read system call.
  */
 /*
  * Read system call.
  */
-read()
-{
-       register struct a {
+read(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     fdes;
                char    *cbuf;
                unsigned count;
                int     fdes;
                char    *cbuf;
                unsigned count;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        register struct file *fp;
        struct uio auio;
        struct iovec aiov;
        register struct file *fp;
        struct uio auio;
        struct iovec aiov;
@@ -53,8 +55,6 @@ read()
            (fp = u.u_ofile[uap->fdes]) == NULL ||
            (fp->f_flag & FREAD) == 0)
                RETURN (EBADF);
            (fp = u.u_ofile[uap->fdes]) == NULL ||
            (fp->f_flag & FREAD) == 0)
                RETURN (EBADF);
-       if (uap->count < 0)
-               RETURN (EINVAL);
        aiov.iov_base = (caddr_t)uap->cbuf;
        aiov.iov_len = uap->count;
        auio.uio_iov = &aiov;
        aiov.iov_base = (caddr_t)uap->cbuf;
        aiov.iov_len = uap->count;
        auio.uio_iov = &aiov;
@@ -66,7 +66,7 @@ read()
        /*
         * if tracing, save a copy of iovec
         */
        /*
         * if tracing, save a copy of iovec
         */
-       if (KTRPOINT(u.u_procp, KTR_GENIO))
+       if (KTRPOINT(p, KTR_GENIO))
                ktriov = aiov;
 #endif
        cnt = uap->count;
                ktriov = aiov;
 #endif
        cnt = uap->count;
@@ -76,20 +76,25 @@ read()
                        error = 0;
        cnt -= auio.uio_resid;
 #ifdef KTRACE
                        error = 0;
        cnt -= auio.uio_resid;
 #ifdef KTRACE
-       if (KTRPOINT(u.u_procp, KTR_GENIO) && error == 0)
-               ktrgenio(u.u_procp->p_tracep, uap->fdes, UIO_READ, &ktriov, cnt);
+       if (KTRPOINT(p, KTR_GENIO) && error == 0)
+               ktrgenio(p->p_tracep, uap->fdes, UIO_READ, &ktriov, cnt, error);
 #endif
 #endif
-       u.u_r.r_val1 = cnt;
+       *retval = cnt;
        RETURN (error);
 }
 
        RETURN (error);
 }
 
-readv()
-{
-       register struct a {
+/*
+ * Scatter read system call.
+ */
+readv(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     fdes;
                struct  iovec *iovp;
                unsigned iovcnt;
                int     fdes;
                struct  iovec *iovp;
                unsigned iovcnt;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        register struct file *fp;
        struct uio auio;
        register struct iovec *iov;
        register struct file *fp;
        struct uio auio;
        register struct iovec *iov;
@@ -134,8 +139,8 @@ readv()
        /*
         * if tracing, save a copy of iovec
         */
        /*
         * if tracing, save a copy of iovec
         */
-       if (KTRPOINT(u.u_procp, KTR_GENIO))  {
-               int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
+       if (KTRPOINT(p, KTR_GENIO))  {
+               unsigned iovlen = auio.uio_iovcnt * sizeof (struct iovec);
 
                MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
                bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
 
                MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
                bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
@@ -150,12 +155,12 @@ readv()
 #ifdef KTRACE
        if (ktriov != NULL) {
                if (error == 0)
 #ifdef KTRACE
        if (ktriov != NULL) {
                if (error == 0)
-                       ktrgenio(u.u_procp->p_tracep, uap->fdes, UIO_READ, 
-                               ktriov, cnt);
+                       ktrgenio(p->p_tracep, uap->fdes, UIO_READ, ktriov,
+                           cnt, error);
                FREE(ktriov, M_TEMP);
        }
 #endif
                FREE(ktriov, M_TEMP);
        }
 #endif
-       u.u_r.r_val1 = cnt;
+       *retval = cnt;
 done:
        if (uap->iovcnt > UIO_SMALLIOV)
                FREE(iov, M_IOV);
 done:
        if (uap->iovcnt > UIO_SMALLIOV)
                FREE(iov, M_IOV);
@@ -165,13 +170,15 @@ done:
 /*
  * Write system call
  */
 /*
  * Write system call
  */
-write()
-{
-       register struct a {
+write(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     fdes;
                char    *cbuf;
                unsigned count;
                int     fdes;
                char    *cbuf;
                unsigned count;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        register struct file *fp;
        struct uio auio;
        struct iovec aiov;
        register struct file *fp;
        struct uio auio;
        struct iovec aiov;
@@ -184,8 +191,6 @@ write()
            (fp = u.u_ofile[uap->fdes]) == NULL ||
            (fp->f_flag & FWRITE) == 0)
                RETURN (EBADF);
            (fp = u.u_ofile[uap->fdes]) == NULL ||
            (fp->f_flag & FWRITE) == 0)
                RETURN (EBADF);
-       if (uap->count < 0)
-               RETURN (EINVAL);
        aiov.iov_base = (caddr_t)uap->cbuf;
        aiov.iov_len = uap->count;
        auio.uio_iov = &aiov;
        aiov.iov_base = (caddr_t)uap->cbuf;
        aiov.iov_len = uap->count;
        auio.uio_iov = &aiov;
@@ -197,7 +202,7 @@ write()
        /*
         * if tracing, save a copy of iovec
         */
        /*
         * if tracing, save a copy of iovec
         */
-       if (KTRPOINT(u.u_procp, KTR_GENIO))
+       if (KTRPOINT(p, KTR_GENIO))
                ktriov = aiov;
 #endif
        cnt = uap->count;
                ktriov = aiov;
 #endif
        cnt = uap->count;
@@ -206,25 +211,30 @@ write()
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;
                if (error == EPIPE)
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;
                if (error == EPIPE)
-                       psignal(u.u_procp, SIGPIPE);
+                       psignal(p, SIGPIPE);
        }
        cnt -= auio.uio_resid;
 #ifdef KTRACE
        }
        cnt -= auio.uio_resid;
 #ifdef KTRACE
-       if (KTRPOINT(u.u_procp, KTR_GENIO) && error == 0)
-               ktrgenio(u.u_procp->p_tracep, uap->fdes, UIO_WRITE,
-                   &ktriov, cnt);
+       if (KTRPOINT(p, KTR_GENIO) && error == 0)
+               ktrgenio(p->p_tracep, uap->fdes, UIO_WRITE,
+                   &ktriov, cnt, error);
 #endif
 #endif
-       u.u_r.r_val1 = cnt;
+       *retval = cnt;
        RETURN (error);
 }
 
        RETURN (error);
 }
 
-writev()
-{
-       register struct a {
+/*
+ * Gather write system call
+ */
+writev(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     fdes;
                struct  iovec *iovp;
                unsigned iovcnt;
                int     fdes;
                struct  iovec *iovp;
                unsigned iovcnt;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        register struct file *fp;
        struct uio auio;
        register struct iovec *iov;
        register struct file *fp;
        struct uio auio;
        register struct iovec *iov;
@@ -269,8 +279,8 @@ writev()
        /*
         * if tracing, save a copy of iovec
         */
        /*
         * if tracing, save a copy of iovec
         */
-       if (KTRPOINT(u.u_procp, KTR_GENIO))  {
-               int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
+       if (KTRPOINT(p, KTR_GENIO))  {
+               unsigned iovlen = auio.uio_iovcnt * sizeof (struct iovec);
 
                MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
                bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
 
                MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
                bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
@@ -282,18 +292,18 @@ writev()
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;
                if (error == EPIPE)
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;
                if (error == EPIPE)
-                       psignal(u.u_procp, SIGPIPE);
+                       psignal(p, SIGPIPE);
        }
        cnt -= auio.uio_resid;
 #ifdef KTRACE
        if (ktriov != NULL) {
                if (error == 0)
        }
        cnt -= auio.uio_resid;
 #ifdef KTRACE
        if (ktriov != NULL) {
                if (error == 0)
-                       ktrgenio(u.u_procp->p_tracep, uap->fdes, UIO_WRITE,
-                               ktriov, cnt);
+                       ktrgenio(p->p_tracep, uap->fdes, UIO_WRITE,
+                               ktriov, cnt, error);
                FREE(ktriov, M_TEMP);
        }
 #endif
                FREE(ktriov, M_TEMP);
        }
 #endif
-       u.u_r.r_val1 = cnt;
+       *retval = cnt;
 done:
        if (uap->iovcnt > UIO_SMALLIOV)
                FREE(iov, M_IOV);
 done:
        if (uap->iovcnt > UIO_SMALLIOV)
                FREE(iov, M_IOV);
@@ -303,14 +313,17 @@ done:
 /*
  * Ioctl system call
  */
 /*
  * Ioctl system call
  */
-ioctl()
-{
-       register struct file *fp;
-       struct a {
+/* ARGSUSED */
+ioctl(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     fdes;
                int     cmd;
                caddr_t cmarg;
                int     fdes;
                int     cmd;
                caddr_t cmarg;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
+       register struct file *fp;
        register int com, error;
        register u_int size;
        caddr_t memp = 0;
        register int com, error;
        register u_int size;
        caddr_t memp = 0;
@@ -327,7 +340,7 @@ ioctl()
 
        if (com == FIOCLEX) {
                u.u_pofile[uap->fdes] |= UF_EXCLOSE;
 
        if (com == FIOCLEX) {
                u.u_pofile[uap->fdes] |= UF_EXCLOSE;
-               return;
+               RETURN (0);
        }
        if (com == FIONCLEX) {
                u.u_pofile[uap->fdes] &= ~UF_EXCLOSE;
        }
        if (com == FIONCLEX) {
                u.u_pofile[uap->fdes] &= ~UF_EXCLOSE;
@@ -343,8 +356,7 @@ ioctl()
        if (size > IOCPARM_MAX)
                RETURN (ENOTTY);
        if (size > sizeof (stkbuf)) {
        if (size > IOCPARM_MAX)
                RETURN (ENOTTY);
        if (size > sizeof (stkbuf)) {
-               memp = (caddr_t)malloc((u_long)IOCPARM_LEN(com), M_IOCTLOPS,
-                   M_WAITOK);
+               memp = (caddr_t)malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
                data = memp;
        }
        if (com&IOC_IN) {
                data = memp;
        }
        if (com&IOC_IN) {
@@ -403,13 +415,15 @@ int       nselcoll;
 /*
  * Select system call.
  */
 /*
  * Select system call.
  */
-select()
-{
-       register struct uap  {
+select(p, uap, retval)
+       register struct proc *p;
+       register struct args {
                int     nd;
                fd_set  *in, *ou, *ex;
                struct  timeval *tv;
                int     nd;
                fd_set  *in, *ou, *ex;
                struct  timeval *tv;
-       } *uap = (struct uap *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        fd_set ibits[3], obits[3];
        struct timeval atv;
        int s, ncoll, ni, error = 0, timo;
        fd_set ibits[3], obits[3];
        struct timeval atv;
        int s, ncoll, ni, error = 0, timo;
@@ -447,11 +461,9 @@ select()
                timo = 0;
 retry:
        ncoll = nselcoll;
                timo = 0;
 retry:
        ncoll = nselcoll;
-       u.u_procp->p_flag |= SSEL;
-       u.u_r.r_val1 = selscan(ibits, obits, uap->nd, &error);
-       if (error == 0)
-               error = u.u_error;              /* XXX */
-       if (error || u.u_r.r_val1)
+       p->p_flag |= SSEL;
+       error = selscan(ibits, obits, uap->nd, retval);
+       if (error || *retval)
                goto done;
        s = splhigh();
        /* this should be timercmp(&time, &atv, >=) */
                goto done;
        s = splhigh();
        /* this should be timercmp(&time, &atv, >=) */
@@ -460,17 +472,17 @@ retry:
                splx(s);
                goto done;
        }
                splx(s);
                goto done;
        }
-       if ((u.u_procp->p_flag & SSEL) == 0 || nselcoll != ncoll) {
+       if ((p->p_flag & SSEL) == 0 || nselcoll != ncoll) {
                splx(s);
                goto retry;
        }
                splx(s);
                goto retry;
        }
-       u.u_procp->p_flag &= ~SSEL;
+       p->p_flag &= ~SSEL;
        error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "select", timo);
        splx(s);
        if (error == 0)
                goto retry;
 done:
        error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "select", timo);
        splx(s);
        if (error == 0)
                goto retry;
 done:
-       u.u_procp->p_flag &= ~SSEL;
+       p->p_flag &= ~SSEL;
        /* select is not restarted after signals... */
        if (error == ERESTART)
                error = EINTR;
        /* select is not restarted after signals... */
        if (error == ERESTART)
                error = EINTR;
@@ -492,15 +504,15 @@ done:
        RETURN (error);
 }
 
        RETURN (error);
 }
 
-selscan(ibits, obits, nfd, errp)
+selscan(ibits, obits, nfd, retval)
        fd_set *ibits, *obits;
        fd_set *ibits, *obits;
-       int nfd, *errp;
+       int nfd, *retval;
 {
        register int which, i, j;
        register fd_mask bits;
        int flag;
        struct file *fp;
 {
        register int which, i, j;
        register fd_mask bits;
        int flag;
        struct file *fp;
-       int n = 0;
+       int error = 0, n = 0;
 
        for (which = 0; which < 3; which++) {
                switch (which) {
 
        for (which = 0; which < 3; which++) {
                switch (which) {
@@ -520,7 +532,7 @@ selscan(ibits, obits, nfd, errp)
                                bits &= ~(1 << j);
                                fp = u.u_ofile[i + j];
                                if (fp == NULL) {
                                bits &= ~(1 << j);
                                fp = u.u_ofile[i + j];
                                if (fp == NULL) {
-                                       *errp = EBADF;
+                                       error = EBADF;
                                        break;
                                }
                                if ((*fp->f_ops->fo_select)(fp, flag)) {
                                        break;
                                }
                                if ((*fp->f_ops->fo_select)(fp, flag)) {
@@ -530,7 +542,8 @@ selscan(ibits, obits, nfd, errp)
                        }
                }
        }
                        }
                }
        }
-       return (n);
+       *retval = n;
+       return (error);
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/