Lines Matching refs:P
90 Pread_live(struct ps_prochandle *P, void *buf, size_t n, uintptr_t addr, in Pread_live() argument
93 return (pread(P->asfd, buf, n, (off_t)addr)); in Pread_live()
97 Pwrite_live(struct ps_prochandle *P, const void *buf, size_t n, uintptr_t addr, in Pwrite_live() argument
100 return (pwrite(P->asfd, buf, n, (off_t)addr)); in Pwrite_live()
104 Pread_maps_live(struct ps_prochandle *P, prmap_t **Pmapp, ssize_t *nmapp, in Pread_maps_live() argument
114 procfs_path, (int)P->pid); in Pread_maps_live()
125 Preset_maps(P); /* utter failure; destroy tables */ in Pread_maps_live()
137 Pread_aux_live(struct ps_prochandle *P, auxv_t **auxvp, int *nauxp, void *data) in Pread_aux_live() argument
146 procfs_path, (int)P->pid); in Pread_aux_live()
174 Pcred_live(struct ps_prochandle *P, prcred_t *pcrp, int ngroups, void *data) in Pcred_live() argument
176 return (proc_get_cred(P->pid, pcrp, ngroups)); in Pcred_live()
180 Psecflags_live(struct ps_prochandle *P, prsecflags_t **psf, void *data) in Psecflags_live() argument
182 return (proc_get_secflags(P->pid, psf)); in Psecflags_live()
186 Ppriv_live(struct ps_prochandle *P, prpriv_t **pprv, void *data) in Ppriv_live() argument
190 pp = proc_get_priv(P->pid); in Ppriv_live()
200 Ppsinfo_live(struct ps_prochandle *P, psinfo_t *psinfo, void *data) in Ppsinfo_live() argument
202 if (proc_get_psinfo(P->pid, psinfo) == -1) in Ppsinfo_live()
209 Plstatus_live(struct ps_prochandle *P, void *data) in Plstatus_live() argument
211 return (read_lfile(P, "lstatus")); in Plstatus_live()
215 Plpsinfo_live(struct ps_prochandle *P, void *data) in Plpsinfo_live() argument
217 return (read_lfile(P, "lpsinfo")); in Plpsinfo_live()
221 Pplatform_live(struct ps_prochandle *P, char *s, size_t n, void *data) in Pplatform_live() argument
229 Puname_live(struct ps_prochandle *P, struct utsname *u, void *data) in Puname_live() argument
235 Pzonename_live(struct ps_prochandle *P, char *s, size_t n, void *data) in Pzonename_live() argument
237 if (getzonenamebyid(P->status.pr_zoneid, s, n) < 0) in Pzonename_live()
259 Pexecname_live(struct ps_prochandle *P, char *buf, size_t buflen, void *data) in Pexecname_live() argument
270 "%s/%d/path/a.out", procfs_path, (int)P->pid); in Pexecname_live()
273 (void) Pfindobj(P, buf, buf, buflen); in Pexecname_live()
282 "%s/%d/object/a.out", procfs_path, (int)P->pid); in Pexecname_live()
292 if (proc_get_cwd(P->pid, cwd, sizeof (cwd)) > 0) in Pexecname_live()
295 (void) Pfindexec(P, cwdp, stat_exec, &st); in Pexecname_live()
306 Pcwd_live(struct ps_prochandle *P, prcwd_t **cwdp, void *data) in Pcwd_live() argument
318 if (proc_get_cwd(P->pid, cwd->prcwd_cwd, sizeof (cwd->prcwd_cwd)) < 0) in Pcwd_live()
374 Pldt_live(struct ps_prochandle *P, struct ssd *pldt, int nldt, void *data) in Pldt_live() argument
376 return (proc_get_ldt(P->pid, pldt, nldt)); in Pldt_live()
496 struct ps_prochandle *P; in Pxcreate() local
508 if ((P = malloc(sizeof (struct ps_prochandle))) == NULL) { in Pxcreate()
514 free(P); in Pxcreate()
531 Pcreate_callback(P); /* execute callback (see below) */ in Pxcreate()
549 (void) memset(P, 0, sizeof (*P)); in Pxcreate()
550 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL); in Pxcreate()
551 P->flags |= CREATED; in Pxcreate()
552 P->state = PS_RUN; in Pxcreate()
553 P->pid = pid; in Pxcreate()
554 P->asfd = -1; in Pxcreate()
555 P->ctlfd = -1; in Pxcreate()
556 P->statfd = -1; in Pxcreate()
557 P->agentctlfd = -1; in Pxcreate()
558 P->agentstatfd = -1; in Pxcreate()
559 Pinit_ops(&P->ops, &P_live_ops); in Pxcreate()
560 Pinitsym(P); in Pxcreate()
561 Pinitfd(P); in Pxcreate()
583 P->asfd = fd; in Pxcreate()
593 P->statfd = fd; in Pxcreate()
603 P->ctlfd = fd; in Pxcreate()
605 (void) Pstop(P, 0); /* stop the controlled process */ in Pxcreate()
615 (void) Psysentry(P, SYS_pause, 1); in Pxcreate()
616 (void) Psysexit(P, SYS_pause, 1); in Pxcreate()
618 if (P->state == PS_STOP && in Pxcreate()
619 P->status.pr_lwp.pr_syscall == SYS_pause && in Pxcreate()
620 (P->status.pr_lwp.pr_why == PR_REQUESTED || in Pxcreate()
621 P->status.pr_lwp.pr_why == PR_SYSENTRY || in Pxcreate()
622 P->status.pr_lwp.pr_why == PR_SYSEXIT)) in Pxcreate()
625 if (P->state != PS_STOP || /* interrupt or process died */ in Pxcreate()
626 Psetrun(P, 0, 0) != 0) { /* can't restart */ in Pxcreate()
637 (void) Pwait(P, 0); in Pxcreate()
639 (void) Psysentry(P, SYS_pause, 0); in Pxcreate()
640 (void) Psysexit(P, SYS_pause, 0); in Pxcreate()
646 (void) Psysentry(P, SYS_exit, 1); in Pxcreate()
647 (void) Psysentry(P, SYS_execve, 1); in Pxcreate()
648 if (Psetrun(P, 0, PRSABORT) == -1) { in Pxcreate()
653 (void) Pwait(P, 0); in Pxcreate()
654 if (P->state != PS_STOP) { in Pxcreate()
664 (void) Psysexit(P, SYS_execve, TRUE); in Pxcreate()
666 while (P->state == PS_STOP && in Pxcreate()
667 P->status.pr_lwp.pr_why == PR_SYSENTRY && in Pxcreate()
668 P->status.pr_lwp.pr_what == SYS_execve) { in Pxcreate()
674 (void) Pread_string(P, execpath, sizeof (execpath), in Pxcreate()
675 (off_t)P->status.pr_lwp.pr_sysarg[0]); in Pxcreate()
682 (void) Psetrun(P, 0, 0); in Pxcreate()
683 (void) Pwait(P, 0); in Pxcreate()
685 if (P->state == PS_LOST && /* we lost control */ in Pxcreate()
686 Preopen(P) != 0) { /* and we can't get it back */ in Pxcreate()
695 if (P->state == PS_STOP && in Pxcreate()
696 P->status.pr_lwp.pr_why == PR_SYSEXIT && in Pxcreate()
697 P->status.pr_lwp.pr_what == SYS_execve && in Pxcreate()
698 (lasterrno = P->status.pr_lwp.pr_errno) != 0) { in Pxcreate()
703 (void) Psetrun(P, 0, 0); in Pxcreate()
704 (void) Pwait(P, 0); in Pxcreate()
711 if (P->state == PS_STOP && in Pxcreate()
712 P->status.pr_lwp.pr_why == PR_SYSEXIT && in Pxcreate()
713 P->status.pr_lwp.pr_what == SYS_execve && in Pxcreate()
714 P->status.pr_lwp.pr_errno == 0) { in Pxcreate()
719 restore_tracing_flags(P); in Pxcreate()
722 if (P->status.pr_dmodel == PR_MODEL_LP64) { in Pxcreate()
731 (void) Psetflags(P, PR_RLC); in Pxcreate()
733 return (P); in Pxcreate()
742 Pfree(P); in Pxcreate()
805 Pcreate_callback(struct ps_prochandle *P) in Pcreate_callback() argument
826 struct ps_prochandle *P; in Pgrab() local
839 if ((P = malloc(sizeof (struct ps_prochandle))) == NULL) { in Pgrab()
844 P->asfd = -1; in Pgrab()
845 P->ctlfd = -1; in Pgrab()
846 P->statfd = -1; in Pgrab()
849 if (P->ctlfd >= 0) in Pgrab()
850 (void) close(P->ctlfd); in Pgrab()
851 if (P->asfd >= 0) in Pgrab()
852 (void) close(P->asfd); in Pgrab()
853 if (P->statfd >= 0) in Pgrab()
854 (void) close(P->statfd); in Pgrab()
855 (void) memset(P, 0, sizeof (*P)); in Pgrab()
856 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL); in Pgrab()
857 P->ctlfd = -1; in Pgrab()
858 P->asfd = -1; in Pgrab()
859 P->statfd = -1; in Pgrab()
860 P->agentctlfd = -1; in Pgrab()
861 P->agentstatfd = -1; in Pgrab()
862 Pinit_ops(&P->ops, &P_live_ops); in Pgrab()
863 Pinitsym(P); in Pgrab()
864 Pinitfd(P); in Pgrab()
911 P->asfd = fd; in Pgrab()
931 P->statfd = fd; in Pgrab()
952 P->ctlfd = fd; in Pgrab()
955 P->state = PS_RUN; in Pgrab()
956 P->pid = pid; in Pgrab()
968 if (Pstopstatus(P, PCNULL, 0) != 0) { in Pgrab()
975 if (P->state == PS_LOST) { /* WoV */ in Pgrab()
976 (void) mutex_destroy(&P->proc_lock); in Pgrab()
980 if (P->state == PS_UNDEAD) in Pgrab()
991 if (P->status.pr_flags & PR_ISSYS) { in Pgrab()
999 if (P->status.pr_dmodel == PR_MODEL_LP64) { in Pgrab()
1008 P->orig_status = P->status; /* structure copy */ in Pgrab()
1025 if (Pread(P, &magic2, sizeof (magic2), (uintptr_t)&magic1) in Pgrab()
1029 Pread(P, &magic2, sizeof (magic2), (uintptr_t)&magic1) in Pgrab()
1042 if (!(P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) && in Pgrab()
1048 if (Psetflags(P, PR_RLC) != 0) { in Pgrab()
1050 (void) mutex_destroy(&P->proc_lock); in Pgrab()
1075 while ((P->status.pr_lwp.pr_flags & (PR_STOPPED|PR_DSTOP)) == in Pgrab()
1077 Pstopstatus(P, PCTWSTOP, 20) != 0) { in Pgrab()
1084 P->status.pr_lwp.pr_flags &= ~PR_DSTOP; in Pgrab()
1092 if (!(P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) && in Pgrab()
1097 if (((P->status.pr_lwp.pr_flags & PR_STOPPED) && in Pgrab()
1098 Pstopstatus(P, PCDSTOP, 0) != 0) || in Pgrab()
1099 Pstopstatus(P, PCSTOP, 2000) != 0) { in Pgrab()
1106 if (P->state == PS_LOST) { /* WoV */ in Pgrab()
1107 (void) mutex_destroy(&P->proc_lock); in Pgrab()
1111 (P->state != PS_STOP && in Pgrab()
1112 !(P->status.pr_flags & PR_DSTOP))) { in Pgrab()
1113 if (P->state != PS_RUN && errno != ENOENT) { in Pgrab()
1127 if (!(P->status.pr_flags & (PR_ISTOP|PR_DSTOP))) { in Pgrab()
1137 if (P->status.pr_dmodel == PR_MODEL_LP64) { in Pgrab()
1148 (void) Psysentry(P, 0, FALSE); in Pgrab()
1149 (void) Psysexit(P, 0, FALSE); in Pgrab()
1150 (void) Psignal(P, 0, FALSE); in Pgrab()
1151 (void) Pfault(P, 0, FALSE); in Pgrab()
1152 Psync(P); in Pgrab()
1156 return (P); in Pgrab()
1159 Pfree(P); in Pgrab()
1240 Pfree(struct ps_prochandle *P) in Pfree() argument
1245 if (P->ucaddrs != NULL) { in Pfree()
1246 free(P->ucaddrs); in Pfree()
1247 P->ucaddrs = NULL; in Pfree()
1248 P->ucnelems = 0; in Pfree()
1251 (void) mutex_lock(&P->proc_lock); in Pfree()
1252 if (P->hashtab != NULL) { in Pfree()
1255 while ((L = P->hashtab[i]) != NULL) in Pfree()
1256 Lfree_internal(P, L); in Pfree()
1258 free(P->hashtab); in Pfree()
1261 while ((fip = list_remove_head(&P->fd_head)) != NULL) { in Pfree()
1265 (void) mutex_unlock(&P->proc_lock); in Pfree()
1266 (void) mutex_destroy(&P->proc_lock); in Pfree()
1268 free(P->zoneroot); in Pfree()
1270 if (P->agentctlfd >= 0) in Pfree()
1271 (void) close(P->agentctlfd); in Pfree()
1272 if (P->agentstatfd >= 0) in Pfree()
1273 (void) close(P->agentstatfd); in Pfree()
1274 if (P->ctlfd >= 0) in Pfree()
1275 (void) close(P->ctlfd); in Pfree()
1276 if (P->asfd >= 0) in Pfree()
1277 (void) close(P->asfd); in Pfree()
1278 if (P->statfd >= 0) in Pfree()
1279 (void) close(P->statfd); in Pfree()
1280 Preset_maps(P); in Pfree()
1281 P->ops.pop_fini(P, P->data); in Pfree()
1284 (void) memset(P, 0, sizeof (*P)); in Pfree()
1285 P->ctlfd = -1; in Pfree()
1286 P->asfd = -1; in Pfree()
1287 P->statfd = -1; in Pfree()
1288 P->agentctlfd = -1; in Pfree()
1289 P->agentstatfd = -1; in Pfree()
1291 free(P); in Pfree()
1298 Pstate(struct ps_prochandle *P) in Pstate() argument
1300 return (P->state); in Pstate()
1309 Pasfd(struct ps_prochandle *P) in Pasfd() argument
1311 return (P->asfd); in Pasfd()
1320 Pctlfd(struct ps_prochandle *P) in Pctlfd() argument
1322 return (P->ctlfd); in Pctlfd()
1331 Ppsinfo(struct ps_prochandle *P) in Ppsinfo() argument
1333 return (P->ops.pop_psinfo(P, &P->psinfo, P->data)); in Ppsinfo()
1342 Pstatus(struct ps_prochandle *P) in Pstatus() argument
1344 return (&P->status); in Pstatus()
1348 Pread_status(struct ps_prochandle *P) in Pread_status() argument
1350 P->ops.pop_status(P, &P->status, P->data); in Pread_status()
1360 Pcred(struct ps_prochandle *P, prcred_t *pcrp, int ngroups) in Pcred() argument
1362 return (P->ops.pop_cred(P, pcrp, ngroups, P->data)); in Pcred()
1367 Psecflags(struct ps_prochandle *P, prsecflags_t **psf) in Psecflags() argument
1371 if ((ret = P->ops.pop_secflags(P, psf, P->data)) == 0) { in Psecflags()
1390 Pcwd(struct ps_prochandle *P, prcwd_t **cwd) in Pcwd() argument
1392 return (P->ops.pop_cwd(P, cwd, P->data)); in Pcwd()
1402 Plstatus(struct ps_prochandle *P) in Plstatus() argument
1404 return (P->ops.pop_lstatus(P, P->data)); in Plstatus()
1408 Plpsinfo(struct ps_prochandle *P) in Plpsinfo() argument
1410 return (P->ops.pop_lpsinfo(P, P->data)); in Plpsinfo()
1422 Pldt(struct ps_prochandle *P, struct ssd *pldt, int nldt) in Pldt() argument
1424 return (P->ops.pop_ldt(P, pldt, nldt, P->data)); in Pldt()
1430 Ppriv_free(struct ps_prochandle *P, prpriv_t *prv) in Ppriv_free() argument
1439 Ppriv(struct ps_prochandle *P, prpriv_t **pprv) in Ppriv() argument
1441 return (P->ops.pop_priv(P, pprv, P->data)); in Ppriv()
1445 Psetpriv(struct ps_prochandle *P, prpriv_t *pprv) in Psetpriv() argument
1451 if (P->state == PS_DEAD) { in Psetpriv()
1468 if (write(P->ctlfd, ctl, sz) != sz) in Psetpriv()
1479 Pprivinfo(struct ps_prochandle *P) in Pprivinfo() argument
1481 core_info_t *core = P->data; in Pprivinfo()
1484 if (P->state != PS_DEAD) in Pprivinfo()
1496 Psync(struct ps_prochandle *P) in Psync() argument
1498 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Psync()
1503 if (P->flags & SETHOLD) { in Psync()
1507 iov[n].iov_base = (caddr_t)&P->status.pr_lwp.pr_lwphold; in Psync()
1508 iov[n++].iov_len = sizeof (P->status.pr_lwp.pr_lwphold); in Psync()
1510 if (P->flags & SETREGS) { in Psync()
1514 if (ctlfd == P->agentctlfd) in Psync()
1515 P->status.pr_lwp.pr_reg[GS] = 0; in Psync()
1521 iov[n].iov_base = (caddr_t)&P->status.pr_lwp.pr_reg[0]; in Psync()
1522 iov[n++].iov_len = sizeof (P->status.pr_lwp.pr_reg); in Psync()
1524 if (P->flags & SETSIG) { in Psync()
1528 iov[n].iov_base = (caddr_t)&P->status.pr_sigtrace; in Psync()
1529 iov[n++].iov_len = sizeof (P->status.pr_sigtrace); in Psync()
1531 if (P->flags & SETFAULT) { in Psync()
1535 iov[n].iov_base = (caddr_t)&P->status.pr_flttrace; in Psync()
1536 iov[n++].iov_len = sizeof (P->status.pr_flttrace); in Psync()
1538 if (P->flags & SETENTRY) { in Psync()
1542 iov[n].iov_base = (caddr_t)&P->status.pr_sysentry; in Psync()
1543 iov[n++].iov_len = sizeof (P->status.pr_sysentry); in Psync()
1545 if (P->flags & SETEXIT) { in Psync()
1549 iov[n].iov_base = (caddr_t)&P->status.pr_sysexit; in Psync()
1550 iov[n++].iov_len = sizeof (P->status.pr_sysexit); in Psync()
1556 P->flags &= ~(SETSIG|SETFAULT|SETENTRY|SETEXIT|SETHOLD|SETREGS); in Psync()
1563 Preopen(struct ps_prochandle *P) in Preopen() argument
1569 if (P->state == PS_DEAD || P->state == PS_IDLE) in Preopen()
1572 if (P->agentcnt > 0) { in Preopen()
1573 P->agentcnt = 1; in Preopen()
1574 Pdestroy_agent(P); in Preopen()
1578 procfs_path, (int)P->pid); in Preopen()
1583 close(P->asfd) < 0 || in Preopen()
1584 (fd = dupfd(fd, P->asfd)) != P->asfd) { in Preopen()
1591 P->asfd = fd; in Preopen()
1595 close(P->statfd) < 0 || in Preopen()
1596 (fd = dupfd(fd, P->statfd)) != P->statfd) { in Preopen()
1603 P->statfd = fd; in Preopen()
1607 close(P->ctlfd) < 0 || in Preopen()
1608 (fd = dupfd(fd, P->ctlfd)) != P->ctlfd) { in Preopen()
1615 P->ctlfd = fd; in Preopen()
1624 P->state = PS_RUN; in Preopen()
1625 if (Pwait(P, 0) == -1) { in Preopen()
1628 P->status.pr_dmodel = PR_MODEL_LP64; in Preopen()
1630 P->status.pr_lwp.pr_why = PR_SYSEXIT; in Preopen()
1631 P->status.pr_lwp.pr_what = SYS_execve; in Preopen()
1632 P->status.pr_lwp.pr_errno = 0; in Preopen()
1640 if (P->state == PS_STOP && in Preopen()
1641 (P->status.pr_lwp.pr_why == PR_REQUESTED || in Preopen()
1642 (P->status.pr_lwp.pr_why == PR_SYSEXIT && in Preopen()
1643 P->status.pr_lwp.pr_what == SYS_execve))) { in Preopen()
1645 if (P->status.pr_lwp.pr_why == PR_REQUESTED) { in Preopen()
1646 P->status.pr_lwp.pr_why = PR_SYSEXIT; in Preopen()
1647 P->status.pr_lwp.pr_what = SYS_execve; in Preopen()
1648 P->status.pr_lwp.pr_errno = 0; in Preopen()
1669 restore_tracing_flags(struct ps_prochandle *P) in restore_tracing_flags() argument
1675 if (P->flags & CREATED) { in restore_tracing_flags()
1677 premptyset(&P->status.pr_sigtrace); in restore_tracing_flags()
1678 premptyset(&P->status.pr_flttrace); in restore_tracing_flags()
1679 premptyset(&P->status.pr_sysentry); in restore_tracing_flags()
1680 premptyset(&P->status.pr_sysexit); in restore_tracing_flags()
1681 if ((P->status.pr_flags & ALL_SETTABLE_FLAGS) != 0) in restore_tracing_flags()
1682 (void) Punsetflags(P, ALL_SETTABLE_FLAGS); in restore_tracing_flags()
1685 P->status.pr_sigtrace = P->orig_status.pr_sigtrace; in restore_tracing_flags()
1686 P->status.pr_flttrace = P->orig_status.pr_flttrace; in restore_tracing_flags()
1687 P->status.pr_sysentry = P->orig_status.pr_sysentry; in restore_tracing_flags()
1688 P->status.pr_sysexit = P->orig_status.pr_sysexit; in restore_tracing_flags()
1689 if ((P->status.pr_flags & ALL_SETTABLE_FLAGS) != in restore_tracing_flags()
1690 (flags = (P->orig_status.pr_flags & ALL_SETTABLE_FLAGS))) { in restore_tracing_flags()
1691 (void) Punsetflags(P, ALL_SETTABLE_FLAGS); in restore_tracing_flags()
1693 (void) Psetflags(P, flags); in restore_tracing_flags()
1700 iov[1].iov_base = (caddr_t)&P->status.pr_sigtrace; in restore_tracing_flags()
1701 iov[1].iov_len = sizeof (P->status.pr_sigtrace); in restore_tracing_flags()
1706 iov[3].iov_base = (caddr_t)&P->status.pr_flttrace; in restore_tracing_flags()
1707 iov[3].iov_len = sizeof (P->status.pr_flttrace); in restore_tracing_flags()
1712 iov[5].iov_base = (caddr_t)&P->status.pr_sysentry; in restore_tracing_flags()
1713 iov[5].iov_len = sizeof (P->status.pr_sysentry); in restore_tracing_flags()
1718 iov[7].iov_base = (caddr_t)&P->status.pr_sysexit; in restore_tracing_flags()
1719 iov[7].iov_len = sizeof (P->status.pr_sysexit); in restore_tracing_flags()
1721 (void) writev(P->ctlfd, iov, 8); in restore_tracing_flags()
1723 P->flags &= ~(SETSIG|SETFAULT|SETENTRY|SETEXIT); in restore_tracing_flags()
1735 Prelease(struct ps_prochandle *P, int flags) in Prelease() argument
1737 if (P->state == PS_DEAD) { in Prelease()
1739 (void *)P, (int)P->pid); in Prelease()
1740 Pfree(P); in Prelease()
1744 if (P->state == PS_IDLE) { in Prelease()
1745 file_info_t *fptr = list_head(&P->file_head); in Prelease()
1747 (void *)P, fptr->file_pname); in Prelease()
1748 Pfree(P); in Prelease()
1753 (void *)P, (int)P->pid); in Prelease()
1755 if (P->ctlfd == -1) { in Prelease()
1756 Pfree(P); in Prelease()
1760 if (P->agentcnt > 0) { in Prelease()
1761 P->agentcnt = 1; in Prelease()
1762 Pdestroy_agent(P); in Prelease()
1768 P->state = PS_RUN; in Prelease()
1769 (void) Pstop(P, 1000); in Prelease()
1772 if (P->state == PS_STOP) in Prelease()
1773 (void) Psetrun(P, SIGKILL, 0); in Prelease()
1774 (void) kill(P->pid, SIGKILL); in Prelease()
1775 Pfree(P); in Prelease()
1783 if (P->state != PS_STOP && in Prelease()
1784 (P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) == 0) { in Prelease()
1785 Pfree(P); in Prelease()
1792 Psync(P); in Prelease()
1795 P->flags |= CREATED; in Prelease()
1798 restore_tracing_flags(P); in Prelease()
1802 (void) Punsetflags(P, PR_RLC|PR_KLC); in Prelease()
1803 Pfree(P); in Prelease()
1812 if ((P->flags & CREATED) || in Prelease()
1813 (P->orig_status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) == 0) { in Prelease()
1814 (void) Psetflags(P, PR_RLC); in Prelease()
1821 if (Psetrun(P, 0, 0) == -1 && errno == EBUSY) in Prelease()
1823 } while (Pstopstatus(P, PCNULL, 0) == 0 && in Prelease()
1824 P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)); in Prelease()
1826 if (P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) in Prelease()
1830 Pfree(P); in Prelease()
1882 prdump(struct ps_prochandle *P) in prdump() argument
1886 prldump("Pstopstatus", &P->status.pr_lwp); in prdump()
1888 bits = *((uint32_t *)&P->status.pr_sigpend); in prdump()
1901 Pstopstatus(struct ps_prochandle *P, in Pstopstatus() argument
1905 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pstopstatus()
1909 int old_state = P->state; in Pstopstatus()
1911 switch (P->state) { in Pstopstatus()
1933 dprintf("Pstopstatus: corrupted state: %d\n", P->state); in Pstopstatus()
1953 if (P->state == PS_DEAD || P->state == PS_IDLE) in Pstopstatus()
1961 Psync(P); in Pstopstatus()
1963 if (P->agentstatfd < 0) { in Pstopstatus()
1964 if (pread(P->statfd, &P->status, in Pstopstatus()
1965 sizeof (P->status), (off_t)0) < 0) in Pstopstatus()
1968 if (pread(P->agentstatfd, &P->status.pr_lwp, in Pstopstatus()
1969 sizeof (P->status.pr_lwp), (off_t)0) < 0) in Pstopstatus()
1971 P->status.pr_flags = P->status.pr_lwp.pr_flags; in Pstopstatus()
1983 P->state = PS_LOST; in Pstopstatus()
2003 deadcheck(P); in Pstopstatus()
2012 if (!(P->status.pr_flags & PR_STOPPED)) { in Pstopstatus()
2013 P->state = PS_RUN; in Pstopstatus()
2021 P->state = PS_STOP; in Pstopstatus()
2024 prdump(P); in Pstopstatus()
2034 switch (P->status.pr_lwp.pr_why) { in Pstopstatus()
2037 if (Pissyscall_prev(P, P->status.pr_lwp.pr_reg[R_PC], in Pstopstatus()
2038 &P->sysaddr) == 0) in Pstopstatus()
2039 P->sysaddr = P->status.pr_lwp.pr_reg[R_PC]; in Pstopstatus()
2059 Pwait(struct ps_prochandle *P, uint_t msec) in Pwait() argument
2061 return (Pstopstatus(P, PCWSTOP, msec)); in Pwait()
2068 Pstop(struct ps_prochandle *P, uint_t msec) in Pstop() argument
2070 return (Pstopstatus(P, PCSTOP, msec)); in Pstop()
2077 Pdstop(struct ps_prochandle *P) in Pdstop() argument
2079 return (Pstopstatus(P, PCDSTOP, 0)); in Pdstop()
2083 deadcheck(struct ps_prochandle *P) in deadcheck() argument
2089 if (P->statfd < 0) in deadcheck()
2090 P->state = PS_UNDEAD; in deadcheck()
2092 if (P->agentstatfd < 0) { in deadcheck()
2093 fd = P->statfd; in deadcheck()
2094 buf = &P->status; in deadcheck()
2095 size = sizeof (P->status); in deadcheck()
2097 fd = P->agentstatfd; in deadcheck()
2098 buf = &P->status.pr_lwp; in deadcheck()
2099 size = sizeof (P->status.pr_lwp); in deadcheck()
2104 P->state = PS_UNDEAD; in deadcheck()
2110 P->state = PS_LOST; in deadcheck()
2115 P->status.pr_flags = P->status.pr_lwp.pr_flags; in deadcheck()
2123 Pgetareg(struct ps_prochandle *P, int regno, prgreg_t *preg) in Pgetareg() argument
2130 if (P->state == PS_IDLE) { in Pgetareg()
2135 if (P->state != PS_STOP && P->state != PS_DEAD) { in Pgetareg()
2140 *preg = P->status.pr_lwp.pr_reg[regno]; in Pgetareg()
2148 Pputareg(struct ps_prochandle *P, int regno, prgreg_t reg) in Pputareg() argument
2155 if (P->state != PS_STOP) { in Pputareg()
2160 P->status.pr_lwp.pr_reg[regno] = reg; in Pputareg()
2161 P->flags |= SETREGS; /* set registers before continuing */ in Pputareg()
2166 Psetrun(struct ps_prochandle *P, in Psetrun() argument
2170 int ctlfd = (P->agentctlfd >= 0) ? P->agentctlfd : P->ctlfd; in Psetrun()
2180 if (P->state != PS_STOP && (P->status.pr_lwp.pr_flags & sbits) == 0) { in Psetrun()
2185 Psync(P); /* flush tracing flags and registers */ in Psetrun()
2195 } else if (sig && sig != P->status.pr_lwp.pr_cursig) { in Psetrun()
2210 P->info_valid = 0; /* will need to update map and file info */ in Psetrun()
2216 if (P->ucaddrs != NULL) { in Psetrun()
2217 free(P->ucaddrs); in Psetrun()
2218 P->ucaddrs = NULL; in Psetrun()
2219 P->ucnelems = 0; in Psetrun()
2225 (void) Pstopstatus(P, PCNULL, 0); in Psetrun()
2230 P->status.pr_lwp.pr_why != PR_JOBCONTROL) { in Psetrun()
2237 P->state = PS_RUN; in Psetrun()
2242 Pread(struct ps_prochandle *P, in Pread() argument
2247 return (P->ops.pop_pread(P, buf, nbyte, address, P->data)); in Pread()
2251 Pread_string(struct ps_prochandle *P, in Pread_string() argument
2272 if ((nbyte = P->ops.pop_pread(P, string, STRSZ, addr, in Pread_string()
2273 P->data)) <= 0) { in Pread_string()
2289 Pwrite(struct ps_prochandle *P, in Pwrite() argument
2294 return (P->ops.pop_pwrite(P, buf, nbyte, address, P->data)); in Pwrite()
2298 Pclearsig(struct ps_prochandle *P) in Pclearsig() argument
2300 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pclearsig()
2305 P->status.pr_lwp.pr_cursig = 0; in Pclearsig()
2310 Pclearfault(struct ps_prochandle *P) in Pclearfault() argument
2312 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pclearfault()
2324 Psetbkpt(struct ps_prochandle *P, uintptr_t address, ulong_t *saved) in Psetbkpt() argument
2334 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetbkpt()
2335 P->state == PS_IDLE) { in Psetbkpt()
2357 if (write(P->ctlfd, ctl, size) != size) in Psetbkpt()
2377 Pdelbkpt(struct ps_prochandle *P, uintptr_t address, ulong_t saved) in Pdelbkpt() argument
2382 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Pdelbkpt()
2383 P->state == PS_IDLE) { in Pdelbkpt()
2395 if (Pread(P, &cur, sizeof (cur), address) == sizeof (cur) && in Pdelbkpt()
2399 if (Pwrite(P, &old, sizeof (old), address) != sizeof (old)) in Pdelbkpt()
2509 Pxecbkpt(struct ps_prochandle *P, ulong_t saved) in Pxecbkpt() argument
2511 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pxecbkpt()
2514 if (P->state != PS_STOP) { in Pxecbkpt()
2519 Psync(P); in Pxecbkpt()
2522 &P->status.pr_flttrace, &P->status.pr_lwp.pr_lwphold, in Pxecbkpt()
2523 P->status.pr_lwp.pr_reg[R_PC], saved); in Pxecbkpt()
2524 rv = Pstopstatus(P, PCNULL, 0); in Pxecbkpt()
2527 if (P->status.pr_lwp.pr_why == PR_JOBCONTROL && in Pxecbkpt()
2529 P->state = PS_RUN; in Pxecbkpt()
2545 Psetwapt(struct ps_prochandle *P, const prwatch_t *wp) in Psetwapt() argument
2550 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetwapt()
2551 P->state == PS_IDLE) { in Psetwapt()
2561 if (write(P->ctlfd, ctl, sizeof (ctl)) != sizeof (ctl)) in Psetwapt()
2571 Pdelwapt(struct ps_prochandle *P, const prwatch_t *wp) in Pdelwapt() argument
2576 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Pdelwapt()
2577 P->state == PS_IDLE) { in Pdelwapt()
2587 if (write(P->ctlfd, ctl, sizeof (ctl)) != sizeof (ctl)) in Pdelwapt()
2704 Pxecwapt(struct ps_prochandle *P, const prwatch_t *wp) in Pxecwapt() argument
2706 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pxecwapt()
2709 if (P->state != PS_STOP) { in Pxecwapt()
2714 Psync(P); in Pxecwapt()
2716 &P->status.pr_flttrace, &P->status.pr_lwp.pr_lwphold, wp); in Pxecwapt()
2717 rv = Pstopstatus(P, PCNULL, 0); in Pxecwapt()
2720 if (P->status.pr_lwp.pr_why == PR_JOBCONTROL && in Pxecwapt()
2722 P->state = PS_RUN; in Pxecwapt()
2735 Psetflags(struct ps_prochandle *P, long flags) in Psetflags() argument
2743 if (write(P->ctlfd, ctl, 2*sizeof (long)) != 2*sizeof (long)) { in Psetflags()
2746 P->status.pr_flags |= flags; in Psetflags()
2747 P->status.pr_lwp.pr_flags |= flags; in Psetflags()
2755 Punsetflags(struct ps_prochandle *P, long flags) in Punsetflags() argument
2763 if (write(P->ctlfd, ctl, 2*sizeof (long)) != 2*sizeof (long)) { in Punsetflags()
2766 P->status.pr_flags &= ~flags; in Punsetflags()
2767 P->status.pr_lwp.pr_flags &= ~flags; in Punsetflags()
2785 Psetaction(struct ps_prochandle *P, void *sp, size_t size, in Psetaction() argument
2795 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetaction()
2796 P->state == PS_IDLE) { in Psetaction()
2806 P->flags |= flag; in Psetaction()
2809 P->flags |= flag; in Psetaction()
2814 P->flags |= flag; in Psetaction()
2817 P->flags |= flag; in Psetaction()
2821 if (P->state == PS_RUN) in Psetaction()
2822 Psync(P); in Psetaction()
2831 Psignal(struct ps_prochandle *P, int which, int stop) in Psignal() argument
2840 oldval = Psetaction(P, &P->status.pr_sigtrace, sizeof (sigset_t), in Psignal()
2844 prdelset(&P->status.pr_sigtrace, SIGKILL); in Psignal()
2853 Psetsignal(struct ps_prochandle *P, const sigset_t *set) in Psetsignal() argument
2855 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetsignal()
2856 P->state == PS_IDLE) in Psetsignal()
2859 P->status.pr_sigtrace = *set; in Psetsignal()
2860 P->flags |= SETSIG; in Psetsignal()
2862 if (P->state == PS_RUN) in Psetsignal()
2863 Psync(P); in Psetsignal()
2870 Pfault(struct ps_prochandle *P, int which, int stop) in Pfault() argument
2872 return (Psetaction(P, &P->status.pr_flttrace, sizeof (fltset_t), in Pfault()
2880 Psetfault(struct ps_prochandle *P, const fltset_t *set) in Psetfault() argument
2882 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetfault()
2883 P->state == PS_IDLE) in Psetfault()
2886 P->status.pr_flttrace = *set; in Psetfault()
2887 P->flags |= SETFAULT; in Psetfault()
2889 if (P->state == PS_RUN) in Psetfault()
2890 Psync(P); in Psetfault()
2897 Psysentry(struct ps_prochandle *P, int which, int stop) in Psysentry() argument
2899 return (Psetaction(P, &P->status.pr_sysentry, sizeof (sysset_t), in Psysentry()
2907 Psetsysentry(struct ps_prochandle *P, const sysset_t *set) in Psetsysentry() argument
2909 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetsysentry()
2910 P->state == PS_IDLE) in Psetsysentry()
2913 P->status.pr_sysentry = *set; in Psetsysentry()
2914 P->flags |= SETENTRY; in Psetsysentry()
2916 if (P->state == PS_RUN) in Psetsysentry()
2917 Psync(P); in Psetsysentry()
2924 Psysexit(struct ps_prochandle *P, int which, int stop) in Psysexit() argument
2926 return (Psetaction(P, &P->status.pr_sysexit, sizeof (sysset_t), in Psysexit()
2934 Psetsysexit(struct ps_prochandle *P, const sysset_t *set) in Psetsysexit() argument
2936 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetsysexit()
2937 P->state == PS_IDLE) in Psetsysexit()
2940 P->status.pr_sysexit = *set; in Psetsysexit()
2941 P->flags |= SETEXIT; in Psetsysexit()
2943 if (P->state == PS_RUN) in Psetsysexit()
2944 Psync(P); in Psetsysexit()
2953 read_lfile(struct ps_prochandle *P, const char *lname) in read_lfile() argument
2963 (int)P->status.pr_pid, lname); in read_lfile()
3002 Plwp_iter(struct ps_prochandle *P, proc_lwp_f *func, void *cd) in Plwp_iter() argument
3009 switch (P->state) { in Plwp_iter()
3011 (void) Pstopstatus(P, PCNULL, 0); in Plwp_iter()
3015 Psync(P); in Plwp_iter()
3027 if (P->status.pr_nlwp <= 1) in Plwp_iter()
3028 return (func(cd, &P->status.pr_lwp)); in Plwp_iter()
3034 if (P->state == PS_DEAD) { in Plwp_iter()
3035 core_info_t *core = P->data; in Plwp_iter()
3052 if ((Lhp = Plstatus(P)) == NULL) in Plwp_iter()
3071 Plwp_iter_all(struct ps_prochandle *P, proc_lwp_all_f *func, void *cd) in Plwp_iter_all() argument
3087 if (P->state == PS_RUN) in Plwp_iter_all()
3088 (void) Pstopstatus(P, PCNULL, 0); in Plwp_iter_all()
3089 (void) Ppsinfo(P); in Plwp_iter_all()
3091 if (P->state == PS_STOP) in Plwp_iter_all()
3092 Psync(P); in Plwp_iter_all()
3099 if (P->status.pr_nlwp + P->status.pr_nzomb <= 1) in Plwp_iter_all()
3100 return (func(cd, &P->status.pr_lwp, &P->psinfo.pr_lwp)); in Plwp_iter_all()
3106 if (P->state == PS_DEAD) { in Plwp_iter_all()
3107 core_info_t *core = P->data; in Plwp_iter_all()
3125 if ((Lhp = Plstatus(P)) == NULL) in Plwp_iter_all()
3127 if ((Lphp = Plpsinfo(P)) == NULL) { in Plwp_iter_all()
3137 if (Lhp->pr_nent != P->status.pr_nlwp || in Plwp_iter_all()
3138 Lphp->pr_nent != P->status.pr_nlwp + P->status.pr_nzomb) in Plwp_iter_all()
3189 Pcontent(struct ps_prochandle *P) in Pcontent() argument
3191 core_info_t *core = P->data; in Pcontent()
3193 if (P->state == PS_DEAD) in Pcontent()
3195 if (P->state == PS_IDLE) in Pcontent()
3214 Lfind_slot(struct ps_prochandle *P, lwpid_t lwpid) in Lfind_slot() argument
3219 for (Lp = &P->hashtab[lwpid % (HASHSIZE - 1)]; in Lfind_slot()
3231 Lfind(struct ps_prochandle *P, lwpid_t lwpid) in Lfind() argument
3233 if (P->hashtab == NULL) { in Lfind()
3237 return (*Lfind_slot(P, lwpid)); in Lfind()
3246 Lgrab(struct ps_prochandle *P, lwpid_t lwpid, int *perr) in Lgrab() argument
3255 (void) mutex_lock(&P->proc_lock); in Lgrab()
3257 if (P->state == PS_UNDEAD || P->state == PS_IDLE) in Lgrab()
3259 else if (P->hashtab == NULL && in Lgrab()
3260 (P->hashtab = calloc(HASHSIZE, sizeof (struct ps_lwphandle *))) in Lgrab()
3263 else if (*(Lp = Lfind_slot(P, lwpid)) != NULL) in Lgrab()
3269 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3276 L->lwp_proc = P; in Lgrab()
3280 if (P->state == PS_DEAD) { /* core file */ in Lgrab()
3281 if (getlwpstatus(P, lwpid, &L->lwp_status) == -1) { in Lgrab()
3287 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3295 procfs_path, (int)P->pid, (int)lwpid); in Lgrab()
3353 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3357 Lfree_internal(P, L); in Lgrab()
3359 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3395 struct ps_prochandle *P = L->lwp_proc; in Lfree() local
3397 (void) mutex_lock(&P->proc_lock); in Lfree()
3398 Lfree_internal(P, L); in Lfree()
3399 (void) mutex_unlock(&P->proc_lock); in Lfree()
3403 Lfree_internal(struct ps_prochandle *P, struct ps_lwphandle *L) in Lfree_internal() argument
3405 *Lfind_slot(P, L->lwp_id) = L->lwp_hash; /* delete from hash table */ in Lfree_internal()
3801 struct ps_prochandle *P = L->lwp_proc; in Lxecbkpt() local
3811 &P->status.pr_flttrace, &L->lwp_status.pr_lwphold, in Lxecbkpt()
3837 struct ps_prochandle *P = L->lwp_proc; in Lxecwapt() local
3847 &P->status.pr_flttrace, &L->lwp_status.pr_lwphold, wp); in Lxecwapt()
3868 struct ps_prochandle *P = L->lwp_proc; in Lstack() local
3871 if (P->status.pr_dmodel == PR_MODEL_NATIVE) { in Lstack()
3872 if (Pread(P, stkp, sizeof (*stkp), addr) != sizeof (*stkp)) in Lstack()
3878 if (Pread(P, &stk32, sizeof (stk32), addr) != sizeof (stk32)) in Lstack()
3891 struct ps_prochandle *P = L->lwp_proc; in Lmain_stack() local
3904 if (P->status.pr_dmodel == PR_MODEL_NATIVE) { in Lmain_stack()
3907 if (Pread(P, stkp, sizeof (*stkp), in Lmain_stack()
3915 if (Pread(P, &stk32, sizeof (stk32), in Lmain_stack()
3949 Padd_mapping(struct ps_prochandle *P, off64_t off, file_info_t *fp, in Padd_mapping() argument
3954 if (P->map_count == P->map_alloc) { in Padd_mapping()
3955 size_t next = P->map_alloc ? P->map_alloc * 2 : 16; in Padd_mapping()
3957 if ((P->mappings = realloc(P->mappings, in Padd_mapping()
3961 P->map_alloc = next; in Padd_mapping()
3964 mp = &P->mappings[P->map_count++]; in Padd_mapping()
3998 Psort_mappings(struct ps_prochandle *P) in Psort_mappings() argument
4003 qsort(P->mappings, P->map_count, sizeof (map_info_t), map_sort); in Psort_mappings()
4008 for (i = 0; i < P->map_count; i++) { in Psort_mappings()
4009 mp = &P->mappings[i]; in Psort_mappings()
4019 struct ps_prochandle *P; in Pgrab_ops() local
4021 if ((P = calloc(1, sizeof (*P))) == NULL) { in Pgrab_ops()
4025 Pinit_ops(&P->ops, ops); in Pgrab_ops()
4026 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL); in Pgrab_ops()
4027 P->pid = pid; in Pgrab_ops()
4028 P->state = PS_STOP; in Pgrab_ops()
4029 P->asfd = -1; in Pgrab_ops()
4030 P->ctlfd = -1; in Pgrab_ops()
4031 P->statfd = -1; in Pgrab_ops()
4032 P->agentctlfd = -1; in Pgrab_ops()
4033 P->agentstatfd = -1; in Pgrab_ops()
4034 Pinitsym(P); in Pgrab_ops()
4035 Pinitfd(P); in Pgrab_ops()
4036 P->data = data; in Pgrab_ops()
4037 Pread_status(P); in Pgrab_ops()
4040 P->flags |= INCORE; in Pgrab_ops()
4043 return (P); in Pgrab_ops()