add some missing returns, correct args to ipcaccess, general cleanup
[unix-history] / usr / src / sys / kern / sys_process.c
index 90a993f..20cd58c 100644 (file)
@@ -3,12 +3,12 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)sys_process.c       7.6 (Berkeley) %G%
+ *     @(#)sys_process.c       7.10 (Berkeley) %G%
  */
 
 #define IPCREG
 #include "param.h"
  */
 
 #define IPCREG
 #include "param.h"
-#include "user.h"
+#include "syscontext.h"
 #include "proc.h"
 #include "vnode.h"
 #include "text.h"
 #include "proc.h"
 #include "vnode.h"
 #include "text.h"
@@ -43,27 +43,26 @@ struct {
 /*
  * sys-trace system call.
  */
 /*
  * sys-trace system call.
  */
-ptrace()
-{
-       register struct proc *p;
-       register struct a {
+ptrace(curp, uap, retval)
+       struct proc *curp;
+       register struct args {
                int     req;
                int     pid;
                int     *addr;
                int     data;
        } *uap;
                int     req;
                int     pid;
                int     *addr;
                int     data;
        } *uap;
+       int *retval;
+{
+       register struct proc *p;
 
 
-       uap = (struct a *)u.u_ap;
        if (uap->req <= 0) {
        if (uap->req <= 0) {
-               u.u_procp->p_flag |= STRC;
-               return;
+               curp->p_flag |= STRC;
+               RETURN (0);
        }
        p = pfind(uap->pid);
        }
        p = pfind(uap->pid);
-       if (p == 0 || p->p_stat != SSTOP || p->p_ppid != u.u_procp->p_pid ||
-           !(p->p_flag & STRC)) {
-               u.u_error = ESRCH;
-               return;
-       }
+       if (p == 0 || p->p_stat != SSTOP || p->p_ppid != curp->p_pid ||
+           !(p->p_flag & STRC))
+               RETURN (ESRCH);
        while (ipc.ip_lock)
                sleep((caddr_t)&ipc, IPCPRI);
        ipc.ip_lock = p->p_pid;
        while (ipc.ip_lock)
                sleep((caddr_t)&ipc, IPCPRI);
        ipc.ip_lock = p->p_pid;
@@ -76,11 +75,12 @@ ptrace()
                        setrun(p);
                sleep((caddr_t)&ipc, IPCPRI);
        }
                        setrun(p);
                sleep((caddr_t)&ipc, IPCPRI);
        }
-       u.u_r.r_val1 = ipc.ip_data;
-       if (ipc.ip_req < 0)
-               u.u_error = EIO;
+       *retval = ipc.ip_data;
        ipc.ip_lock = 0;
        wakeup((caddr_t)&ipc);
        ipc.ip_lock = 0;
        wakeup((caddr_t)&ipc);
+       if (ipc.ip_req < 0)
+               RETURN (EIO);
+       RETURN (0);
 }
 
 #define        PHYSOFF(p, o) \
 }
 
 #define        PHYSOFF(p, o) \
@@ -91,17 +91,17 @@ ptrace()
  * executes to implement the command
  * of the parent process in tracing.
  */
  * executes to implement the command
  * of the parent process in tracing.
  */
-procxmt()
+procxmt(p)
+       register struct proc *p;
 {
 {
-       register int i;
-       register *p;
+       register int i, *poff;
        register struct text *xp;
        struct vattr vattr;
        struct vnode *vp;
 
        register struct text *xp;
        struct vattr vattr;
        struct vnode *vp;
 
-       if (ipc.ip_lock != u.u_procp->p_pid)
+       if (ipc.ip_lock != p->p_pid)
                return (0);
                return (0);
-       u.u_procp->p_slptime = 0;
+       p->p_slptime = 0;
        i = ipc.ip_req;
        ipc.ip_req = 0;
        switch (i) {
        i = ipc.ip_req;
        ipc.ip_req = 0;
        switch (i) {
@@ -119,8 +119,13 @@ procxmt()
                break;
 
        case PT_READ_U:                 /* read the child's u. */
                break;
 
        case PT_READ_U:                 /* read the child's u. */
+#ifdef HPUXCOMPAT
+               if (u.u_pcb.pcb_flags & PCB_HPUXTRACE)
+                       i = hpuxtobsduoff(ipc.ip_addr);
+               else
+#endif
                i = (int)ipc.ip_addr;
                i = (int)ipc.ip_addr;
-               if (i<0 || i >= ctob(UPAGES))
+               if (i<0 || i > ctob(UPAGES)-sizeof(int))
                        goto error;
                ipc.ip_data = *(int *)PHYSOFF(&u, i);
                break;
                        goto error;
                ipc.ip_data = *(int *)PHYSOFF(&u, i);
                break;
@@ -129,7 +134,7 @@ procxmt()
                /*
                 * If text, must assure exclusive use
                 */
                /*
                 * If text, must assure exclusive use
                 */
-               if (xp = u.u_procp->p_textp) {
+               if (xp = p->p_textp) {
                        vp = xp->x_vptr;
                        VOP_GETATTR(vp, &vattr, u.u_cred);
                        if (xp->x_count!=1 || (vattr.va_mode & VSVTX))
                        vp = xp->x_vptr;
                        VOP_GETATTR(vp, &vattr, u.u_cred);
                        if (xp->x_count!=1 || (vattr.va_mode & VSVTX))
@@ -138,8 +143,8 @@ procxmt()
                }
                i = -1;
                if ((i = suiword((caddr_t)ipc.ip_addr, ipc.ip_data)) < 0) {
                }
                i = -1;
                if ((i = suiword((caddr_t)ipc.ip_addr, ipc.ip_data)) < 0) {
-                       if (chgprot((caddr_t)ipc.ip_addr, RW) &&
-                           chgprot((caddr_t)ipc.ip_addr+(sizeof(int)-1), RW))
+                       if (!chgprot((caddr_t)ipc.ip_addr, RW) &&
+                           !chgprot((caddr_t)ipc.ip_addr+(sizeof(int)-1), RW))
                                i = suiword((caddr_t)ipc.ip_addr, ipc.ip_data);
                        (void) chgprot((caddr_t)ipc.ip_addr, RO);
                        (void) chgprot((caddr_t)ipc.ip_addr+(sizeof(int)-1), RO);
                                i = suiword((caddr_t)ipc.ip_addr, ipc.ip_data);
                        (void) chgprot((caddr_t)ipc.ip_addr, RO);
                        (void) chgprot((caddr_t)ipc.ip_addr+(sizeof(int)-1), RO);
@@ -148,13 +153,13 @@ procxmt()
                        goto error;
 #if defined(tahoe)
                /* make sure the old value is not in cache */
                        goto error;
 #if defined(tahoe)
                /* make sure the old value is not in cache */
-               ckeyrelease(u.u_procp->p_ckey);
-               u.u_procp->p_ckey = getcodekey();
+               ckeyrelease(p->p_ckey);
+               p->p_ckey = getcodekey();
 #endif
                if (xp) {
                        xp->x_flag |= XWRIT;
 #if defined(tahoe)
 #endif
                if (xp) {
                        xp->x_flag |= XWRIT;
 #if defined(tahoe)
-                       xp->x_ckey = u.u_procp->p_ckey;
+                       xp->x_ckey = p->p_ckey;
 #endif
                }
                break;
 #endif
                }
                break;
@@ -166,24 +171,36 @@ procxmt()
                break;
 
        case PT_WRITE_U:                /* write the child's u. */
                break;
 
        case PT_WRITE_U:                /* write the child's u. */
+#ifdef HPUXCOMPAT
+               if (u.u_pcb.pcb_flags & PCB_HPUXTRACE)
+                       i = hpuxtobsduoff(ipc.ip_addr);
+               else
+#endif
                i = (int)ipc.ip_addr;
                i = (int)ipc.ip_addr;
-               p = (int *)PHYSOFF(&u, i);
+               poff = (int *)PHYSOFF(&u, i);
                for (i=0; i<NIPCREG; i++)
                for (i=0; i<NIPCREG; i++)
-                       if (p == &u.u_ar0[ipcreg[i]])
+                       if (poff == &u.u_ar0[ipcreg[i]])
                                goto ok;
                                goto ok;
-               if (p == &u.u_ar0[PS]) {
+               if (poff == &u.u_ar0[PS]) {
                        ipc.ip_data |= PSL_USERSET;
                        ipc.ip_data |= PSL_USERSET;
-                       ipc.ip_data &=  ~PSL_USERCLR;
+                       ipc.ip_data &= ~PSL_USERCLR;
 #ifdef PSL_CM_CLR
                        if (ipc.ip_data & PSL_CM)
                                ipc.ip_data &= ~PSL_CM_CLR;
 #endif
                        goto ok;
                }
 #ifdef PSL_CM_CLR
                        if (ipc.ip_data & PSL_CM)
                                ipc.ip_data &= ~PSL_CM_CLR;
 #endif
                        goto ok;
                }
+#if defined(hp300)
+#ifdef FPCOPROC
+               if (poff >= (int *)u.u_pcb.pcb_fpregs.fpf_regs &&
+                   poff <= (int *)&u.u_pcb.pcb_fpregs.fpf_fpiar)
+                       goto ok;
+#endif
+#endif
                goto error;
 
        ok:
                goto error;
 
        ok:
-               *p = ipc.ip_data;
+               *poff = ipc.ip_data;
                break;
 
        case PT_STEP:                   /* single step the child */
                break;
 
        case PT_STEP:                   /* single step the child */
@@ -192,7 +209,7 @@ procxmt()
                        u.u_ar0[PC] = (int)ipc.ip_addr;
                if ((unsigned)ipc.ip_data > NSIG)
                        goto error;
                        u.u_ar0[PC] = (int)ipc.ip_addr;
                if ((unsigned)ipc.ip_data > NSIG)
                        goto error;
-               u.u_procp->p_cursig = ipc.ip_data;      /* see issig */
+               p->p_cursig = ipc.ip_data;      /* see issig */
                if (i == PT_STEP) 
                        u.u_ar0[PS] |= PSL_T;
                wakeup((caddr_t)&ipc);
                if (i == PT_STEP) 
                        u.u_ar0[PS] |= PSL_T;
                wakeup((caddr_t)&ipc);
@@ -200,7 +217,7 @@ procxmt()
 
        case PT_KILL:                   /* kill the child process */
                wakeup((caddr_t)&ipc);
 
        case PT_KILL:                   /* kill the child process */
                wakeup((caddr_t)&ipc);
-               exit(u.u_procp->p_cursig);
+               exit(p, p->p_cursig);
 
        default:
        error:
 
        default:
        error: