Lines Matching refs:P
85 Pread_live(struct ps_prochandle *P, void *buf, size_t n, uintptr_t addr, in Pread_live() argument
88 return (pread(P->asfd, buf, n, (off_t)addr)); in Pread_live()
93 Pwrite_live(struct ps_prochandle *P, const void *buf, size_t n, uintptr_t addr, in Pwrite_live() argument
96 return (pwrite(P->asfd, buf, n, (off_t)addr)); in Pwrite_live()
101 Pread_maps_live(struct ps_prochandle *P, prmap_t **Pmapp, ssize_t *nmapp, in Pread_maps_live() argument
111 procfs_path, (int)P->pid); in Pread_maps_live()
122 Preset_maps(P); /* utter failure; destroy tables */ in Pread_maps_live()
135 Pread_aux_live(struct ps_prochandle *P, auxv_t **auxvp, int *nauxp, void *data) in Pread_aux_live() argument
144 procfs_path, (int)P->pid); in Pread_aux_live()
173 Pcred_live(struct ps_prochandle *P, prcred_t *pcrp, int ngroups, void *data) in Pcred_live() argument
175 return (proc_get_cred(P->pid, pcrp, ngroups)); in Pcred_live()
180 Ppriv_live(struct ps_prochandle *P, prpriv_t **pprv, void *data) in Ppriv_live() argument
184 pp = proc_get_priv(P->pid); in Ppriv_live()
195 Ppsinfo_live(struct ps_prochandle *P, psinfo_t *psinfo, void *data) in Ppsinfo_live() argument
197 if (proc_get_psinfo(P->pid, psinfo) == -1) in Ppsinfo_live()
205 Plstatus_live(struct ps_prochandle *P, void *data) in Plstatus_live() argument
207 return (read_lfile(P, "lstatus")); in Plstatus_live()
212 Plpsinfo_live(struct ps_prochandle *P, void *data) in Plpsinfo_live() argument
214 return (read_lfile(P, "lpsinfo")); in Plpsinfo_live()
219 Pplatform_live(struct ps_prochandle *P, char *s, size_t n, void *data) in Pplatform_live() argument
228 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()
260 Pexecname_live(struct ps_prochandle *P, char *buf, size_t buflen, void *data) in Pexecname_live() argument
272 "%s/%d/path/a.out", procfs_path, (int)P->pid); in Pexecname_live()
275 (void) Pfindobj(P, buf, buf, buflen); in Pexecname_live()
284 "%s/%d/object/a.out", procfs_path, (int)P->pid); in Pexecname_live()
295 "%s/%d/path/cwd", procfs_path, (int)P->pid); in Pexecname_live()
300 (void) Pfindexec(P, ret > 0 ? cwd : NULL, stat_exec, &st); in Pexecname_live()
308 Pldt_live(struct ps_prochandle *P, struct ssd *pldt, int nldt, void *data) in Pldt_live() argument
310 return (proc_get_ldt(P->pid, pldt, nldt)); in Pldt_live()
428 struct ps_prochandle *P; in Pxcreate() local
440 if ((P = malloc(sizeof (struct ps_prochandle))) == NULL) { in Pxcreate()
446 free(P); in Pxcreate()
463 Pcreate_callback(P); /* execute callback (see below) */ in Pxcreate()
481 (void) memset(P, 0, sizeof (*P)); in Pxcreate()
482 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL); in Pxcreate()
483 P->flags |= CREATED; in Pxcreate()
484 P->state = PS_RUN; in Pxcreate()
485 P->pid = pid; in Pxcreate()
486 P->asfd = -1; in Pxcreate()
487 P->ctlfd = -1; in Pxcreate()
488 P->statfd = -1; in Pxcreate()
489 P->agentctlfd = -1; in Pxcreate()
490 P->agentstatfd = -1; in Pxcreate()
491 Pinit_ops(&P->ops, &P_live_ops); in Pxcreate()
492 Pinitsym(P); in Pxcreate()
514 P->asfd = fd; in Pxcreate()
524 P->statfd = fd; in Pxcreate()
534 P->ctlfd = fd; in Pxcreate()
536 (void) Pstop(P, 0); /* stop the controlled process */ in Pxcreate()
546 (void) Psysentry(P, SYS_pause, 1); in Pxcreate()
547 (void) Psysexit(P, SYS_pause, 1); in Pxcreate()
549 if (P->state == PS_STOP && in Pxcreate()
550 P->status.pr_lwp.pr_syscall == SYS_pause && in Pxcreate()
551 (P->status.pr_lwp.pr_why == PR_REQUESTED || in Pxcreate()
552 P->status.pr_lwp.pr_why == PR_SYSENTRY || in Pxcreate()
553 P->status.pr_lwp.pr_why == PR_SYSEXIT)) in Pxcreate()
556 if (P->state != PS_STOP || /* interrupt or process died */ in Pxcreate()
557 Psetrun(P, 0, 0) != 0) { /* can't restart */ in Pxcreate()
568 (void) Pwait(P, 0); in Pxcreate()
570 (void) Psysentry(P, SYS_pause, 0); in Pxcreate()
571 (void) Psysexit(P, SYS_pause, 0); in Pxcreate()
577 (void) Psysentry(P, SYS_exit, 1); in Pxcreate()
578 (void) Psysentry(P, SYS_execve, 1); in Pxcreate()
579 if (Psetrun(P, 0, PRSABORT) == -1) { in Pxcreate()
584 (void) Pwait(P, 0); in Pxcreate()
585 if (P->state != PS_STOP) { in Pxcreate()
595 (void) Psysexit(P, SYS_execve, TRUE); in Pxcreate()
597 while (P->state == PS_STOP && in Pxcreate()
598 P->status.pr_lwp.pr_why == PR_SYSENTRY && in Pxcreate()
599 P->status.pr_lwp.pr_what == SYS_execve) { in Pxcreate()
605 (void) Pread_string(P, execpath, sizeof (execpath), in Pxcreate()
606 (off_t)P->status.pr_lwp.pr_sysarg[0]); in Pxcreate()
613 (void) Psetrun(P, 0, 0); in Pxcreate()
614 (void) Pwait(P, 0); in Pxcreate()
616 if (P->state == PS_LOST && /* we lost control */ in Pxcreate()
617 Preopen(P) != 0) { /* and we can't get it back */ in Pxcreate()
626 if (P->state == PS_STOP && in Pxcreate()
627 P->status.pr_lwp.pr_why == PR_SYSEXIT && in Pxcreate()
628 P->status.pr_lwp.pr_what == SYS_execve && in Pxcreate()
629 (lasterrno = P->status.pr_lwp.pr_errno) != 0) { in Pxcreate()
634 (void) Psetrun(P, 0, 0); in Pxcreate()
635 (void) Pwait(P, 0); in Pxcreate()
642 if (P->state == PS_STOP && in Pxcreate()
643 P->status.pr_lwp.pr_why == PR_SYSEXIT && in Pxcreate()
644 P->status.pr_lwp.pr_what == SYS_execve && in Pxcreate()
645 P->status.pr_lwp.pr_errno == 0) { in Pxcreate()
650 restore_tracing_flags(P); in Pxcreate()
653 if (P->status.pr_dmodel == PR_MODEL_LP64) { in Pxcreate()
662 (void) Psetflags(P, PR_RLC); in Pxcreate()
664 return (P); in Pxcreate()
673 Pfree(P); in Pxcreate()
737 Pcreate_callback(struct ps_prochandle *P) in Pcreate_callback() argument
758 struct ps_prochandle *P; in Pgrab() local
771 if ((P = malloc(sizeof (struct ps_prochandle))) == NULL) { in Pgrab()
776 P->asfd = -1; in Pgrab()
777 P->ctlfd = -1; in Pgrab()
778 P->statfd = -1; in Pgrab()
781 if (P->ctlfd >= 0) in Pgrab()
782 (void) close(P->ctlfd); in Pgrab()
783 if (P->asfd >= 0) in Pgrab()
784 (void) close(P->asfd); in Pgrab()
785 if (P->statfd >= 0) in Pgrab()
786 (void) close(P->statfd); in Pgrab()
787 (void) memset(P, 0, sizeof (*P)); in Pgrab()
788 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL); in Pgrab()
789 P->ctlfd = -1; in Pgrab()
790 P->asfd = -1; in Pgrab()
791 P->statfd = -1; in Pgrab()
792 P->agentctlfd = -1; in Pgrab()
793 P->agentstatfd = -1; in Pgrab()
794 Pinit_ops(&P->ops, &P_live_ops); in Pgrab()
795 Pinitsym(P); in Pgrab()
842 P->asfd = fd; in Pgrab()
862 P->statfd = fd; in Pgrab()
883 P->ctlfd = fd; in Pgrab()
886 P->state = PS_RUN; in Pgrab()
887 P->pid = pid; in Pgrab()
899 if (Pstopstatus(P, PCNULL, 0) != 0) { in Pgrab()
906 if (P->state == PS_LOST) { /* WoV */ in Pgrab()
907 (void) mutex_destroy(&P->proc_lock); in Pgrab()
911 if (P->state == PS_UNDEAD) in Pgrab()
922 if (P->status.pr_flags & PR_ISSYS) { in Pgrab()
930 if (P->status.pr_dmodel == PR_MODEL_LP64) { in Pgrab()
939 P->orig_status = P->status; /* structure copy */ in Pgrab()
956 if (Pread(P, &magic2, sizeof (magic2), (uintptr_t)&magic1) in Pgrab()
960 Pread(P, &magic2, sizeof (magic2), (uintptr_t)&magic1) in Pgrab()
973 if (!(P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) && in Pgrab()
979 if (Psetflags(P, PR_RLC) != 0) { in Pgrab()
981 (void) mutex_destroy(&P->proc_lock); in Pgrab()
1006 while ((P->status.pr_lwp.pr_flags & (PR_STOPPED|PR_DSTOP)) == in Pgrab()
1008 Pstopstatus(P, PCTWSTOP, 20) != 0) { in Pgrab()
1015 P->status.pr_lwp.pr_flags &= ~PR_DSTOP; in Pgrab()
1023 if (!(P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) && in Pgrab()
1028 if (((P->status.pr_lwp.pr_flags & PR_STOPPED) && in Pgrab()
1029 Pstopstatus(P, PCDSTOP, 0) != 0) || in Pgrab()
1030 Pstopstatus(P, PCSTOP, 2000) != 0) { in Pgrab()
1037 if (P->state == PS_LOST) { /* WoV */ in Pgrab()
1038 (void) mutex_destroy(&P->proc_lock); in Pgrab()
1042 (P->state != PS_STOP && in Pgrab()
1043 !(P->status.pr_flags & PR_DSTOP))) { in Pgrab()
1044 if (P->state != PS_RUN && errno != ENOENT) { in Pgrab()
1058 if (!(P->status.pr_flags & (PR_ISTOP|PR_DSTOP))) { in Pgrab()
1068 if (P->status.pr_dmodel == PR_MODEL_LP64) { in Pgrab()
1079 (void) Psysentry(P, 0, FALSE); in Pgrab()
1080 (void) Psysexit(P, 0, FALSE); in Pgrab()
1081 (void) Psignal(P, 0, FALSE); in Pgrab()
1082 (void) Pfault(P, 0, FALSE); in Pgrab()
1083 Psync(P); in Pgrab()
1087 return (P); in Pgrab()
1090 Pfree(P); in Pgrab()
1171 Pfree(struct ps_prochandle *P) in Pfree() argument
1175 if (P->ucaddrs != NULL) { in Pfree()
1176 free(P->ucaddrs); in Pfree()
1177 P->ucaddrs = NULL; in Pfree()
1178 P->ucnelems = 0; in Pfree()
1181 (void) mutex_lock(&P->proc_lock); in Pfree()
1182 if (P->hashtab != NULL) { in Pfree()
1185 while ((L = P->hashtab[i]) != NULL) in Pfree()
1186 Lfree_internal(P, L); in Pfree()
1188 free(P->hashtab); in Pfree()
1191 while (P->num_fd > 0) { in Pfree()
1192 fd_info_t *fip = list_next(&P->fd_head); in Pfree()
1195 P->num_fd--; in Pfree()
1197 (void) mutex_unlock(&P->proc_lock); in Pfree()
1198 (void) mutex_destroy(&P->proc_lock); in Pfree()
1200 if (P->agentctlfd >= 0) in Pfree()
1201 (void) close(P->agentctlfd); in Pfree()
1202 if (P->agentstatfd >= 0) in Pfree()
1203 (void) close(P->agentstatfd); in Pfree()
1204 if (P->ctlfd >= 0) in Pfree()
1205 (void) close(P->ctlfd); in Pfree()
1206 if (P->asfd >= 0) in Pfree()
1207 (void) close(P->asfd); in Pfree()
1208 if (P->statfd >= 0) in Pfree()
1209 (void) close(P->statfd); in Pfree()
1210 Preset_maps(P); in Pfree()
1211 P->ops.pop_fini(P, P->data); in Pfree()
1214 (void) memset(P, 0, sizeof (*P)); in Pfree()
1215 P->ctlfd = -1; in Pfree()
1216 P->asfd = -1; in Pfree()
1217 P->statfd = -1; in Pfree()
1218 P->agentctlfd = -1; in Pfree()
1219 P->agentstatfd = -1; in Pfree()
1221 free(P); in Pfree()
1228 Pstate(struct ps_prochandle *P) in Pstate() argument
1230 return (P->state); in Pstate()
1239 Pasfd(struct ps_prochandle *P) in Pasfd() argument
1241 return (P->asfd); in Pasfd()
1250 Pctlfd(struct ps_prochandle *P) in Pctlfd() argument
1252 return (P->ctlfd); in Pctlfd()
1261 Ppsinfo(struct ps_prochandle *P) in Ppsinfo() argument
1263 return (P->ops.pop_psinfo(P, &P->psinfo, P->data)); in Ppsinfo()
1272 Pstatus(struct ps_prochandle *P) in Pstatus() argument
1274 return (&P->status); in Pstatus()
1278 Pread_status(struct ps_prochandle *P) in Pread_status() argument
1280 P->ops.pop_status(P, &P->status, P->data); in Pread_status()
1290 Pcred(struct ps_prochandle *P, prcred_t *pcrp, int ngroups) in Pcred() argument
1292 return (P->ops.pop_cred(P, pcrp, ngroups, P->data)); in Pcred()
1296 Plstatus(struct ps_prochandle *P) in Plstatus() argument
1298 return (P->ops.pop_lstatus(P, P->data)); in Plstatus()
1302 Plpsinfo(struct ps_prochandle *P) in Plpsinfo() argument
1304 return (P->ops.pop_lpsinfo(P, P->data)); in Plpsinfo()
1316 Pldt(struct ps_prochandle *P, struct ssd *pldt, int nldt) in Pldt() argument
1318 return (P->ops.pop_ldt(P, pldt, nldt, P->data)); in Pldt()
1327 Ppriv(struct ps_prochandle *P, prpriv_t **pprv) in Ppriv() argument
1329 return (P->ops.pop_priv(P, pprv, P->data)); in Ppriv()
1333 Psetpriv(struct ps_prochandle *P, prpriv_t *pprv) in Psetpriv() argument
1339 if (P->state == PS_DEAD) { in Psetpriv()
1356 if (write(P->ctlfd, ctl, sz) != sz) in Psetpriv()
1367 Pprivinfo(struct ps_prochandle *P) in Pprivinfo() argument
1369 core_info_t *core = P->data; in Pprivinfo()
1372 if (P->state != PS_DEAD) in Pprivinfo()
1384 Psync(struct ps_prochandle *P) in Psync() argument
1386 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Psync()
1391 if (P->flags & SETHOLD) { in Psync()
1395 iov[n].iov_base = (caddr_t)&P->status.pr_lwp.pr_lwphold; in Psync()
1396 iov[n++].iov_len = sizeof (P->status.pr_lwp.pr_lwphold); in Psync()
1398 if (P->flags & SETREGS) { in Psync()
1402 if (ctlfd == P->agentctlfd) in Psync()
1403 P->status.pr_lwp.pr_reg[GS] = 0; in Psync()
1409 iov[n].iov_base = (caddr_t)&P->status.pr_lwp.pr_reg[0]; in Psync()
1410 iov[n++].iov_len = sizeof (P->status.pr_lwp.pr_reg); in Psync()
1412 if (P->flags & SETSIG) { in Psync()
1416 iov[n].iov_base = (caddr_t)&P->status.pr_sigtrace; in Psync()
1417 iov[n++].iov_len = sizeof (P->status.pr_sigtrace); in Psync()
1419 if (P->flags & SETFAULT) { in Psync()
1423 iov[n].iov_base = (caddr_t)&P->status.pr_flttrace; in Psync()
1424 iov[n++].iov_len = sizeof (P->status.pr_flttrace); in Psync()
1426 if (P->flags & SETENTRY) { in Psync()
1430 iov[n].iov_base = (caddr_t)&P->status.pr_sysentry; in Psync()
1431 iov[n++].iov_len = sizeof (P->status.pr_sysentry); in Psync()
1433 if (P->flags & SETEXIT) { in Psync()
1437 iov[n].iov_base = (caddr_t)&P->status.pr_sysexit; in Psync()
1438 iov[n++].iov_len = sizeof (P->status.pr_sysexit); in Psync()
1444 P->flags &= ~(SETSIG|SETFAULT|SETENTRY|SETEXIT|SETHOLD|SETREGS); in Psync()
1451 Preopen(struct ps_prochandle *P) in Preopen() argument
1457 if (P->state == PS_DEAD || P->state == PS_IDLE) in Preopen()
1460 if (P->agentcnt > 0) { in Preopen()
1461 P->agentcnt = 1; in Preopen()
1462 Pdestroy_agent(P); in Preopen()
1466 procfs_path, (int)P->pid); in Preopen()
1471 close(P->asfd) < 0 || in Preopen()
1472 (fd = dupfd(fd, P->asfd)) != P->asfd) { in Preopen()
1479 P->asfd = fd; in Preopen()
1483 close(P->statfd) < 0 || in Preopen()
1484 (fd = dupfd(fd, P->statfd)) != P->statfd) { in Preopen()
1491 P->statfd = fd; in Preopen()
1495 close(P->ctlfd) < 0 || in Preopen()
1496 (fd = dupfd(fd, P->ctlfd)) != P->ctlfd) { in Preopen()
1503 P->ctlfd = fd; in Preopen()
1512 P->state = PS_RUN; in Preopen()
1513 if (Pwait(P, 0) == -1) { in Preopen()
1516 P->status.pr_dmodel = PR_MODEL_LP64; in Preopen()
1518 P->status.pr_lwp.pr_why = PR_SYSEXIT; in Preopen()
1519 P->status.pr_lwp.pr_what = SYS_execve; in Preopen()
1520 P->status.pr_lwp.pr_errno = 0; in Preopen()
1528 if (P->state == PS_STOP && in Preopen()
1529 (P->status.pr_lwp.pr_why == PR_REQUESTED || in Preopen()
1530 (P->status.pr_lwp.pr_why == PR_SYSEXIT && in Preopen()
1531 P->status.pr_lwp.pr_what == SYS_execve))) { in Preopen()
1533 if (P->status.pr_lwp.pr_why == PR_REQUESTED) { in Preopen()
1534 P->status.pr_lwp.pr_why = PR_SYSEXIT; in Preopen()
1535 P->status.pr_lwp.pr_what = SYS_execve; in Preopen()
1536 P->status.pr_lwp.pr_errno = 0; in Preopen()
1557 restore_tracing_flags(struct ps_prochandle *P) in restore_tracing_flags() argument
1563 if (P->flags & CREATED) { in restore_tracing_flags()
1565 premptyset(&P->status.pr_sigtrace); in restore_tracing_flags()
1566 premptyset(&P->status.pr_flttrace); in restore_tracing_flags()
1567 premptyset(&P->status.pr_sysentry); in restore_tracing_flags()
1568 premptyset(&P->status.pr_sysexit); in restore_tracing_flags()
1569 if ((P->status.pr_flags & ALL_SETTABLE_FLAGS) != 0) in restore_tracing_flags()
1570 (void) Punsetflags(P, ALL_SETTABLE_FLAGS); in restore_tracing_flags()
1573 P->status.pr_sigtrace = P->orig_status.pr_sigtrace; in restore_tracing_flags()
1574 P->status.pr_flttrace = P->orig_status.pr_flttrace; in restore_tracing_flags()
1575 P->status.pr_sysentry = P->orig_status.pr_sysentry; in restore_tracing_flags()
1576 P->status.pr_sysexit = P->orig_status.pr_sysexit; in restore_tracing_flags()
1577 if ((P->status.pr_flags & ALL_SETTABLE_FLAGS) != in restore_tracing_flags()
1578 (flags = (P->orig_status.pr_flags & ALL_SETTABLE_FLAGS))) { in restore_tracing_flags()
1579 (void) Punsetflags(P, ALL_SETTABLE_FLAGS); in restore_tracing_flags()
1581 (void) Psetflags(P, flags); in restore_tracing_flags()
1588 iov[1].iov_base = (caddr_t)&P->status.pr_sigtrace; in restore_tracing_flags()
1589 iov[1].iov_len = sizeof (P->status.pr_sigtrace); in restore_tracing_flags()
1594 iov[3].iov_base = (caddr_t)&P->status.pr_flttrace; in restore_tracing_flags()
1595 iov[3].iov_len = sizeof (P->status.pr_flttrace); in restore_tracing_flags()
1600 iov[5].iov_base = (caddr_t)&P->status.pr_sysentry; in restore_tracing_flags()
1601 iov[5].iov_len = sizeof (P->status.pr_sysentry); in restore_tracing_flags()
1606 iov[7].iov_base = (caddr_t)&P->status.pr_sysexit; in restore_tracing_flags()
1607 iov[7].iov_len = sizeof (P->status.pr_sysexit); in restore_tracing_flags()
1609 (void) writev(P->ctlfd, iov, 8); in restore_tracing_flags()
1611 P->flags &= ~(SETSIG|SETFAULT|SETENTRY|SETEXIT); in restore_tracing_flags()
1623 Prelease(struct ps_prochandle *P, int flags) in Prelease() argument
1625 if (P->state == PS_DEAD) { in Prelease()
1627 (void *)P, (int)P->pid); in Prelease()
1628 Pfree(P); in Prelease()
1632 if (P->state == PS_IDLE) { in Prelease()
1633 file_info_t *fptr = list_next(&P->file_head); in Prelease()
1635 (void *)P, fptr->file_pname); in Prelease()
1636 Pfree(P); in Prelease()
1641 (void *)P, (int)P->pid); in Prelease()
1643 if (P->ctlfd == -1) { in Prelease()
1644 Pfree(P); in Prelease()
1648 if (P->agentcnt > 0) { in Prelease()
1649 P->agentcnt = 1; in Prelease()
1650 Pdestroy_agent(P); in Prelease()
1656 P->state = PS_RUN; in Prelease()
1657 (void) Pstop(P, 1000); in Prelease()
1660 if (P->state == PS_STOP) in Prelease()
1661 (void) Psetrun(P, SIGKILL, 0); in Prelease()
1662 (void) kill(P->pid, SIGKILL); in Prelease()
1663 Pfree(P); in Prelease()
1671 if (P->state != PS_STOP && in Prelease()
1672 (P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) == 0) { in Prelease()
1673 Pfree(P); in Prelease()
1680 Psync(P); in Prelease()
1683 P->flags |= CREATED; in Prelease()
1686 restore_tracing_flags(P); in Prelease()
1690 (void) Punsetflags(P, PR_RLC|PR_KLC); in Prelease()
1691 Pfree(P); in Prelease()
1700 if ((P->flags & CREATED) || in Prelease()
1701 (P->orig_status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) == 0) { in Prelease()
1702 (void) Psetflags(P, PR_RLC); in Prelease()
1709 if (Psetrun(P, 0, 0) == -1 && errno == EBUSY) in Prelease()
1711 } while (Pstopstatus(P, PCNULL, 0) == 0 && in Prelease()
1712 P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)); in Prelease()
1714 if (P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) in Prelease()
1718 Pfree(P); in Prelease()
1770 prdump(struct ps_prochandle *P) in prdump() argument
1774 prldump("Pstopstatus", &P->status.pr_lwp); in prdump()
1776 bits = *((uint32_t *)&P->status.pr_sigpend); in prdump()
1789 Pstopstatus(struct ps_prochandle *P, in Pstopstatus() argument
1793 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pstopstatus()
1797 int old_state = P->state; in Pstopstatus()
1799 switch (P->state) { in Pstopstatus()
1821 dprintf("Pstopstatus: corrupted state: %d\n", P->state); in Pstopstatus()
1841 if (P->state == PS_DEAD || P->state == PS_IDLE) in Pstopstatus()
1849 Psync(P); in Pstopstatus()
1851 if (P->agentstatfd < 0) { in Pstopstatus()
1852 if (pread(P->statfd, &P->status, in Pstopstatus()
1853 sizeof (P->status), (off_t)0) < 0) in Pstopstatus()
1856 if (pread(P->agentstatfd, &P->status.pr_lwp, in Pstopstatus()
1857 sizeof (P->status.pr_lwp), (off_t)0) < 0) in Pstopstatus()
1859 P->status.pr_flags = P->status.pr_lwp.pr_flags; in Pstopstatus()
1871 P->state = PS_LOST; in Pstopstatus()
1891 deadcheck(P); in Pstopstatus()
1900 if (!(P->status.pr_flags & PR_STOPPED)) { in Pstopstatus()
1901 P->state = PS_RUN; in Pstopstatus()
1909 P->state = PS_STOP; in Pstopstatus()
1912 prdump(P); in Pstopstatus()
1922 switch (P->status.pr_lwp.pr_why) { in Pstopstatus()
1925 if (Pissyscall_prev(P, P->status.pr_lwp.pr_reg[R_PC], in Pstopstatus()
1926 &P->sysaddr) == 0) in Pstopstatus()
1927 P->sysaddr = P->status.pr_lwp.pr_reg[R_PC]; in Pstopstatus()
1947 Pwait(struct ps_prochandle *P, uint_t msec) in Pwait() argument
1949 return (Pstopstatus(P, PCWSTOP, msec)); in Pwait()
1956 Pstop(struct ps_prochandle *P, uint_t msec) in Pstop() argument
1958 return (Pstopstatus(P, PCSTOP, msec)); in Pstop()
1965 Pdstop(struct ps_prochandle *P) in Pdstop() argument
1967 return (Pstopstatus(P, PCDSTOP, 0)); in Pdstop()
1971 deadcheck(struct ps_prochandle *P) in deadcheck() argument
1977 if (P->statfd < 0) in deadcheck()
1978 P->state = PS_UNDEAD; in deadcheck()
1980 if (P->agentstatfd < 0) { in deadcheck()
1981 fd = P->statfd; in deadcheck()
1982 buf = &P->status; in deadcheck()
1983 size = sizeof (P->status); in deadcheck()
1985 fd = P->agentstatfd; in deadcheck()
1986 buf = &P->status.pr_lwp; in deadcheck()
1987 size = sizeof (P->status.pr_lwp); in deadcheck()
1992 P->state = PS_UNDEAD; in deadcheck()
1998 P->state = PS_LOST; in deadcheck()
2003 P->status.pr_flags = P->status.pr_lwp.pr_flags; in deadcheck()
2011 Pgetareg(struct ps_prochandle *P, int regno, prgreg_t *preg) in Pgetareg() argument
2018 if (P->state == PS_IDLE) { in Pgetareg()
2023 if (P->state != PS_STOP && P->state != PS_DEAD) { in Pgetareg()
2028 *preg = P->status.pr_lwp.pr_reg[regno]; in Pgetareg()
2036 Pputareg(struct ps_prochandle *P, int regno, prgreg_t reg) in Pputareg() argument
2043 if (P->state != PS_STOP) { in Pputareg()
2048 P->status.pr_lwp.pr_reg[regno] = reg; in Pputareg()
2049 P->flags |= SETREGS; /* set registers before continuing */ in Pputareg()
2054 Psetrun(struct ps_prochandle *P, in Psetrun() argument
2058 int ctlfd = (P->agentctlfd >= 0) ? P->agentctlfd : P->ctlfd; in Psetrun()
2068 if (P->state != PS_STOP && (P->status.pr_lwp.pr_flags & sbits) == 0) { in Psetrun()
2073 Psync(P); /* flush tracing flags and registers */ in Psetrun()
2083 } else if (sig && sig != P->status.pr_lwp.pr_cursig) { in Psetrun()
2098 P->info_valid = 0; /* will need to update map and file info */ in Psetrun()
2104 if (P->ucaddrs != NULL) { in Psetrun()
2105 free(P->ucaddrs); in Psetrun()
2106 P->ucaddrs = NULL; in Psetrun()
2107 P->ucnelems = 0; in Psetrun()
2113 (void) Pstopstatus(P, PCNULL, 0); in Psetrun()
2118 P->status.pr_lwp.pr_why != PR_JOBCONTROL) { in Psetrun()
2125 P->state = PS_RUN; in Psetrun()
2130 Pread(struct ps_prochandle *P, in Pread() argument
2135 return (P->ops.pop_pread(P, buf, nbyte, address, P->data)); in Pread()
2139 Pread_string(struct ps_prochandle *P, in Pread_string() argument
2160 if ((nbyte = P->ops.pop_pread(P, string, STRSZ, addr, in Pread_string()
2161 P->data)) <= 0) { in Pread_string()
2177 Pwrite(struct ps_prochandle *P, in Pwrite() argument
2182 return (P->ops.pop_pwrite(P, buf, nbyte, address, P->data)); in Pwrite()
2186 Pclearsig(struct ps_prochandle *P) in Pclearsig() argument
2188 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pclearsig()
2193 P->status.pr_lwp.pr_cursig = 0; in Pclearsig()
2198 Pclearfault(struct ps_prochandle *P) in Pclearfault() argument
2200 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pclearfault()
2212 Psetbkpt(struct ps_prochandle *P, uintptr_t address, ulong_t *saved) in Psetbkpt() argument
2222 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetbkpt()
2223 P->state == PS_IDLE) { in Psetbkpt()
2245 if (write(P->ctlfd, ctl, size) != size) in Psetbkpt()
2265 Pdelbkpt(struct ps_prochandle *P, uintptr_t address, ulong_t saved) in Pdelbkpt() argument
2270 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Pdelbkpt()
2271 P->state == PS_IDLE) { in Pdelbkpt()
2283 if (Pread(P, &cur, sizeof (cur), address) == sizeof (cur) && in Pdelbkpt()
2287 if (Pwrite(P, &old, sizeof (old), address) != sizeof (old)) in Pdelbkpt()
2397 Pxecbkpt(struct ps_prochandle *P, ulong_t saved) in Pxecbkpt() argument
2399 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pxecbkpt()
2402 if (P->state != PS_STOP) { in Pxecbkpt()
2407 Psync(P); in Pxecbkpt()
2410 &P->status.pr_flttrace, &P->status.pr_lwp.pr_lwphold, in Pxecbkpt()
2411 P->status.pr_lwp.pr_reg[R_PC], saved); in Pxecbkpt()
2412 rv = Pstopstatus(P, PCNULL, 0); in Pxecbkpt()
2415 if (P->status.pr_lwp.pr_why == PR_JOBCONTROL && in Pxecbkpt()
2417 P->state = PS_RUN; in Pxecbkpt()
2433 Psetwapt(struct ps_prochandle *P, const prwatch_t *wp) in Psetwapt() argument
2438 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetwapt()
2439 P->state == PS_IDLE) { in Psetwapt()
2449 if (write(P->ctlfd, ctl, sizeof (ctl)) != sizeof (ctl)) in Psetwapt()
2459 Pdelwapt(struct ps_prochandle *P, const prwatch_t *wp) in Pdelwapt() argument
2464 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Pdelwapt()
2465 P->state == PS_IDLE) { in Pdelwapt()
2475 if (write(P->ctlfd, ctl, sizeof (ctl)) != sizeof (ctl)) in Pdelwapt()
2592 Pxecwapt(struct ps_prochandle *P, const prwatch_t *wp) in Pxecwapt() argument
2594 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd; in Pxecwapt()
2597 if (P->state != PS_STOP) { in Pxecwapt()
2602 Psync(P); in Pxecwapt()
2604 &P->status.pr_flttrace, &P->status.pr_lwp.pr_lwphold, wp); in Pxecwapt()
2605 rv = Pstopstatus(P, PCNULL, 0); in Pxecwapt()
2608 if (P->status.pr_lwp.pr_why == PR_JOBCONTROL && in Pxecwapt()
2610 P->state = PS_RUN; in Pxecwapt()
2623 Psetflags(struct ps_prochandle *P, long flags) in Psetflags() argument
2631 if (write(P->ctlfd, ctl, 2*sizeof (long)) != 2*sizeof (long)) { in Psetflags()
2634 P->status.pr_flags |= flags; in Psetflags()
2635 P->status.pr_lwp.pr_flags |= flags; in Psetflags()
2643 Punsetflags(struct ps_prochandle *P, long flags) in Punsetflags() argument
2651 if (write(P->ctlfd, ctl, 2*sizeof (long)) != 2*sizeof (long)) { in Punsetflags()
2654 P->status.pr_flags &= ~flags; in Punsetflags()
2655 P->status.pr_lwp.pr_flags &= ~flags; in Punsetflags()
2673 Psetaction(struct ps_prochandle *P, void *sp, size_t size, in Psetaction() argument
2683 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetaction()
2684 P->state == PS_IDLE) { in Psetaction()
2694 P->flags |= flag; in Psetaction()
2697 P->flags |= flag; in Psetaction()
2702 P->flags |= flag; in Psetaction()
2705 P->flags |= flag; in Psetaction()
2709 if (P->state == PS_RUN) in Psetaction()
2710 Psync(P); in Psetaction()
2719 Psignal(struct ps_prochandle *P, int which, int stop) in Psignal() argument
2728 oldval = Psetaction(P, &P->status.pr_sigtrace, sizeof (sigset_t), in Psignal()
2732 prdelset(&P->status.pr_sigtrace, SIGKILL); in Psignal()
2741 Psetsignal(struct ps_prochandle *P, const sigset_t *set) in Psetsignal() argument
2743 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetsignal()
2744 P->state == PS_IDLE) in Psetsignal()
2747 P->status.pr_sigtrace = *set; in Psetsignal()
2748 P->flags |= SETSIG; in Psetsignal()
2750 if (P->state == PS_RUN) in Psetsignal()
2751 Psync(P); in Psetsignal()
2758 Pfault(struct ps_prochandle *P, int which, int stop) in Pfault() argument
2760 return (Psetaction(P, &P->status.pr_flttrace, sizeof (fltset_t), in Pfault()
2768 Psetfault(struct ps_prochandle *P, const fltset_t *set) in Psetfault() argument
2770 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetfault()
2771 P->state == PS_IDLE) in Psetfault()
2774 P->status.pr_flttrace = *set; in Psetfault()
2775 P->flags |= SETFAULT; in Psetfault()
2777 if (P->state == PS_RUN) in Psetfault()
2778 Psync(P); in Psetfault()
2785 Psysentry(struct ps_prochandle *P, int which, int stop) in Psysentry() argument
2787 return (Psetaction(P, &P->status.pr_sysentry, sizeof (sysset_t), in Psysentry()
2795 Psetsysentry(struct ps_prochandle *P, const sysset_t *set) in Psetsysentry() argument
2797 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetsysentry()
2798 P->state == PS_IDLE) in Psetsysentry()
2801 P->status.pr_sysentry = *set; in Psetsysentry()
2802 P->flags |= SETENTRY; in Psetsysentry()
2804 if (P->state == PS_RUN) in Psetsysentry()
2805 Psync(P); in Psetsysentry()
2812 Psysexit(struct ps_prochandle *P, int which, int stop) in Psysexit() argument
2814 return (Psetaction(P, &P->status.pr_sysexit, sizeof (sysset_t), in Psysexit()
2822 Psetsysexit(struct ps_prochandle *P, const sysset_t *set) in Psetsysexit() argument
2824 if (P->state == PS_DEAD || P->state == PS_UNDEAD || in Psetsysexit()
2825 P->state == PS_IDLE) in Psetsysexit()
2828 P->status.pr_sysexit = *set; in Psetsysexit()
2829 P->flags |= SETEXIT; in Psetsysexit()
2831 if (P->state == PS_RUN) in Psetsysexit()
2832 Psync(P); in Psetsysexit()
2841 read_lfile(struct ps_prochandle *P, const char *lname) in read_lfile() argument
2851 (int)P->status.pr_pid, lname); in read_lfile()
2890 Plwp_iter(struct ps_prochandle *P, proc_lwp_f *func, void *cd) in Plwp_iter() argument
2897 switch (P->state) { in Plwp_iter()
2899 (void) Pstopstatus(P, PCNULL, 0); in Plwp_iter()
2903 Psync(P); in Plwp_iter()
2915 if (P->status.pr_nlwp <= 1) in Plwp_iter()
2916 return (func(cd, &P->status.pr_lwp)); in Plwp_iter()
2922 if (P->state == PS_DEAD) { in Plwp_iter()
2923 core_info_t *core = P->data; in Plwp_iter()
2940 if ((Lhp = Plstatus(P)) == NULL) in Plwp_iter()
2959 Plwp_iter_all(struct ps_prochandle *P, proc_lwp_all_f *func, void *cd) in Plwp_iter_all() argument
2975 if (P->state == PS_RUN) in Plwp_iter_all()
2976 (void) Pstopstatus(P, PCNULL, 0); in Plwp_iter_all()
2977 (void) Ppsinfo(P); in Plwp_iter_all()
2979 if (P->state == PS_STOP) in Plwp_iter_all()
2980 Psync(P); in Plwp_iter_all()
2987 if (P->status.pr_nlwp + P->status.pr_nzomb <= 1) in Plwp_iter_all()
2988 return (func(cd, &P->status.pr_lwp, &P->psinfo.pr_lwp)); in Plwp_iter_all()
2994 if (P->state == PS_DEAD) { in Plwp_iter_all()
2995 core_info_t *core = P->data; in Plwp_iter_all()
3013 if ((Lhp = Plstatus(P)) == NULL) in Plwp_iter_all()
3015 if ((Lphp = Plpsinfo(P)) == NULL) { in Plwp_iter_all()
3025 if (Lhp->pr_nent != P->status.pr_nlwp || in Plwp_iter_all()
3026 Lphp->pr_nent != P->status.pr_nlwp + P->status.pr_nzomb) in Plwp_iter_all()
3077 Pcontent(struct ps_prochandle *P) in Pcontent() argument
3079 core_info_t *core = P->data; in Pcontent()
3081 if (P->state == PS_DEAD) in Pcontent()
3083 if (P->state == PS_IDLE) in Pcontent()
3102 Lfind(struct ps_prochandle *P, lwpid_t lwpid) in Lfind() argument
3107 for (Lp = &P->hashtab[lwpid % (HASHSIZE - 1)]; in Lfind()
3120 Lgrab(struct ps_prochandle *P, lwpid_t lwpid, int *perr) in Lgrab() argument
3129 (void) mutex_lock(&P->proc_lock); in Lgrab()
3131 if (P->state == PS_UNDEAD || P->state == PS_IDLE) in Lgrab()
3133 else if (P->hashtab == NULL && in Lgrab()
3134 (P->hashtab = calloc(HASHSIZE, sizeof (struct ps_lwphandle *))) in Lgrab()
3137 else if (*(Lp = Lfind(P, lwpid)) != NULL) in Lgrab()
3143 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3150 L->lwp_proc = P; in Lgrab()
3154 if (P->state == PS_DEAD) { /* core file */ in Lgrab()
3155 if (getlwpstatus(P, lwpid, &L->lwp_status) == -1) { in Lgrab()
3161 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3169 procfs_path, (int)P->pid, (int)lwpid); in Lgrab()
3227 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3231 Lfree_internal(P, L); in Lgrab()
3233 (void) mutex_unlock(&P->proc_lock); in Lgrab()
3269 struct ps_prochandle *P = L->lwp_proc; in Lfree() local
3271 (void) mutex_lock(&P->proc_lock); in Lfree()
3272 Lfree_internal(P, L); in Lfree()
3273 (void) mutex_unlock(&P->proc_lock); in Lfree()
3277 Lfree_internal(struct ps_prochandle *P, struct ps_lwphandle *L) in Lfree_internal() argument
3279 *Lfind(P, L->lwp_id) = L->lwp_hash; /* delete from hash table */ in Lfree_internal()
3675 struct ps_prochandle *P = L->lwp_proc; in Lxecbkpt() local
3685 &P->status.pr_flttrace, &L->lwp_status.pr_lwphold, in Lxecbkpt()
3711 struct ps_prochandle *P = L->lwp_proc; in Lxecwapt() local
3721 &P->status.pr_flttrace, &L->lwp_status.pr_lwphold, wp); in Lxecwapt()
3742 struct ps_prochandle *P = L->lwp_proc; in Lstack() local
3745 if (P->status.pr_dmodel == PR_MODEL_NATIVE) { in Lstack()
3746 if (Pread(P, stkp, sizeof (*stkp), addr) != sizeof (*stkp)) in Lstack()
3752 if (Pread(P, &stk32, sizeof (stk32), addr) != sizeof (stk32)) in Lstack()
3765 struct ps_prochandle *P = L->lwp_proc; in Lmain_stack() local
3778 if (P->status.pr_dmodel == PR_MODEL_NATIVE) { in Lmain_stack()
3781 if (Pread(P, stkp, sizeof (*stkp), in Lmain_stack()
3789 if (Pread(P, &stk32, sizeof (stk32), in Lmain_stack()
3823 Padd_mapping(struct ps_prochandle *P, off64_t off, file_info_t *fp, in Padd_mapping() argument
3828 if (P->map_count == P->map_alloc) { in Padd_mapping()
3829 size_t next = P->map_alloc ? P->map_alloc * 2 : 16; in Padd_mapping()
3831 if ((P->mappings = realloc(P->mappings, in Padd_mapping()
3835 P->map_alloc = next; in Padd_mapping()
3838 mp = &P->mappings[P->map_count++]; in Padd_mapping()
3872 Psort_mappings(struct ps_prochandle *P) in Psort_mappings() argument
3877 qsort(P->mappings, P->map_count, sizeof (map_info_t), map_sort); in Psort_mappings()
3882 for (i = 0; i < P->map_count; i++) { in Psort_mappings()
3883 mp = &P->mappings[i]; in Psort_mappings()
3893 struct ps_prochandle *P; in Pgrab_ops() local
3895 if ((P = calloc(1, sizeof (*P))) == NULL) { in Pgrab_ops()
3899 Pinit_ops(&P->ops, ops); in Pgrab_ops()
3900 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL); in Pgrab_ops()
3901 P->pid = pid; in Pgrab_ops()
3902 P->state = PS_STOP; in Pgrab_ops()
3903 P->asfd = -1; in Pgrab_ops()
3904 P->ctlfd = -1; in Pgrab_ops()
3905 P->statfd = -1; in Pgrab_ops()
3906 P->agentctlfd = -1; in Pgrab_ops()
3907 P->agentstatfd = -1; in Pgrab_ops()
3908 Pinitsym(P); in Pgrab_ops()
3909 P->data = data; in Pgrab_ops()
3910 Pread_status(P); in Pgrab_ops()
3913 P->flags |= INCORE; in Pgrab_ops()
3916 return (P); in Pgrab_ops()