fixed problem with sizeof MsgId == 0
[unix-history] / usr / src / sys / kern / kern_proc.c
index 0b8fde9..4f5ffeb 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_proc.c     3.15    %G%     */
+/*     kern_proc.c     3.24    %G%     */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -17,6 +17,8 @@
 #include "../h/vm.h"
 #include "../h/text.h"
 #include "../h/psl.h"
 #include "../h/vm.h"
 #include "../h/text.h"
 #include "../h/psl.h"
+#include "../h/vlimit.h"
+#include "../h/file.h"
 
 /*
  * exec system call, with and without environments.
 
 /*
  * exec system call, with and without environments.
@@ -111,7 +113,8 @@ exece()
                bdwrite(bp);
        bp = 0;
        nc = (nc + NBPW-1) & ~(NBPW-1);
                bdwrite(bp);
        bp = 0;
        nc = (nc + NBPW-1) & ~(NBPW-1);
-       if (getxfile(ip, nc) || u.u_error) {
+       getxfile(ip, nc + (na+4)*NBPW);
+       if (u.u_error) {
 badarg:
                for (c = 0; c < nc; c += BSIZE)
                        if (bp = baddr(argdev, dbtofsb(bno)+(c>>BSHIFT))) {
 badarg:
                for (c = 0; c < nc; c += BSIZE)
                        if (bp = baddr(argdev, dbtofsb(bno)+(c>>BSHIFT))) {
@@ -168,27 +171,20 @@ bad:
 
 /*
  * Read in and set up memory for executed file.
 
 /*
  * Read in and set up memory for executed file.
- * Zero return is normal;
- * non-zero means only the text is being replaced
  */
 getxfile(ip, nargc)
 register struct inode *ip;
 {
  */
 getxfile(ip, nargc)
 register struct inode *ip;
 {
-       register sep;
        register size_t ts, ds, ss;
        register size_t ts, ds, ss;
-       register int overlay;
        int pagi = 0;
 
        /*
         * read in first few bytes
         * of file for segment
         * sizes:
        int pagi = 0;
 
        /*
         * read in first few bytes
         * of file for segment
         * sizes:
-        * ux_mag = 407/410/411/405
+        * ux_mag = 407/410/413
         *  407 is plain executable
         *  410 is RO text
         *  407 is plain executable
         *  410 is RO text
-        *  411 is separated ID
-        *  405 is overlaid text
-        *  412 is demand paged plain executable (NOT IMPLEMENTED)
         *  413 is demand paged RO text
         */
 
         *  413 is demand paged RO text
         */
 
@@ -204,18 +200,8 @@ register struct inode *ip;
                u.u_error = ENOEXEC;
                goto bad;
        }
                u.u_error = ENOEXEC;
                goto bad;
        }
-       sep = 0;
-       overlay = 0;
        switch (u.u_exdata.ux_mag) {
 
        switch (u.u_exdata.ux_mag) {
 
-       case 0405:
-               overlay++;
-               break;
-
-       case 0412:
-               u.u_error = ENOEXEC;
-               goto bad;
-
        case 0407:
                u.u_exdata.ux_dsize += u.u_exdata.ux_tsize;
                u.u_exdata.ux_tsize = 0;
        case 0407:
                u.u_exdata.ux_dsize += u.u_exdata.ux_tsize;
                u.u_exdata.ux_tsize = 0;
@@ -232,17 +218,18 @@ register struct inode *ip;
                }
                break;
 
                }
                break;
 
-       case 0411:
-               u.u_error = ENOEXEC;
-               goto bad;
-
        default:
                u.u_error = ENOEXEC;
                goto bad;
        }
        if(u.u_exdata.ux_tsize!=0 && (ip->i_flag&ITEXT)==0 && ip->i_count!=1) {
        default:
                u.u_error = ENOEXEC;
                goto bad;
        }
        if(u.u_exdata.ux_tsize!=0 && (ip->i_flag&ITEXT)==0 && ip->i_count!=1) {
-               u.u_error = ETXTBSY;
-               goto bad;
+               register struct file *fp;
+
+               for (fp = file; fp < &file[NFILE]; fp++)
+                       if (fp->f_inode == ip && (fp->f_flag&FWRITE)) {
+                               u.u_error = ETXTBSY;
+                               goto bad;
+                       }
        }
 
        /*
        }
 
        /*
@@ -254,89 +241,74 @@ register struct inode *ip;
        ts = clrnd(btoc(u.u_exdata.ux_tsize));
        ds = clrnd(btoc((u.u_exdata.ux_dsize+u.u_exdata.ux_bsize)));
        ss = clrnd(SSIZE + btoc(nargc));
        ts = clrnd(btoc(u.u_exdata.ux_tsize));
        ds = clrnd(btoc((u.u_exdata.ux_dsize+u.u_exdata.ux_bsize)));
        ss = clrnd(SSIZE + btoc(nargc));
-       if (overlay) {
-               if ((u.u_procp->p_flag & SPAGI) ||
-                   u.u_sep==0 && ctos(ts) != ctos(u.u_tsize) || nargc) {
-                       u.u_error = ENOMEM;
-                       goto bad;
-               }
-               ds = u.u_dsize;
-               ss = u.u_ssize;
-               sep = u.u_sep;
-               xfree();
-               xalloc(ip, pagi);
-               u.u_ar0[PC] = u.u_exdata.ux_entloc + 2; /* skip over entry mask */
-       } else {
-               if (chksize(ts, ds, ss))
-                       goto bad;
-               u.u_cdmap = zdmap;
-               u.u_csmap = zdmap;
-               if (swpexpand(ds, ss, &u.u_cdmap, &u.u_csmap) == NULL)
-                       goto bad;
-
-               /*
-                * At this point, committed to the new image!
-                * Release virtual memory resources of old process, and
-                * initialize the virtual memory of the new process.
-                * If we resulted from vfork(), instead wakeup our
-                * parent who will set SVFDONE when he has taken back
-                * our resources.
-                */
-               u.u_prof.pr_scale = 0;
-               if ((u.u_procp->p_flag & SVFORK) == 0)
-                       vrelvm();
-               else {
-                       u.u_procp->p_flag &= ~SVFORK;
-                       u.u_procp->p_flag |= SKEEP;
-                       wakeup((caddr_t)u.u_procp);
-                       while ((u.u_procp->p_flag & SVFDONE) == 0)
-                               sleep((caddr_t)u.u_procp, PZERO - 1);
-                       u.u_procp->p_flag &= ~(SVFDONE|SKEEP);
-               }
-               u.u_procp->p_flag &= ~(SPAGI|SANOM|SUANOM);
-               u.u_procp->p_flag |= pagi;
-               u.u_dmap = u.u_cdmap;
-               u.u_smap = u.u_csmap;
-               vgetvm(ts, ds, ss);
-
-               if (pagi == 0) {
-                       /*
-                        * Read in data segment.
-                        */
-                       u.u_base = (char *)ctob(ts);
-                       u.u_offset = sizeof(u.u_exdata)+u.u_exdata.ux_tsize;
-                       u.u_count = u.u_exdata.ux_dsize;
-                       readi(ip);
-               }
-               xalloc(ip, pagi);
-               if (pagi && u.u_procp->p_textp)
-                       vinifod((struct fpte *)dptopte(u.u_procp, 0),
-                           PG_FTEXT, u.u_procp->p_textp->x_iptr,
-                           1 + ts/CLSIZE, (int)btoc(u.u_exdata.ux_dsize));
+       if (chksize(ts, ds, ss))
+               goto bad;
+       u.u_cdmap = zdmap;
+       u.u_csmap = zdmap;
+       if (swpexpand(ds, ss, &u.u_cdmap, &u.u_csmap) == NULL)
+               goto bad;
 
 
-               /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
-               mtpr(TBIA, 0);
+       /*
+        * At this point, committed to the new image!
+        * Release virtual memory resources of old process, and
+        * initialize the virtual memory of the new process.
+        * If we resulted from vfork(), instead wakeup our
+        * parent who will set SVFDONE when he has taken back
+        * our resources.
+        */
+       u.u_prof.pr_scale = 0;
+       if ((u.u_procp->p_flag & SVFORK) == 0)
+               vrelvm();
+       else {
+               u.u_procp->p_flag &= ~SVFORK;
+               u.u_procp->p_flag |= SKEEP;
+               wakeup((caddr_t)u.u_procp);
+               while ((u.u_procp->p_flag & SVFDONE) == 0)
+                       sleep((caddr_t)u.u_procp, PZERO - 1);
+               u.u_procp->p_flag &= ~(SVFDONE|SKEEP);
+       }
+       u.u_procp->p_flag &= ~(SPAGI|SANOM|SUANOM|SNUSIG);
+       u.u_procp->p_flag |= pagi;
+       u.u_dmap = u.u_cdmap;
+       u.u_smap = u.u_csmap;
+       vgetvm(ts, ds, ss);
 
 
+       if (pagi == 0) {
                /*
                /*
-                * set SUID/SGID protections, if no tracing
+                * Read in data segment.
                 */
                 */
-               if ((u.u_procp->p_flag&STRC)==0) {
-                       if(ip->i_mode&ISUID)
-                               if(u.u_uid != 0) {
-                                       u.u_uid = ip->i_uid;
-                                       u.u_procp->p_uid = ip->i_uid;
-                               }
-                       if(ip->i_mode&ISGID)
-                               u.u_gid = ip->i_gid;
-               } else
-                       psignal(u.u_procp, SIGTRAP);
+               u.u_base = (char *)ctob(ts);
+               u.u_offset = sizeof(u.u_exdata)+u.u_exdata.ux_tsize;
+               u.u_count = u.u_exdata.ux_dsize;
+               readi(ip);
        }
        }
+       xalloc(ip, pagi);
+       if (pagi && u.u_procp->p_textp)
+               vinifod((struct fpte *)dptopte(u.u_procp, 0),
+                   PG_FTEXT, u.u_procp->p_textp->x_iptr,
+                   1 + ts/CLSIZE, (int)btoc(u.u_exdata.ux_dsize));
+
+       /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
+       mtpr(TBIA, 0);
+
+       /*
+        * set SUID/SGID protections, if no tracing
+        */
+       if ((u.u_procp->p_flag&STRC)==0) {
+               if(ip->i_mode&ISUID)
+                       if(u.u_uid != 0) {
+                               u.u_uid = ip->i_uid;
+                               u.u_procp->p_uid = ip->i_uid;
+                       }
+               if(ip->i_mode&ISGID)
+                       u.u_gid = ip->i_gid;
+       } else
+               psignal(u.u_procp, SIGTRAP);
        u.u_tsize = ts;
        u.u_dsize = ds;
        u.u_ssize = ss;
        u.u_tsize = ts;
        u.u_dsize = ds;
        u.u_ssize = ss;
-       u.u_sep = sep;
 bad:
 bad:
-       return(overlay);
+       return;
 }
 
 /*
 }
 
 /*
@@ -467,13 +439,14 @@ exit(rv)
                plock(u.u_rdir);
                iput(u.u_rdir);
        }
                plock(u.u_rdir);
                iput(u.u_rdir);
        }
+       u.u_limit[LIM_FSIZE] = INFINITY;
        acct();
        vrelpt(u.u_procp);
        vrelu(u.u_procp, 0);
        multprog--;
 /*     spl7();                 /* clock will get mad because of overlaying */
        acct();
        vrelpt(u.u_procp);
        vrelu(u.u_procp, 0);
        multprog--;
 /*     spl7();                 /* clock will get mad because of overlaying */
-       noproc = 1;
        p->p_stat = SZOMB;
        p->p_stat = SZOMB;
+       noproc = 1;
        i = PIDHASH(p->p_pid);
        x = p - proc;
        if (pidhash[i] == x)
        i = PIDHASH(p->p_pid);
        x = p - proc;
        if (pidhash[i] == x)
@@ -594,12 +567,10 @@ loop:
                u.u_r.r_val1 = 0;
                return;
        }
                u.u_r.r_val1 = 0;
                return;
        }
-/*
-       if (setjmp(u.u_qsav)) {
+       if ((u.u_procp->p_flag&SNUSIG) && setjmp(u.u_qsav)) {
                u.u_eosys = RESTARTSYS;
                return;
        }
                u.u_eosys = RESTARTSYS;
                return;
        }
-*/
        sleep((caddr_t)u.u_procp, PWAIT);
        goto loop;
 }
        sleep((caddr_t)u.u_procp, PWAIT);
        goto loop;
 }
@@ -684,6 +655,10 @@ sbreak()
        if (n < 0)
                n = 0;
        d = clrnd(n - u.u_dsize);
        if (n < 0)
                n = 0;
        d = clrnd(n - u.u_dsize);
+       if (ctob(u.u_dsize+d) > u.u_limit[LIM_DATA]) {
+               u.u_error = ENOMEM;
+               return;
+       }
        if (chksize(u.u_tsize, u.u_dsize+d, u.u_ssize))
                return;
        if (swpexpand(u.u_dsize+d, u.u_ssize, &u.u_dmap, &u.u_smap)==0)
        if (chksize(u.u_tsize, u.u_dsize+d, u.u_ssize))
                return;
        if (swpexpand(u.u_dsize+d, u.u_ssize, &u.u_dmap, &u.u_smap)==0)