fix to previous changes
[unix-history] / usr / src / sys / kern / sys_process.c
index 5f34cda..bc36b1a 100644 (file)
@@ -1,9 +1,10 @@
-/*
- * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
  *
  *
- *     @(#)sys_process.c       7.17 (Berkeley) %G%
+ *     @(#)sys_process.c       7.22 (Berkeley) %G%
  */
 
 #define IPCREG
  */
 
 #define IPCREG
@@ -42,7 +43,7 @@ struct {
 } ipc;
 
 /*
 } ipc;
 
 /*
- * sys-trace system call.
+ * Process debugging system call.
  */
 ptrace(curp, uap, retval)
        struct proc *curp;
  */
 ptrace(curp, uap, retval)
        struct proc *curp;
@@ -84,8 +85,8 @@ ptrace(curp, uap, retval)
        return (0);
 }
 
        return (0);
 }
 
-#define        PHYSOFF(p, o) \
-       ((physadr)(p)+((o)/sizeof(((physadr)0)->r[0])))
+#define        PHYSOFF(p, o) ((caddr_t)(p) + (o))
+
 #if defined(i386)
 #undef        PC
 #undef        SP
 #if defined(i386)
 #undef        PC
 #undef        SP
@@ -101,19 +102,20 @@ ptrace(curp, uap, retval)
 #endif
 
 /*
 #endif
 
 /*
- * Code that the child process
- * executes to implement the command
- * of the parent process in tracing.
+ * Transmit a tracing request from the parent to the child process
+ * being debugged. This code runs in the context of the child process
+ * to fulfill the command requested by the parent.
  */
 procxmt(p)
        register struct proc *p;
 {
        register int i, *poff;
  */
 procxmt(p)
        register struct proc *p;
 {
        register int i, *poff;
+       extern char kstack[];
 
        if (ipc.ip_lock != p->p_pid)
                return (0);
        p->p_slptime = 0;
 
        if (ipc.ip_lock != p->p_pid)
                return (0);
        p->p_slptime = 0;
-       u.u_kproc.kp_proc.p_regs = p->p_regs;   /* u.u_ar0 */
+       p->p_addr->u_kproc.kp_proc.p_regs = p->p_regs;  /* u.u_ar0 */
        i = ipc.ip_req;
        ipc.ip_req = 0;
        switch (i) {
        i = ipc.ip_req;
        ipc.ip_req = 0;
        switch (i) {
@@ -132,14 +134,14 @@ procxmt(p)
 
        case PT_READ_U:                 /* read the child's u. */
 #ifdef HPUXCOMPAT
 
        case PT_READ_U:                 /* read the child's u. */
 #ifdef HPUXCOMPAT
-               if (u.u_pcb.pcb_flags & PCB_HPUXTRACE)
+               if (p->p_addr->u_pcb.pcb_flags & PCB_HPUXTRACE)
                        i = hpuxtobsduoff(ipc.ip_addr);
                else
 #endif
                i = (int)ipc.ip_addr;
                        i = hpuxtobsduoff(ipc.ip_addr);
                else
 #endif
                i = (int)ipc.ip_addr;
-               if (i<0 || i > ctob(UPAGES)-sizeof(int))
+               if ((u_int) i > ctob(UPAGES)-sizeof(int) || (i & 1) != 0)
                        goto error;
                        goto error;
-               ipc.ip_data = *(int *)PHYSOFF(&u, i);
+               ipc.ip_data = *(int *)PHYSOFF(p->p_addr, i);
                break;
 
        case PT_WRITE_I:                /* write the child's text space */
                break;
 
        case PT_WRITE_I:                /* write the child's text space */
@@ -170,12 +172,12 @@ procxmt(p)
 
        case PT_WRITE_U:                /* write the child's u. */
 #ifdef HPUXCOMPAT
 
        case PT_WRITE_U:                /* write the child's u. */
 #ifdef HPUXCOMPAT
-               if (u.u_pcb.pcb_flags & PCB_HPUXTRACE)
+               if (p->p_addr->u_pcb.pcb_flags & PCB_HPUXTRACE)
                        i = hpuxtobsduoff(ipc.ip_addr);
                else
 #endif
                i = (int)ipc.ip_addr;
                        i = hpuxtobsduoff(ipc.ip_addr);
                else
 #endif
                i = (int)ipc.ip_addr;
-               poff = (int *)PHYSOFF(&u, i);
+               poff = (int *)PHYSOFF(kstack, i);
                for (i=0; i<NIPCREG; i++)
                        if (poff == &p->p_regs[ipcreg[i]])
                                goto ok;
                for (i=0; i<NIPCREG; i++)
                        if (poff == &p->p_regs[ipcreg[i]])
                                goto ok;
@@ -190,8 +192,8 @@ procxmt(p)
                }
 #if defined(hp300)
 #ifdef FPCOPROC
                }
 #if defined(hp300)
 #ifdef FPCOPROC
-               if (poff >= (int *)u.u_pcb.pcb_fpregs.fpf_regs &&
-                   poff <= (int *)&u.u_pcb.pcb_fpregs.fpf_fpiar)
+               if (poff >= (int *)&((struct user *)kstack)->u_pcb.pcb_fpregs.fpf_regs &&
+                   poff <= (int *)&((struct user *)kstack)->u_pcb.pcb_fpregs.fpf_fpiar)
                        goto ok;
 #endif
 #endif
                        goto ok;
 #endif
 #endif
@@ -224,3 +226,29 @@ procxmt(p)
        wakeup((caddr_t)&ipc);
        return (0);
 }
        wakeup((caddr_t)&ipc);
        return (0);
 }
+
+/*
+ * Process debugging system call.
+ */
+/* ARGSUSED */
+profil(p, uap, retval)
+       struct proc *p;
+       register struct args {
+               short   *bufbase;
+               unsigned bufsize;
+               unsigned pcoffset;
+               unsigned pcscale;
+       } *uap;
+       int *retval;
+{
+       register struct uprof *upp = &p->p_stats->p_prof;
+
+       upp->pr_base = uap->bufbase;
+       upp->pr_size = uap->bufsize;
+       upp->pr_off = uap->pcoffset;
+       upp->pr_scale = uap->pcscale;
+#ifdef PROFTIMER
+       initprofclock();
+#endif
+       return (0);
+}