• Home
  • Raw
  • Download

Lines Matching refs:tcp

190 	struct tcb *tcp;  local
200 for (tcp = tcbtab[0]; tcp < &tcbtab[0][tcbtabsize]; ++tcp)
201 tcbtab[tcp - tcbtab[0]] = &tcbtab[0][tcp - tcbtab[0]];
282 if ((tcp = alloctcb(pid)) == NULL) {
287 tcp->flags |= TCB_ATTACHED;
406 tcp = tcbtab[c];
408 tcp->outf = outf;
409 if (!(tcp->flags & TCB_INUSE) || !(tcp->flags & TCB_ATTACHED))
412 if (proc_open(tcp, 1) < 0) {
414 droptcb(tcp);
419 if (tcp->flags & TCB_CLONE_THREAD)
424 sprintf(procdir, "/proc/%d/task", tcp->pid);
444 tcp = NULL;
446 tcp = alloctcb(tid);
447 if (tcp == NULL) {
452 tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_CLONE_DETACHED|TCB_FOLLOWFORK;
456 tcp->parent = tcbtab[c];
462 droptcb(tcp);
470 tcp->pid, ntid);
474 tcp->pid);
480 if (ptrace(PTRACE_ATTACH, tcp->pid, (char *) 1, 0) < 0) {
482 droptcb(tcp);
489 tcp->pid);
632 if ((tcp = alloctcb(pid)) == NULL) {
638 if (proc_open(tcp, 0) < 0) {
692 newoutf(tcp) in newoutf() argument
693 struct tcb *tcp; in newoutf()
699 sprintf(name, "%s.%u", outfname, tcp->pid);
711 tcp->outf = fp;
748 struct tcb *tcp; local
751 tcp = tcbtab[i];
752 if ((tcp->flags & TCB_INUSE) == 0) {
753 tcp->pid = pid;
754 tcp->parent = NULL;
755 tcp->nchildren = 0;
756 tcp->nzombies = 0;
758 tcp->nclone_threads = tcp->nclone_detached = 0;
759 tcp->nclone_waiting = 0;
761 tcp->flags = TCB_INUSE | TCB_STARTUP;
762 tcp->outf = outf; /* Initialise to current out file */
763 tcp->stime.tv_sec = 0;
764 tcp->stime.tv_usec = 0;
765 tcp->pfd = -1;
767 return tcp;
775 proc_open(tcp, attaching) in proc_open() argument
776 struct tcb *tcp; in proc_open()
793 sprintf(proc, "/proc/%d/ctl", tcp->pid);
794 if ((tcp->pfd = open(proc, O_WRONLY|O_EXCL)) < 0) {
798 if ((arg = fcntl(tcp->pfd, F_GETFD)) < 0) {
802 if (fcntl(tcp->pfd, F_SETFD, arg|FD_CLOEXEC) < 0) {
806 sprintf(proc, "/proc/%d/status", tcp->pid);
807 if ((tcp->pfd_stat = open(proc, O_RDONLY|O_EXCL)) < 0) {
811 if ((arg = fcntl(tcp->pfd_stat, F_GETFD)) < 0) {
815 if (fcntl(tcp->pfd_stat, F_SETFD, arg|FD_CLOEXEC) < 0) {
819 sprintf(proc, "/proc/%d/as", tcp->pid);
820 if ((tcp->pfd_as = open(proc, O_RDONLY|O_EXCL)) < 0) {
824 if ((arg = fcntl(tcp->pfd_as, F_GETFD)) < 0) {
828 if (fcntl(tcp->pfd_as, F_SETFD, arg|FD_CLOEXEC) < 0) {
835 sprintf(proc, "/proc/%d", tcp->pid);
836 if ((tcp->pfd = open(proc, O_RDWR|O_EXCL)) < 0) {
838 sprintf(proc, "/proc/%d/mem", tcp->pid);
839 if ((tcp->pfd = open(proc, O_RDWR)) < 0) {
844 if ((arg = fcntl(tcp->pfd, F_GETFD)) < 0) {
848 if (fcntl(tcp->pfd, F_SETFD, arg|FD_CLOEXEC) < 0) {
854 sprintf(proc, "/proc/%d/regs", tcp->pid);
855 if ((tcp->pfd_reg = open(proc, O_RDONLY)) < 0) {
860 sprintf(proc, "/proc/%d/status", tcp->pid);
861 if ((tcp->pfd_status = open(proc, O_RDONLY)) < 0) {
866 tcp->pfd_status = -1;
875 if (IOCTL_STATUS (tcp) < 0) {
879 if (tcp->status.PR_FLAGS & PR_ASLEEP)
885 if (IOCTL(tcp->pfd, PIOCSTOP, (char *)NULL) < 0) {
893 if (IOCTL(tcp->pfd, PIOCSET, &arg) < 0) {
899 if (IOCTL(tcp->pfd, followfork ? PIOCSET : PIOCRESET, &arg) < 0) {
905 if (ioctl(tcp->pfd, PIOCSRLC) < 0) {
909 if (ioctl(tcp->pfd, followfork ? PIOCSFORK : PIOCRFORK) < 0) {
915 if (ioctl(tcp->pfd, PIOCGFL, &arg) < 0) {
920 if (ioctl(tcp->pfd, PIOCSFL, arg) < 0) {
949 if (IOCTL(tcp->pfd, PIOCSENTRY, &syscalls) < 0) {
954 if (IOCTL(tcp->pfd, PIOCSEXIT, &syscalls) < 0) {
964 if (IOCTL(tcp->pfd, PIOCSTRACE, &signals) < 0) {
974 if (IOCTL(tcp->pfd, PIOCSFAULT, &faults) < 0) {
981 if(ioctl(tcp->pfd, PIOCBIS, arg) < 0) {
992 kill(tcp->pid, SIGINT);
997 if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0) {
1005 kill(tcp->pid, SIGCONT);
1009 if (IOCTL_WSTOP (tcp) < 0) {
1013 if (tcp->status.PR_WHY == PR_SYSENTRY) {
1014 tcp->flags &= ~TCB_INSYSCALL;
1015 get_scno(tcp);
1016 if (known_scno(tcp) == SYS_execve)
1022 if (IOCTL(tcp->pfd, PIOCRUN, &arg) < 0) {
1024 if (IOCTL(tcp->pfd, PIOCRUN, 0) < 0) {
1032 if (tcp->status.PR_WHY == PR_SIGNALLED &&
1033 tcp->status.PR_WHAT == SIGSTOP)
1034 kill(tcp->pid, SIGCONT);
1050 sprintf(proc, "/proc/%d/status", tcp->pid);
1059 tcp->flags &= ~(TCB_INSYSCALL|TCB_STARTUP);
1060 tcp->status.PR_WHY = PR_SYSENTRY;
1061 trace_syscall(tcp);
1070 proc_poller(tcp->pfd);
1074 proc_poller(tcp->pfd);
1076 last_pfd = tcp->pfd;
1088 struct tcb *tcp; local
1091 tcp = tcbtab[i];
1092 if (pid && tcp->pid != pid)
1094 if (tcp->flags & TCB_INUSE)
1095 return tcp;
1109 struct tcb *tcp = tcbtab[i]; local
1110 if (tcp->pfd != pfd)
1112 if (tcp->flags & TCB_INUSE)
1113 return tcp;
1121 droptcb(tcp) in droptcb() argument
1122 struct tcb *tcp; in droptcb()
1124 if (tcp->pid == 0)
1127 if (tcp->nclone_threads > 0) {
1132 tcp->flags |= TCB_EXITING;
1137 tcp->pid = 0;
1139 if (tcp->parent != NULL) {
1140 tcp->parent->nchildren--;
1142 if (tcp->flags & TCB_CLONE_DETACHED)
1143 tcp->parent->nclone_detached--;
1144 if (tcp->flags & TCB_CLONE_THREAD)
1145 tcp->parent->nclone_threads--;
1148 if (!(tcp->flags & TCB_CLONE_DETACHED))
1150 tcp->parent->nzombies++;
1151 tcp->parent = NULL;
1154 tcp->flags = 0;
1155 if (tcp->pfd != -1) {
1156 close(tcp->pfd);
1157 tcp->pfd = -1;
1159 if (tcp->pfd_reg != -1) {
1160 close(tcp->pfd_reg);
1161 tcp->pfd_reg = -1;
1163 if (tcp->pfd_status != -1) {
1164 close(tcp->pfd_status);
1165 tcp->pfd_status = -1;
1173 if (outfname && followfork > 1 && tcp->outf)
1174 fclose(tcp->outf);
1176 tcp->outf = 0;
1182 resume(tcp) in resume() argument
1183 struct tcb *tcp; in resume()
1185 if (tcp == NULL)
1188 if (!(tcp->flags & TCB_SUSPENDED)) {
1189 fprintf(stderr, "PANIC: pid %u not suspended\n", tcp->pid);
1192 tcp->flags &= ~TCB_SUSPENDED;
1194 if (tcp->flags & TCB_CLONE_THREAD)
1195 tcp->parent->nclone_waiting--;
1198 if (ptrace(PTRACE_SYSCALL, tcp->pid, (char *) 1, 0) < 0) {
1204 fprintf(stderr, "Process %u resumed\n", tcp->pid);
1213 detach(tcp, sig) in detach() argument
1214 struct tcb *tcp; in detach()
1222 if (tcp->flags & TCB_BPTSET)
1235 if ((error = ptrace(PTRACE_DETACH, tcp->pid, (char *) 1, sig)) == 0) {
1242 else if (kill(tcp->pid, 0) < 0) {
1246 else if (kill(tcp->pid, SIGSTOP) < 0) {
1253 if (wait4(tcp->pid, &status, __WALL, NULL) < 0) {
1262 if (waitpid(tcp->pid, &status, 0) < 0) {
1269 if (wait4(tcp->pid, &status, __WCLONE,
1286 tcp->pid, (char *) 1, sig)) < 0) {
1293 if ((error = ptrace(PTRACE_CONT, tcp->pid, (char *) 1,
1306 if (sig && kill(tcp->pid, sig) < 0)
1309 if ((error = ptrace(PTRACE_DETACH, tcp->pid, (char *) 1, sig)) < 0)
1332 if (tcp->parent &&
1333 (tcp->parent->flags & TCB_SUSPENDED) &&
1334 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid)) {
1335 error = resume(tcp->parent);
1339 if (tcp->parent && tcp->parent->nclone_waiting > 0) {
1346 if (t->parent == tcp->parent && t != tcp
1349 && t->waitpid == tcp->pid) {
1359 if (t->parent == tcp->parent && t != tcp
1375 fprintf(stderr, "Process %u detached\n", tcp->pid);
1377 droptcb(tcp);
1392 struct tcb *tcp;
1394 tcp = pid2tcb(pid);
1395 if (tcp)
1396 droptcb(tcp);
1407 struct tcb *tcp; in cleanup() local
1410 tcp = tcbtab[i]; in cleanup()
1411 if (!(tcp->flags & TCB_INUSE)) in cleanup()
1415 "cleanup: looking at pid %u\n", tcp->pid); in cleanup()
1417 (!outfname || followfork < 2 || tcp_last == tcp)) { in cleanup()
1421 if (tcp->flags & TCB_ATTACHED) in cleanup()
1422 detach(tcp, 0); in cleanup()
1424 kill(tcp->pid, SIGCONT); in cleanup()
1425 kill(tcp->pid, SIGTERM); in cleanup()
1505 struct tcb *tcp = tcbtab[i]; in rebuild_pollv() local
1506 if (!(tcp->flags & TCB_INUSE)) in rebuild_pollv()
1508 pollv[j].fd = tcp->pfd; in rebuild_pollv()
1659 struct tcb *tcp; in choose_pfd() local
1670 tcp = pfd2tcb(pollv[last].fd); in choose_pfd()
1671 if (tcp && (tcp->flags & TCB_INSYSCALL)) in choose_pfd()
1679 tcp = pfd2tcb(pollv[j].fd); in choose_pfd()
1680 if (!tcp) { in choose_pfd()
1684 droptcb(tcp); in choose_pfd()
1702 struct tcb *tcp; local
1720 tcp = pid2tcb(0);
1721 if (!tcp)
1723 pfd = tcp->pfd;
1740 tcp = in_syscall;
1742 pv.fd = tcp->pfd;
1774 if ((tcp = pfd2tcb(pfd)) == NULL) {
1784 ioctl_result = IOCTL_WSTOP (tcp);
1790 ioctl_result = IOCTL_STATUS (tcp);
1792 ioctl_result = IOCTL_WSTOP (tcp);
1820 droptcb(tcp);
1829 if ((tcp->flags & TCB_STARTUP) && (tcp->status.PR_WHY == PR_SYSEXIT)) {
1831 IOCTL (tcp->pfd, PIOCRUN, 0);
1837 tcp->flags &= ~TCB_STARTUP;
1840 outf = tcp->outf;
1848 if ((len = pread(tcp->pfd_status, buf, sizeof(buf) - 1, 0)) > 0) {
1856 stime.tv_sec = tcp->status.pr_stime.tv_sec;
1857 stime.tv_usec = tcp->status.pr_stime.tv_nsec/1000;
1859 tv_sub(&tcp->dtime, &stime, &tcp->stime);
1860 tcp->stime = stime;
1862 what = tcp->status.PR_WHAT;
1863 switch (tcp->status.PR_WHY) {
1866 if (tcp->status.PR_FLAGS & PR_ASLEEP) {
1867 tcp->status.PR_WHY = PR_SYSENTRY;
1868 if (trace_syscall(tcp) < 0) {
1877 in_syscall = tcp;
1880 if (trace_syscall(tcp) < 0) {
1887 printleader(tcp);
1890 printtrailer(tcp);
1892 if (tcp->status.PR_INFO.si_signo == what) {
1893 printleader(tcp);
1895 printsiginfo(&tcp->status.PR_INFO, 1);
1896 printtrailer(tcp);
1903 printleader(tcp);
1905 printtrailer(tcp);
1913 fprintf(stderr, "odd stop %d\n", tcp->status.PR_WHY);
1919 if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0) {
1921 if (IOCTL (tcp->pfd, PIOCRUN, 0) < 0) {
1940 handle_group_exit(struct tcb *tcp, int sig) argument
1944 struct tcb *leader = ((tcp->flags & TCB_CLONE_THREAD)
1945 ? tcp->parent
1946 : tcp->nclone_detached > 0
1947 ? tcp : NULL);
1950 if (leader != NULL && leader != tcp &&
1954 tcp->pid, leader ? leader->pid : -1);
1955 droptcb(tcp); /* Already died. */
1958 if (tcp->flags & TCB_ATTACHED) {
1959 if (leader != NULL && leader != tcp) {
1977 tcp->pid, sig, leader->pid);
1983 detach(tcp, sig);
1985 else if (ptrace(PTRACE_CONT, tcp->pid, (char *) 1, sig) < 0) {
1993 if (leader != NULL && leader != tcp)
1994 droptcb(tcp);
2011 struct tcb *tcp; local
2083 if ((tcp = pid2tcb(pid)) == NULL) {
2095 if ((tcp = alloctcb(pid)) == NULL) {
2100 tcp->flags |= TCB_ATTACHED | TCB_SUSPENDED;
2101 newoutf(tcp);
2119 outf = tcp->outf;
2122 tv_sub(&tcp->dtime, &ru.ru_stime, &tcp->stime);
2123 tcp->stime = ru.ru_stime;
2127 if (tcp->flags & TCB_SUSPENDED) {
2141 printleader(tcp);
2148 printtrailer(tcp);
2151 handle_group_exit(tcp, -1);
2153 droptcb(tcp);
2160 if ((tcp->flags & TCB_ATTACHED)
2162 && !(tcp->parent && (tcp->parent->flags &
2169 if (tcp == tcp_last) {
2170 if ((tcp->flags & (TCB_INSYSCALL|TCB_REPRINT))
2177 handle_group_exit(tcp, -1);
2179 droptcb(tcp);
2185 droptcb(tcp);
2192 if (tcp->flags & TCB_STARTUP) {
2198 tcp->flags &= ~TCB_STARTUP;
2199 if (tcp->flags & TCB_ATTACHED) {
2209 detach(tcp, WSTOPSIG(status));
2217 fixvfork(tcp);
2220 if (tcp->flags & TCB_BPTSET) {
2221 if (clearbpt(tcp) < 0) /* Pretty fatal */ {
2222 droptcb(tcp);
2232 (tcp->flags & TCB_SIGTRAPPED)) {
2237 tcp->flags &= ~(TCB_INSYSCALL | TCB_SIGTRAPPED);
2270 printleader(tcp);
2274 printtrailer(tcp);
2276 if (((tcp->flags & TCB_ATTACHED) ||
2277 tcp->nclone_threads > 0) &&
2278 !sigishandled(tcp, WSTOPSIG(status))) {
2280 handle_group_exit(tcp, WSTOPSIG(status));
2282 detach(tcp, WSTOPSIG(status));
2292 tcp->flags &= ~TCB_SUSPENDED;
2295 if (trace_syscall(tcp) < 0) {
2296 if (tcp->flags & TCB_ATTACHED)
2297 detach(tcp, 0);
2300 tcp->pid, (char *) 1, SIGTERM);
2301 droptcb(tcp);
2305 if (tcp->flags & TCB_EXITING) {
2307 if (tcp->flags & TCB_GROUP_EXITING) {
2308 if (handle_group_exit(tcp, 0) < 0)
2313 if (tcp->flags & TCB_ATTACHED)
2314 detach(tcp, 0);
2322 if (tcp->flags & TCB_SUSPENDED) {
2374 printleader(tcp) argument
2375 struct tcb *tcp;
2377 if (tcp_last && (!outfname || followfork < 2 || tcp_last == tcp)) {
2383 tprintf("%-5d ", tcp->pid);
2385 tprintf("[pid %5u] ", tcp->pid);
2414 printcall(tcp);
2426 printtrailer(tcp) argument
2427 struct tcb *tcp;