setgroups check int > NGROUPS, so negative would fail; minor cleanup
[unix-history] / usr / src / sys / kern / kern_exec.c
index 84b8a2b..175c7c5 100644 (file)
@@ -2,19 +2,9 @@
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  *
  *
- *     @(#)kern_exec.c 7.14 (Berkeley) %G%
+ *     @(#)kern_exec.c 7.30 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 #include "machine/psl.h"
 #include "machine/mtpr.h"
 
 #include "machine/psl.h"
 #include "machine/mtpr.h"
 
+#ifdef HPUXCOMPAT
+#include "../hpux/hpux_exec.h"
+#endif
+
 /*
  * exec system call, with and without environments.
  */
 /*
  * exec system call, with and without environments.
  */
-struct execa {
-       char    *fname;
-       char    **argp;
-       char    **envp;
-};
-
-execv()
+execv(p, uap, retval)
+       struct proc *p;
+       struct args {
+               char    *fname;
+               char    **argp;
+               char    **envp;
+       } *uap;
+       int *retval;
 {
 {
-       ((struct execa *)u.u_ap)->envp = NULL;
-       execve();
+
+       uap->envp = NULL;
+       return (execve(p, uap, retval));
 }
 
 }
 
-execve()
+/* ARGSUSED */
+execve(p, uap, retval)
+       register struct proc *p;
+       register struct args {
+               char    *fname;
+               char    **argp;
+               char    **envp;
+       } *uap;
+       int *retval;
 {
        register nc;
        register char *cp;
        register struct buf *bp;
        struct buf *tbp;
 {
        register nc;
        register char *cp;
        register struct buf *bp;
        struct buf *tbp;
-       register struct execa *uap;
        int na, ne, ucp, ap, cc;
        unsigned len;
        int indir, uid, gid;
        int na, ne, ucp, ap, cc;
        unsigned len;
        int indir, uid, gid;
@@ -75,32 +78,39 @@ execve()
        union {
                char    ex_shell[MAXINTERP];    /* #! and interpreter name */
                struct  exec ex_exec;
        union {
                char    ex_shell[MAXINTERP];    /* #! and interpreter name */
                struct  exec ex_exec;
+#ifdef HPUXCOMPAT
+               struct  hpux_exec ex_hexec;
+#endif
        } exdata;
        } exdata;
+#ifdef HPUXCOMPAT
+       struct hpux_exec hhead;
+#endif
+       register struct ucred *cred = u.u_cred;
        register struct nameidata *ndp = &u.u_nd;
        register struct nameidata *ndp = &u.u_nd;
-       int resid, error;
+       int resid, error, flags = 0;
 #ifdef SECSIZE
        extern long argdbsize;                  /* XXX */
 #endif SECSIZE
 
 #ifdef SECSIZE
        extern long argdbsize;                  /* XXX */
 #endif SECSIZE
 
+  start:
        ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
        ndp->ni_segflg = UIO_USERSPACE;
        ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
        ndp->ni_segflg = UIO_USERSPACE;
-       ndp->ni_dirp = ((struct execa *)u.u_ap)->fname;
-       if (u.u_error = namei(ndp)) {
-               return;
-       }
+       ndp->ni_dirp = uap->fname;
+       if (error = namei(ndp))
+               return (error);
        vp = ndp->ni_vp;
        bno = 0;
        bp = 0;
        indir = 0;
        vp = ndp->ni_vp;
        bno = 0;
        bp = 0;
        indir = 0;
-       uid = u.u_cred->cr_uid;
-       gid = u.u_cred->cr_gid;
-       if (u.u_error = VOP_GETATTR(vp, &vattr, u.u_cred))
+       uid = cred->cr_uid;
+       gid = cred->cr_gid;
+       if (error = VOP_GETATTR(vp, &vattr, cred))
                goto bad;
                goto bad;
-       if (vp->v_mount->m_flag & M_NOEXEC) {
-               u.u_error = EACCES;
+       if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
+               error = EACCES;
                goto bad;
        }
                goto bad;
        }
-       if ((vp->v_mount->m_flag & M_NOSUID) == 0) {
+       if ((vp->v_mount->mnt_flag & MNT_NOSUID) == 0) {
                if (vattr.va_mode & VSUID)
                        uid = vattr.va_uid;
                if (vattr.va_mode & VSGID)
                if (vattr.va_mode & VSUID)
                        uid = vattr.va_uid;
                if (vattr.va_mode & VSGID)
@@ -108,14 +118,13 @@ execve()
        }
 
   again:
        }
 
   again:
-       if (u.u_error = VOP_ACCESS(vp, VEXEC, u.u_cred))
+       if (error = VOP_ACCESS(vp, VEXEC, cred))
                goto bad;
                goto bad;
-       if ((u.u_procp->p_flag & STRC) &&
-           (u.u_error = VOP_ACCESS(vp, VREAD, u.u_cred)))
+       if ((p->p_flag & STRC) && (error = VOP_ACCESS(vp, VREAD, cred)))
                goto bad;
        if (vp->v_type != VREG ||
            (vattr.va_mode & (VEXEC|(VEXEC>>3)|(VEXEC>>6))) == 0) {
                goto bad;
        if (vp->v_type != VREG ||
            (vattr.va_mode & (VEXEC|(VEXEC>>3)|(VEXEC>>6))) == 0) {
-               u.u_error = EACCES;
+               error = EACCES;
                goto bad;
        }
 
                goto bad;
        }
 
@@ -134,16 +143,80 @@ execve()
         * THE ASCII LINE.
         */
        exdata.ex_shell[0] = '\0';      /* for zero length files */
         * THE ASCII LINE.
         */
        exdata.ex_shell[0] = '\0';      /* for zero length files */
-       u.u_error = vn_rdwr(UIO_READ, vp, (caddr_t)&exdata, sizeof (exdata),
-           (off_t)0, UIO_SYSSPACE, (IO_UNIT|IO_NODELOCKED), u.u_cred, &resid);
-       if (u.u_error)
+       error = vn_rdwr(UIO_READ, vp, (caddr_t)&exdata, sizeof (exdata),
+           (off_t)0, UIO_SYSSPACE, (IO_UNIT|IO_NODELOCKED), cred, &resid);
+       if (error)
                goto bad;
 #ifndef lint
        if (resid > sizeof(exdata) - sizeof(exdata.ex_exec) &&
            exdata.ex_shell[0] != '#') {
                goto bad;
 #ifndef lint
        if (resid > sizeof(exdata) - sizeof(exdata.ex_exec) &&
            exdata.ex_shell[0] != '#') {
-               u.u_error = ENOEXEC;
+               error = ENOEXEC;
                goto bad;
        }
                goto bad;
        }
+#endif
+#if defined(hp300)
+       switch ((int)exdata.ex_exec.a_mid) {
+
+       /*
+        * An ancient hp200 or hp300 binary, shouldn't happen anymore.
+        * Mark as invalid.
+        */
+       case MID_ZERO:
+               exdata.ex_exec.a_magic = 0;
+               break;
+
+       /*
+        * HP200 series has a smaller page size so we cannot
+        * demand-load or even write protect text, so we just
+        * treat as OMAGIC.
+        */
+       case MID_HP200:
+               exdata.ex_exec.a_magic = OMAGIC;
+               break;
+
+       case MID_HP300:
+               break;
+
+#ifdef HPUXCOMPAT
+       case MID_HPUX:
+               /*
+                * Save a.out header.  This is eventually saved in the pcb,
+                * but we cannot do that yet in case the exec fails before
+                * the image is overlayed.
+                */
+               bcopy((caddr_t)&exdata.ex_hexec,
+                     (caddr_t)&hhead, sizeof hhead);
+               /*
+                * If version number is 0x2bad this is a native BSD
+                * binary created via the HPUX SGS.  Should not be
+                * treated as an HPUX binary.
+                */
+               if (exdata.ex_hexec.ha_version != BSDVNUM)
+                       flags |= SHPUX;
+               /*
+                * Shuffle important fields to their BSD locations.
+                * Note that the order in which this is done is important.
+                */
+               exdata.ex_exec.a_text = exdata.ex_hexec.ha_text;
+               exdata.ex_exec.a_data = exdata.ex_hexec.ha_data;
+               exdata.ex_exec.a_bss = exdata.ex_hexec.ha_bss;
+               exdata.ex_exec.a_entry = exdata.ex_hexec.ha_entry;
+               /*
+                * For ZMAGIC files, make sizes consistant with those
+                * generated by BSD ld.
+                */
+               if (exdata.ex_exec.a_magic == ZMAGIC) {
+                       exdata.ex_exec.a_text = 
+                               ctob(btoc(exdata.ex_exec.a_text));
+                       nc = exdata.ex_exec.a_data + exdata.ex_exec.a_bss;
+                       exdata.ex_exec.a_data =
+                               ctob(btoc(exdata.ex_exec.a_data));
+                       nc -= (int)exdata.ex_exec.a_data;
+                       exdata.ex_exec.a_bss = (nc < 0) ? 0 : nc;
+               }
+               break;
+#endif
+       }
 #endif
        switch ((int)exdata.ex_exec.a_magic) {
 
 #endif
        switch ((int)exdata.ex_exec.a_magic) {
 
@@ -153,9 +226,10 @@ execve()
                break;
 
        case ZMAGIC:
                break;
 
        case ZMAGIC:
+               flags |= SPAGV;
        case NMAGIC:
                if (exdata.ex_exec.a_text == 0) {
        case NMAGIC:
                if (exdata.ex_exec.a_text == 0) {
-                       u.u_error = ENOEXEC;
+                       error = ENOEXEC;
                        goto bad;
                }
                break;
                        goto bad;
                }
                break;
@@ -164,12 +238,12 @@ execve()
                if (exdata.ex_shell[0] != '#' ||
                    exdata.ex_shell[1] != '!' ||
                    indir) {
                if (exdata.ex_shell[0] != '#' ||
                    exdata.ex_shell[1] != '!' ||
                    indir) {
-                       u.u_error = ENOEXEC;
+                       error = ENOEXEC;
                        goto bad;
                }
                for (cp = &exdata.ex_shell[2];; ++cp) {
                        if (cp >= &exdata.ex_shell[MAXINTERP]) {
                        goto bad;
                }
                for (cp = &exdata.ex_shell[2];; ++cp) {
                        if (cp >= &exdata.ex_shell[MAXINTERP]) {
-                               u.u_error = ENOEXEC;
+                               error = ENOEXEC;
                                goto bad;
                        }
                        if (*cp == '\n') {
                                goto bad;
                        }
                        if (*cp == '\n') {
@@ -197,18 +271,34 @@ execve()
                vput(vp);
                ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
                ndp->ni_segflg = UIO_SYSSPACE;
                vput(vp);
                ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
                ndp->ni_segflg = UIO_SYSSPACE;
-               if (u.u_error = namei(ndp))
-                       return;
+               if (error = namei(ndp))
+                       return (error);
                vp = ndp->ni_vp;
                vp = ndp->ni_vp;
-               if (u.u_error = VOP_GETATTR(vp, &vattr, u.u_cred))
+               if (error = VOP_GETATTR(vp, &vattr, cred))
                        goto bad;
                bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)cfname,
                    MAXCOMLEN);
                cfname[MAXCOMLEN] = '\0';
                        goto bad;
                bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)cfname,
                    MAXCOMLEN);
                cfname[MAXCOMLEN] = '\0';
-               uid = u.u_cred->cr_uid; /* shell scripts can't be setuid */
-               gid = u.u_cred->cr_gid;
+               uid = cred->cr_uid;     /* shell scripts can't be setuid */
+               gid = cred->cr_gid;
                goto again;
        }
                goto again;
        }
+       /*
+        * If the vnode has been modified since we last used it,
+        * then throw away all its pages and its text table entry.
+        */
+       if (vp->v_text && vp->v_text->x_mtime != vattr.va_mtime.tv_sec) {
+               /*
+                * Try once to release, if it is still busy
+                * take more drastic action.
+                */
+               xrele(vp);
+               if (vp->v_flag & VTEXT) {
+                       vput(vp);
+                       vgone(vp);
+                       goto start;
+               }
+       }
 
        /*
         * Collect arguments on "file" in swap space.
 
        /*
         * Collect arguments on "file" in swap space.
@@ -217,18 +307,21 @@ execve()
        ne = 0;
        nc = 0;
        cc = 0;
        ne = 0;
        nc = 0;
        cc = 0;
-       uap = (struct execa *)u.u_ap;
 #ifdef SECSIZE
        bno = rmalloc(argmap, (clrnd((int)btoc(NCARGS))) * CLBYTES / argdbsize);
 #else SECSIZE
        bno = rmalloc(argmap, (long)ctod(clrnd((int)btoc(NCARGS))));
 #endif SECSIZE
        if (bno == 0) {
 #ifdef SECSIZE
        bno = rmalloc(argmap, (clrnd((int)btoc(NCARGS))) * CLBYTES / argdbsize);
 #else SECSIZE
        bno = rmalloc(argmap, (long)ctod(clrnd((int)btoc(NCARGS))));
 #endif SECSIZE
        if (bno == 0) {
-               swkill(u.u_procp, "exec: no swap space");
+               swkill(p, "exec: no swap space");
                goto bad;
        }
        if (bno % CLSIZE)
                panic("execa rmalloc");
                goto bad;
        }
        if (bno % CLSIZE)
                panic("execa rmalloc");
+#ifdef GENERIC
+       if (rootdev == dumpdev)
+               bno += 4096;
+#endif
        /*
         * Copy arguments into file in argdev area.
         */
        /*
         * Copy arguments into file in argdev area.
         */
@@ -257,8 +350,12 @@ execve()
                        break;
                na++;
                if (ap == -1) {
                        break;
                na++;
                if (ap == -1) {
-                       u.u_error = EFAULT;
-                       break;
+                       error = EFAULT;
+                       if (bp) {
+                               brelse(bp);
+                               bp = 0;
+                       }
+                       goto badarg;
                }
                do {
                        if (cc <= 0) {
                }
                do {
                        if (cc <= 0) {
@@ -295,7 +392,6 @@ execve()
                        cc -= len;
                } while (error == ENOENT);
                if (error) {
                        cc -= len;
                } while (error == ENOENT);
                if (error) {
-                       u.u_error = error;
                        if (bp)
                                brelse(bp);
                        bp = 0;
                        if (bp)
                                brelse(bp);
                        bp = 0;
@@ -306,26 +402,38 @@ execve()
                bdwrite(bp);
        bp = 0;
        nc = (nc + NBPW-1) & ~(NBPW-1);
                bdwrite(bp);
        bp = 0;
        nc = (nc + NBPW-1) & ~(NBPW-1);
-       getxfile(vp, &exdata.ex_exec, nc + (na+4)*NBPW, uid, gid, u.u_cred);
-       if (u.u_error) {
+       error = getxfile(p, vp, &exdata.ex_exec, flags, nc + (na+4)*NBPW,
+           uid, gid);
+       if (error) {
 badarg:
                for (cc = 0; cc < nc; cc += CLBYTES) {
 badarg:
                for (cc = 0; cc < nc; cc += CLBYTES) {
-                       u.u_error = baddr(argdev_vp, bno + ctod(cc/NBPG),
+                       (void) baddr(argdev_vp, bno + ctod(cc/NBPG),
                                CLBYTES, NOCRED, &tbp);
                        bp = tbp;
 #endif SECSIZE
                        if (bp) {
                                CLBYTES, NOCRED, &tbp);
                        bp = tbp;
 #endif SECSIZE
                        if (bp) {
-                               bp->b_flags |= B_AGE;           /* throw away */
-                               bp->b_flags &= ~B_DELWRI;       /* cancel io */
+                               bp->b_flags |= B_INVAL;         /* throw away */
                                brelse(bp);
                                bp = 0;
                        }
                }
                goto bad;
        }
                                brelse(bp);
                                bp = 0;
                        }
                }
                goto bad;
        }
+       if (vp->v_text)
+               vp->v_text->x_mtime = vattr.va_mtime.tv_sec;
        vput(vp);
        vp = NULL;
 
        vput(vp);
        vp = NULL;
 
+#ifdef HPUXCOMPAT
+       /*
+        * We are now committed to the exec so we can save the exec
+        * header in the pcb where we can dump it if necessary in core()
+        */
+       if (u.u_pcb.pcb_flags & PCB_HPUXBIN)
+               bcopy((caddr_t)&hhead,
+                     (caddr_t)u.u_pcb.pcb_exec, sizeof hhead);
+#endif
+
        /*
         * Copy back arglist.
         */
        /*
         * Copy back arglist.
         */
@@ -358,8 +466,7 @@ badarg:
                                    NOCRED, &tbp);
                                bp = tbp;
 #endif SECSIZE
                                    NOCRED, &tbp);
                                bp = tbp;
 #endif SECSIZE
-                               bp->b_flags |= B_AGE;           /* throw away */
-                               bp->b_flags &= ~B_DELWRI;       /* cancel io */
+                               bp->b_flags |= B_INVAL;         /* throw away */
                                cp = bp->b_un.b_addr;
                        }
                        error = copyoutstr(cp, (caddr_t)ucp, (unsigned)cc,
                                cp = bp->b_un.b_addr;
                        }
                        error = copyoutstr(cp, (caddr_t)ucp, (unsigned)cc,
@@ -374,11 +481,11 @@ badarg:
        }
        (void) suword((caddr_t)ap, 0);
 
        }
        (void) suword((caddr_t)ap, 0);
 
-       execsigs(u.u_procp);
+       execsigs(p);
 
        for (nc = u.u_lastfile; nc >= 0; --nc) {
                if (u.u_pofile[nc] & UF_EXCLOSE) {
 
        for (nc = u.u_lastfile; nc >= 0; --nc) {
                if (u.u_pofile[nc] & UF_EXCLOSE) {
-                       closef(u.u_ofile[nc]);
+                       (void) closef(u.u_ofile[nc]);
                        u.u_ofile[nc] = NULL;
                        u.u_pofile[nc] = 0;
                }
                        u.u_ofile[nc] = NULL;
                        u.u_pofile[nc] = 0;
                }
@@ -386,17 +493,17 @@ badarg:
        }
        while (u.u_lastfile >= 0 && u.u_ofile[u.u_lastfile] == NULL)
                u.u_lastfile--;
        }
        while (u.u_lastfile >= 0 && u.u_ofile[u.u_lastfile] == NULL)
                u.u_lastfile--;
-       setregs(exdata.ex_exec.a_entry);
+       setregs(exdata.ex_exec.a_entry, retval);
        /*
         * Remember file name for accounting.
         */
        u.u_acflag &= ~AFORK;
        if (indir)
        /*
         * Remember file name for accounting.
         */
        u.u_acflag &= ~AFORK;
        if (indir)
-               bcopy((caddr_t)cfname, (caddr_t)u.u_comm, MAXCOMLEN);
+               bcopy((caddr_t)cfname, (caddr_t)p->p_comm, MAXCOMLEN);
        else {
                if (ndp->ni_dent.d_namlen > MAXCOMLEN)
                        ndp->ni_dent.d_namlen = MAXCOMLEN;
        else {
                if (ndp->ni_dent.d_namlen > MAXCOMLEN)
                        ndp->ni_dent.d_namlen = MAXCOMLEN;
-               bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)u.u_comm,
+               bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)p->p_comm,
                    (unsigned)(ndp->ni_dent.d_namlen + 1));
        }
 bad:
                    (unsigned)(ndp->ni_dent.d_namlen + 1));
        }
 bad:
@@ -411,31 +518,33 @@ bad:
 #endif SECSIZE
        if (vp)
                vput(vp);
 #endif SECSIZE
        if (vp)
                vput(vp);
+       return (error);
 }
 
 /*
  * Read in and set up memory for executed file.
  */
 }
 
 /*
  * Read in and set up memory for executed file.
  */
-getxfile(vp, ep, nargc, uid, gid, cred)
+getxfile(p, vp, ep, flags, nargc, uid, gid)
+       register struct proc *p;
        register struct vnode *vp;
        register struct exec *ep;
        register struct vnode *vp;
        register struct exec *ep;
-       int nargc, uid, gid;
-       struct ucred *cred;
+       int flags, nargc, uid, gid;
 {
 {
-       register struct proc *p = u.u_procp;
-       size_t ts, ds, ids, uds, ss;
-       int pagi;
+       segsz_t ts, ds, ids, uds, ss;
+       register struct ucred *cred = u.u_cred;
+       off_t toff;
+       int error;
 
 
-       if (ep->a_magic == ZMAGIC)
-               pagi = SPAGV;
+#ifdef HPUXCOMPAT
+       if (ep->a_mid == MID_HPUX)
+               toff = sizeof (struct hpux_exec);
        else
        else
-               pagi = 0;
-       if (vp->v_text && (vp->v_text->x_flag & XTRC)) {
-               u.u_error = ETXTBSY;
-               goto bad;
-       }
+#endif
+       toff = sizeof (struct exec);
+       if (vp->v_text && (vp->v_text->x_flag & XTRC))
+               return (ETXTBSY);
        if (ep->a_text != 0 && (vp->v_flag & VTEXT) == 0 &&
        if (ep->a_text != 0 && (vp->v_flag & VTEXT) == 0 &&
-           vp->v_count != 1) {
+           vp->v_usecount != 1) {
                register struct file *fp;
 
                for (fp = file; fp < fileNFILE; fp++) {
                register struct file *fp;
 
                for (fp = file; fp < fileNFILE; fp++) {
@@ -443,8 +552,7 @@ getxfile(vp, ep, nargc, uid, gid, cred)
                            fp->f_count > 0 &&
                            (struct vnode *)fp->f_data == vp &&
                            (fp->f_flag & FWRITE)) {
                            fp->f_count > 0 &&
                            (struct vnode *)fp->f_data == vp &&
                            (fp->f_flag & FWRITE)) {
-                               u.u_error = ETXTBSY;
-                               goto bad;
+                               return (ETXTBSY);
                        }
                }
        }
                        }
                }
        }
@@ -459,16 +567,17 @@ getxfile(vp, ep, nargc, uid, gid, cred)
        uds = clrnd(btoc(ep->a_bss));
        ds = clrnd(btoc(ep->a_data + ep->a_bss));
        ss = clrnd(SSIZE + btoc(nargc));
        uds = clrnd(btoc(ep->a_bss));
        ds = clrnd(btoc(ep->a_data + ep->a_bss));
        ss = clrnd(SSIZE + btoc(nargc));
-       if (chksize((unsigned)ts, (unsigned)ids, (unsigned)uds, (unsigned)ss))
-               goto bad;
+       if (error =
+           chksize((unsigned)ts, (unsigned)ids, (unsigned)uds, (unsigned)ss))
+               return (error);
 
        /*
         * Make sure enough space to start process.
         */
        u.u_cdmap = zdmap;
        u.u_csmap = zdmap;
 
        /*
         * Make sure enough space to start process.
         */
        u.u_cdmap = zdmap;
        u.u_csmap = zdmap;
-       if (swpexpand(ds, ss, &u.u_cdmap, &u.u_csmap) == NULL)
-               goto bad;
+       if (error = swpexpand(ds, ss, &u.u_cdmap, &u.u_csmap))
+               return (error);
 
        /*
         * At this point, we are committed to the new image!
 
        /*
         * At this point, we are committed to the new image!
@@ -478,9 +587,13 @@ getxfile(vp, ep, nargc, uid, gid, cred)
         * parent who will set SVFDONE when he has taken back
         * our resources.
         */
         * parent who will set SVFDONE when he has taken back
         * our resources.
         */
-       if ((p->p_flag & SVFORK) == 0)
+       if ((p->p_flag & SVFORK) == 0) {
+#ifdef MAPMEM
+               if (u.u_mmap && (error = mmexec(p)))
+                       return (error);
+#endif
                vrelvm();
                vrelvm();
-       else {
+       else {
                p->p_flag &= ~SVFORK;
                p->p_flag |= SKEEP;
                wakeup((caddr_t)p);
                p->p_flag &= ~SVFORK;
                p->p_flag |= SKEEP;
                wakeup((caddr_t)p);
@@ -488,19 +601,27 @@ getxfile(vp, ep, nargc, uid, gid, cred)
                        sleep((caddr_t)p, PZERO - 1);
                p->p_flag &= ~(SVFDONE|SKEEP);
        }
                        sleep((caddr_t)p, PZERO - 1);
                p->p_flag &= ~(SVFDONE|SKEEP);
        }
-       p->p_flag &= ~(SPAGV|SSEQL|SUANOM);
-       p->p_flag |= pagi | SEXEC;
+#ifdef hp300
+       u.u_pcb.pcb_flags &= ~(PCB_AST|PCB_HPUXMMAP|PCB_HPUXBIN);
+#ifdef HPUXCOMPAT
+       /* remember that we were loaded from an HPUX format file */
+       if (ep->a_mid == MID_HPUX)
+               u.u_pcb.pcb_flags |= PCB_HPUXBIN;
+#endif
+#endif
+       p->p_flag &= ~(SPAGV|SSEQL|SUANOM|SHPUX);
+       p->p_flag |= flags | SEXEC;
        u.u_dmap = u.u_cdmap;
        u.u_smap = u.u_csmap;
        vgetvm(ts, ds, ss);
 
        u.u_dmap = u.u_cdmap;
        u.u_smap = u.u_csmap;
        vgetvm(ts, ds, ss);
 
-       if (pagi == 0)
-               u.u_error = vn_rdwr(UIO_READ, vp,
-                       (char *)ctob(dptov(u.u_procp, 0)),
+       if ((flags & SPAGV) == 0)
+               (void) vn_rdwr(UIO_READ, vp,
+                       (char *)ctob(dptov(p, 0)),
                        (int)ep->a_data,
                        (int)ep->a_data,
-                       (off_t)(sizeof (struct exec) + ep->a_text),
+                       (off_t)(toff + ep->a_text),
                        UIO_USERSPACE, (IO_UNIT|IO_NODELOCKED), cred, (int *)0);
                        UIO_USERSPACE, (IO_UNIT|IO_NODELOCKED), cred, (int *)0);
-       xalloc(vp, ep, pagi, cred);
+       xalloc(vp, ep, toff, cred);
 #if defined(tahoe)
        /*
         * Define new keys.
 #if defined(tahoe)
        /*
         * Define new keys.
@@ -514,31 +635,35 @@ getxfile(vp, ep, nargc, uid, gid, cred)
        p->p_dkey = getdatakey();
        mtpr(DCK, p->p_dkey);
 #endif
        p->p_dkey = getdatakey();
        mtpr(DCK, p->p_dkey);
 #endif
-       if (pagi && p->p_textp)
-               vinifod((struct fpte *)dptopte(p, 0),
+       if ((flags & SPAGV) && p->p_textp)
+               vinifod(p, (struct fpte *)dptopte(p, 0),
                    PG_FTEXT, p->p_textp->x_vptr,
                    PG_FTEXT, p->p_textp->x_vptr,
-                   (long)(1 + ts/CLSIZE), (size_t)btoc(ep->a_data));
+                   (long)(1 + ts/CLSIZE), (segsz_t)btoc(ep->a_data));
 
 #if defined(vax) || defined(tahoe)
        /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
        mtpr(TBIA, 0);
 #endif
 
 #if defined(vax) || defined(tahoe)
        /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
        mtpr(TBIA, 0);
 #endif
+#ifdef hp300
+       TBIAU();
+#endif
+#if defined(i386)
+       tlbflush();
+#endif
 
 
-       if (u.u_error)
-               swkill(u.u_procp, "exec: I/O error mapping pages");
        /*
         * set SUID/SGID protections, if no tracing
         */
        if ((p->p_flag&STRC)==0) {
        /*
         * set SUID/SGID protections, if no tracing
         */
        if ((p->p_flag&STRC)==0) {
-               if (uid != u.u_cred->cr_uid || gid != u.u_cred->cr_gid)
-                       u.u_cred = crcopy(u.u_cred);
-               u.u_cred->cr_uid = uid;
-               u.u_cred->cr_gid = gid;
+               if (uid != cred->cr_uid || gid != cred->cr_gid)
+                       u.u_cred = cred = crcopy(cred);
+               cred->cr_uid = uid;
+               cred->cr_gid = gid;
                p->p_uid = uid;
        } else
                psignal(p, SIGTRAP);
        p->p_svuid = p->p_uid;
                p->p_uid = uid;
        } else
                psignal(p, SIGTRAP);
        p->p_svuid = p->p_uid;
-       p->p_svgid = u.u_cred->cr_gid;
+       p->p_svgid = cred->cr_gid;
        u.u_tsize = ts;
        u.u_dsize = ds;
        u.u_ssize = ss;
        u.u_tsize = ts;
        u.u_dsize = ds;
        u.u_ssize = ss;
@@ -546,6 +671,5 @@ getxfile(vp, ep, nargc, uid, gid, cred)
 #if defined(tahoe)
        u.u_pcb.pcb_savacc.faddr = (float *)NULL;
 #endif
 #if defined(tahoe)
        u.u_pcb.pcb_savacc.faddr = (float *)NULL;
 #endif
-bad:
-       return;
+       return (0);
 }
 }