1*8953Sroot /* sys_process.c 5.6 82/10/31 */ 27426Sroot 37426Sroot #include "../h/param.h" 47426Sroot #include "../h/systm.h" 57426Sroot #include "../h/dir.h" 67426Sroot #include "../h/user.h" 77426Sroot #include "../h/proc.h" 87426Sroot #include "../h/inode.h" 97426Sroot #include "../h/reg.h" 107426Sroot #include "../h/text.h" 117426Sroot #include "../h/seg.h" 127426Sroot #include "../h/pte.h" 137426Sroot #include "../h/psl.h" 147426Sroot #include "../h/vm.h" 157426Sroot #include "../h/buf.h" 167426Sroot #include "../h/acct.h" 177426Sroot 187501Sroot /* 197501Sroot * Priority for tracing 207501Sroot */ 217501Sroot #define IPCPRI PZERO 227501Sroot 237501Sroot /* 247501Sroot * Tracing variables. 257501Sroot * Used to pass trace command from 267501Sroot * parent to child being traced. 277501Sroot * This data base cannot be 287501Sroot * shared and is locked 297501Sroot * per user. 307501Sroot */ 317501Sroot struct { 327501Sroot int ip_lock; 337501Sroot int ip_req; 347501Sroot int *ip_addr; 357501Sroot int ip_data; 367501Sroot } ipc; 377501Sroot 387501Sroot /* 397501Sroot * sys-trace system call. 407501Sroot */ 417501Sroot ptrace() 427501Sroot { 437501Sroot register struct proc *p; 447501Sroot register struct a { 457501Sroot int req; 467501Sroot int pid; 477501Sroot int *addr; 487501Sroot int data; 497501Sroot } *uap; 507501Sroot 517501Sroot uap = (struct a *)u.u_ap; 527501Sroot if (uap->req <= 0) { 537501Sroot u.u_procp->p_flag |= STRC; 547501Sroot return; 557501Sroot } 567501Sroot p = pfind(uap->pid); 577501Sroot if (p == 0 || p->p_stat != SSTOP || p->p_ppid != u.u_procp->p_pid) { 587501Sroot u.u_error = ESRCH; 597501Sroot return; 607501Sroot } 617501Sroot while (ipc.ip_lock) 627501Sroot sleep((caddr_t)&ipc, IPCPRI); 637501Sroot ipc.ip_lock = p->p_pid; 647501Sroot ipc.ip_data = uap->data; 657501Sroot ipc.ip_addr = uap->addr; 667501Sroot ipc.ip_req = uap->req; 677501Sroot p->p_flag &= ~SWTED; 687501Sroot while (ipc.ip_req > 0) { 697501Sroot if (p->p_stat==SSTOP) 707501Sroot setrun(p); 717501Sroot sleep((caddr_t)&ipc, IPCPRI); 727501Sroot } 737501Sroot u.u_r.r_val1 = ipc.ip_data; 747501Sroot if (ipc.ip_req < 0) 757501Sroot u.u_error = EIO; 767501Sroot ipc.ip_lock = 0; 777501Sroot wakeup((caddr_t)&ipc); 787501Sroot } 797501Sroot 808952Sroot #if vax 818952Sroot #define NIPCREG 16 828952Sroot #endif 838952Sroot #if sun 848952Sroot #define NIPCREG 17 858952Sroot #endif 868952Sroot int ipcreg[NIPCREG] = 878952Sroot #if vax 888952Sroot {R0,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,AP,FP,SP,PC}; 898952Sroot #endif 908952Sroot #if sun 918952Sroot {R0,R1,R2,R3,R4,R5,R6,R7,AR0,AR1,AR2,AR3,AR4,AR5,AR6,AR7,PC}; 928952Sroot #endif 938952Sroot 94*8953Sroot #define PHYSOFF(p, o) \ 958952Sroot ((physadr)(p)+((o)/sizeof(((physadr)0)->r[0]))) 968952Sroot 977501Sroot /* 987501Sroot * Code that the child process 997501Sroot * executes to implement the command 1007501Sroot * of the parent process in tracing. 1017501Sroot */ 1027501Sroot procxmt() 1037501Sroot { 1047501Sroot register int i; 1057501Sroot register *p; 1067501Sroot register struct text *xp; 1077501Sroot 1087501Sroot if (ipc.ip_lock != u.u_procp->p_pid) 1097501Sroot return (0); 1107501Sroot u.u_procp->p_slptime = 0; 1117501Sroot i = ipc.ip_req; 1127501Sroot ipc.ip_req = 0; 1137501Sroot switch (i) { 1147501Sroot 1157501Sroot /* read user I */ 1167501Sroot case 1: 1177501Sroot if (!useracc((caddr_t)ipc.ip_addr, 4, B_READ)) 1187501Sroot goto error; 1197501Sroot ipc.ip_data = fuiword((caddr_t)ipc.ip_addr); 1207501Sroot break; 1217501Sroot 1227501Sroot /* read user D */ 1237501Sroot case 2: 1247501Sroot if (!useracc((caddr_t)ipc.ip_addr, 4, B_READ)) 1257501Sroot goto error; 1267501Sroot ipc.ip_data = fuword((caddr_t)ipc.ip_addr); 1277501Sroot break; 1287501Sroot 1297501Sroot /* read u */ 1307501Sroot case 3: 1317501Sroot i = (int)ipc.ip_addr; 1327501Sroot if (i<0 || i >= ctob(UPAGES)) 1337501Sroot goto error; 1348952Sroot ipc.ip_data = *(int *)PHYSOFF(&u, i); 1357501Sroot break; 1367501Sroot 1377501Sroot /* write user I */ 1387501Sroot /* Must set up to allow writing */ 1397501Sroot case 4: 1407501Sroot /* 1417501Sroot * If text, must assure exclusive use 1427501Sroot */ 1437501Sroot if (xp = u.u_procp->p_textp) { 1447501Sroot if (xp->x_count!=1 || xp->x_iptr->i_mode&ISVTX) 1457501Sroot goto error; 1467501Sroot xp->x_iptr->i_flag &= ~ITEXT; 1477501Sroot } 1487501Sroot i = -1; 1498952Sroot if ((i = suiword((caddr_t)ipc.ip_addr, ipc.ip_data)) < 0) { 1508952Sroot if (chgprot((caddr_t)ipc.ip_addr, RW) && 1518952Sroot chgprot((caddr_t)ipc.ip_addr+(sizeof(int)-1), RW)) 1528952Sroot i = suiword((caddr_t)ipc.ip_addr, ipc.ip_data); 1538952Sroot (void) chgprot((caddr_t)ipc.ip_addr, RO); 1548952Sroot (void) chgprot((caddr_t)ipc.ip_addr+(sizeof(int)-1), RO); 1558952Sroot } 1567501Sroot if (i < 0) 1577501Sroot goto error; 1587501Sroot if (xp) 1597501Sroot xp->x_flag |= XWRIT; 1607501Sroot break; 1617501Sroot 1627501Sroot /* write user D */ 1637501Sroot case 5: 1647501Sroot if (suword((caddr_t)ipc.ip_addr, 0) < 0) 1657501Sroot goto error; 1667501Sroot (void) suword((caddr_t)ipc.ip_addr, ipc.ip_data); 1677501Sroot break; 1687501Sroot 1697501Sroot /* write u */ 1707501Sroot case 6: 1717501Sroot i = (int)ipc.ip_addr; 1728952Sroot p = (int *)PHYSOFF(&u, i); 1738952Sroot for (i=0; i<NIPCREG; i++) 1747501Sroot if (p == &u.u_ar0[ipcreg[i]]) 1757501Sroot goto ok; 1767501Sroot if (p == &u.u_ar0[PS]) { 1778952Sroot ipc.ip_data |= PSL_USERSET; 1787501Sroot ipc.ip_data &= ~PSL_USERCLR; 1797501Sroot goto ok; 1807501Sroot } 1817501Sroot goto error; 1827501Sroot 1837501Sroot ok: 1847501Sroot *p = ipc.ip_data; 1857501Sroot break; 1867501Sroot 1877501Sroot /* set signal and continue */ 1887501Sroot /* one version causes a trace-trap */ 1897501Sroot case 9: 1907501Sroot case 7: 1917501Sroot if ((int)ipc.ip_addr != 1) 1927501Sroot u.u_ar0[PC] = (int)ipc.ip_addr; 1937501Sroot if ((unsigned)ipc.ip_data > NSIG) 1947501Sroot goto error; 1957501Sroot u.u_procp->p_cursig = ipc.ip_data; /* see issig */ 1967501Sroot if (i == 9) 1977501Sroot u.u_ar0[PS] |= PSL_T; 1987501Sroot wakeup((caddr_t)&ipc); 1997501Sroot return (1); 2007501Sroot 2017501Sroot /* force exit */ 2027501Sroot case 8: 2037501Sroot wakeup((caddr_t)&ipc); 2047501Sroot exit(u.u_procp->p_cursig); 2057501Sroot 2067501Sroot default: 2077501Sroot error: 2087501Sroot ipc.ip_req = -1; 2097501Sroot } 2107501Sroot wakeup((caddr_t)&ipc); 2117501Sroot return (0); 2127501Sroot } 213