Lines Matching refs:pctx

72 static void (*pctx_cpc_callback)(cpc_t *cpc, struct __pctx *pctx);
83 pctx_error(pctx_t *pctx, const char *fn, const char *fmt, ...)
88 pctx->errfn(fn, fmt, ap);
105 pctx_t *pctx;
107 pctx = calloc(1, sizeof (*pctx));
108 pctx->uarg = arg;
109 pctx->verbose = verbose;
110 pctx->terminate = 0;
111 pctx->errfn = errfn ? errfn : pctx_default_errfn;
113 if ((pctx->Pr = Pcreate(filename, argv, &err, 0, 0)) == NULL) {
116 pctx_error(pctx, fn, gettext("cannot trace set-id or "
120 pctx_error(pctx, fn, gettext("cannot control LP64 "
124 pctx_error(pctx, fn, gettext("cannot execute "
128 pctx_error(pctx, fn, gettext("cannot find"
132 pctx_error(pctx, fn, gettext("cannot fork, "
136 pctx_error(pctx, fn, gettext("%s, program '%s'\n"),
140 free(pctx);
144 if (Psysentry(pctx->Pr, SYS_exit, 1) == -1) {
145 pctx_error(pctx, fn,
147 Prelease(pctx->Pr, PRELEASE_KILL);
148 free(pctx);
155 pctx->created = 1;
156 (void) Psetflags(pctx->Pr, PR_KLC);
157 (void) pctx_set_events(pctx, PCTX_NULL_EVENT);
159 return (pctx);
170 pctx_t *pctx;
172 pctx = calloc(1, sizeof (*pctx));
173 pctx->uarg = arg;
174 pctx->verbose = verbose;
175 pctx->errfn = errfn ? errfn : pctx_default_errfn;
177 if ((pctx->Pr = Pgrab(pid, 0, &err)) == NULL) {
180 pctx_error(pctx, fn,
184 pctx_error(pctx, fn,
188 pctx_error(pctx, fn,
192 pctx_error(pctx, fn,
197 pctx_error(pctx, fn,
201 pctx_error(pctx, fn,
205 pctx_error(pctx, fn, gettext("cannot control LP64 "
209 pctx_error(pctx, fn, gettext("%s: pid %d\n"),
213 free(pctx);
217 if (Psysentry(pctx->Pr, SYS_exit, 1) == -1) {
218 pctx_error(pctx, fn,
220 Prelease(pctx->Pr, PRELEASE_CLEAR);
221 free(pctx);
231 pctx->created = 0;
232 (void) Psetflags(pctx->Pr, PR_RLC);
233 (void) pctx_set_events(pctx, PCTX_NULL_EVENT);
235 return (pctx);
240 default_void(pctx_t *pctx)
245 default_int(pctx_t *pctx)
251 pctx_set_events(pctx_t *pctx, ...)
258 va_start(pvar, pctx);
264 pctx->exec = (pctx_sysc_execfn_t *)
268 pctx->fork = (pctx_sysc_forkfn_t *)
272 pctx->exit = (pctx_sysc_exitfn_t *)
276 pctx->lwp_create = (pctx_sysc_lwp_createfn_t *)
280 pctx->init_lwp = (pctx_init_lwpfn_t *)
284 pctx->fini_lwp = (pctx_fini_lwpfn_t *)
288 pctx->lwp_exit = (pctx_sysc_lwp_exitfn_t *)
292 pctx_error(pctx, fn,
303 if (pctx->exec == NULL)
304 pctx->exec = (pctx_sysc_execfn_t *)default_int;
305 if (pctx->fork == NULL)
306 pctx->fork = (pctx_sysc_forkfn_t *)default_void;
307 if (pctx->exit == NULL)
308 pctx->exit = (pctx_sysc_exitfn_t *)default_void;
309 if (pctx->lwp_create == NULL)
310 pctx->lwp_create = (pctx_sysc_lwp_createfn_t *)default_int;
311 if (pctx->init_lwp == NULL)
312 pctx->init_lwp = (pctx_init_lwpfn_t *)default_int;
313 if (pctx->fini_lwp == NULL)
314 pctx->fini_lwp = (pctx_fini_lwpfn_t *)default_int;
315 if (pctx->lwp_exit == NULL)
316 pctx->lwp_exit = (pctx_sysc_lwp_exitfn_t *)default_int;
318 if (pctx->fork != (pctx_sysc_forkfn_t *)default_void) {
319 (void) Psysexit(pctx->Pr, SYS_vfork, 1);
320 (void) Psysexit(pctx->Pr, SYS_forksys, 1);
321 if (Psetflags(pctx->Pr, PR_FORK) == -1)
324 (void) Psysexit(pctx->Pr, SYS_vfork, 0);
325 (void) Psysexit(pctx->Pr, SYS_forksys, 0);
326 if (Punsetflags(pctx->Pr, PR_FORK) == -1)
334 if (pctx->exec != (pctx_sysc_execfn_t *)default_int ||
335 pctx->fini_lwp != (pctx_fini_lwpfn_t *)default_int ||
336 pctx->init_lwp != (pctx_init_lwpfn_t *)default_int) {
337 (void) Psysexit(pctx->Pr, SYS_execve, 1);
338 (void) Psysentry(pctx->Pr, SYS_execve, 1);
340 (void) Psysexit(pctx->Pr, SYS_execve, 0);
341 (void) Psysentry(pctx->Pr, SYS_execve, 0);
344 (void) Psysexit(pctx->Pr, SYS_lwp_create,
345 pctx->lwp_create != (pctx_sysc_lwp_createfn_t *)default_int ||
346 pctx->init_lwp != (pctx_init_lwpfn_t *)default_int);
348 (void) Psysentry(pctx->Pr, SYS_lwp_exit,
349 pctx->lwp_exit != (pctx_sysc_lwp_exitfn_t *)default_int ||
350 pctx->fini_lwp != (pctx_fini_lwpfn_t *)default_int);
374 pctx_begin_syscalls(pctx_t *pctx)
376 if (pctx->Pr == NULL)
378 if (pctx->sigblocked++ == 0) {
379 (void) sigprocmask(SIG_BLOCK, &termsig, &pctx->savedset);
380 (void) Pcreate_agent(pctx->Pr);
385 pctx_end_syscalls(pctx_t *pctx)
387 if (pctx->Pr == NULL)
389 if (--pctx->sigblocked == 0) {
390 (void) Pdestroy_agent(pctx->Pr);
391 (void) sigprocmask(SIG_SETMASK, &pctx->savedset, NULL);
400 pctx_lwpiterate(pctx_t *pctx, int (*action)(pctx_t *, pid_t, id_t, void *))
413 pstatus = Pstatus(pctx->Pr);
415 pctx_begin_syscalls(pctx);
416 ret = action(pctx, pstatus->pr_pid, 1, pctx->uarg);
417 pctx_end_syscalls(pctx);
442 pctx_begin_syscalls(pctx);
444 if (action(pctx,
445 pstatus->pr_pid, lwps->pr_lwpid, pctx->uarg) != 0)
450 pctx_end_syscalls(pctx);
461 pctx_free(pctx_t *pctx)
463 if (pctx->cpc != NULL && pctx_cpc_callback != NULL)
464 (*pctx_cpc_callback)(pctx->cpc, pctx);
465 if (pctx->Pr) {
466 Pfree(pctx->Pr);
467 pctx->Pr = NULL;
469 pctx->errfn = pctx_default_errfn;
476 pctx_release(pctx_t *pctx)
478 if (pctx->Pr) {
479 Prelease(pctx->Pr, PRELEASE_CLEAR);
480 pctx->Pr = NULL;
483 pctx_free(pctx);
484 bzero(pctx, sizeof (*pctx));
485 free(pctx);
520 pctx_t *pctx,
533 pid_t pid = Pstatus(pctx->Pr)->pr_pid;
551 if (pctx_lwpiterate(pctx, pctx->init_lwp) != 0) {
552 if (pctx->verbose)
553 pctx_error(pctx, fn,
573 while (running == 1 && !pctx->terminate) {
575 if (Psetrun(pctx->Pr, 0, 0) != 0) {
576 if (pctx->verbose)
577 pctx_error(pctx, fn,
605 } while (mswait == 0 && !pctx->terminate);
608 if (pctx->terminate)
611 (void) Pwait(pctx->Pr, mswait);
614 switch (pstate = Pstate(pctx->Pr)) {
619 if (Pstop(pctx->Pr, 5 * MILLISEC) == -1 ||
620 (pstate = Pstate(pctx->Pr)) != PS_STOP) {
621 pctx_error(pctx, fn,
633 (void) Preopen(pctx->Pr);
634 if ((pstate = Pstate(pctx->Pr)) != PS_LOST)
636 pctx_error(pctx, fn,
643 if (pctx->verbose)
644 pctx_error(pctx, fn,
650 if (pctx->verbose)
651 pctx_error(pctx, fn,
660 pstatus = Pstatus(pctx->Pr);
674 if (pctx_lwpiterate(pctx, tick) != 0)
682 pctx_begin_syscalls(pctx);
683 (void) pctx->fini_lwp(pctx,
684 pid, lwpid, pctx->uarg);
685 (void) pctx->lwp_exit(pctx,
686 pid, lwpid, pctx->uarg);
687 pctx_end_syscalls(pctx);
690 if (pctx_lwpiterate(pctx, pctx->fini_lwp)
693 pctx->exit(pctx, pid, lwpid,
695 pctx->uarg);
700 (void) pctx_lwpiterate(pctx, pctx->fini_lwp);
703 pctx_error(pctx, fn,
718 if (pctx_lwpiterate(pctx,
719 pctx->init_lwp) == 0)
725 if (pctx->exec == (pctx_sysc_execfn_t *)
731 Ppsinfo(pctx->Pr), sizeof (psinfo));
733 pctx_begin_syscalls(pctx);
734 if (pctx->exec(pctx, pid, lwpid,
735 psinfo.pr_psargs, pctx->uarg) != 0)
737 if (running == 1 && pctx->init_lwp(pctx,
738 pid, 1, pctx->uarg) != 0)
740 pctx_end_syscalls(pctx);
746 pctx_begin_syscalls(pctx);
747 if (pctx->init_lwp(pctx, pid, lwpid,
748 pctx->uarg) != 0)
750 if (running == 1 && pctx->lwp_create(pctx,
751 pid, lwpid, pctx->uarg) != 0)
753 pctx_end_syscalls(pctx);
767 wascreated = pctx->created;
768 forkfn = pctx->fork;
769 pctx_free(pctx);
770 pctx = pctx_capture(pid, pctx->uarg,
771 pctx->verbose, pctx->errfn);
772 if (pctx != NULL) {
779 pctx->created = 1;
781 pctx->Pr, PR_KLC);
783 (*forkfn)(pctx, ppid, pid,
784 lwpid, pctx->uarg);
785 pctx_release(pctx);
792 pctx_error(pctx, fn,
802 pctx_error(pctx, fn, gettext(
809 if (pctx->verbose)
810 pctx_error(pctx, fn,
814 if (pctx->verbose)
815 pctx_error(pctx, fn,
821 if (pctx->verbose)
822 pctx_error(pctx, fn,
826 if (pctx->verbose)
827 pctx_error(pctx, fn,
831 if (pctx->verbose)
832 pctx_error(pctx, fn,
837 if (pctx->verbose)
838 pctx_error(pctx, fn,
849 if (pctx->terminate)
858 pctx_error(pctx, fn, gettext("lost control of pid %d\n"),
860 pctx_free(pctx);
870 __pctx_cpc(pctx_t *pctx, cpc_t *cpc,
880 * We store the last cpc_t used by libpctx, so that when this pctx is
884 if (pctx->cpc != NULL && pctx->cpc != cpc && pctx_cpc_callback != NULL)
885 (*pctx_cpc_callback)(pctx->cpc, pctx);
886 pctx->cpc = cpc;
974 error = Psyscall(pctx->Pr, &rval, SYS_cpc, 5, &argd[0]);
985 * notify libcpc when a pctx handle is invalidated.
997 pctx_terminate(struct __pctx *pctx)
999 pctx->terminate = 1;