Commit | Line | Data |
---|---|---|
be172dde | 1 | #ifndef lint |
d830bff6 | 2 | static char sccsid[] = "@(#)fetch.c 1.3 (Lucasfilm) %G%"; |
be172dde SL |
3 | #endif |
4 | ||
5 | #include "systat.h" | |
6 | ||
7 | long | |
8 | getw(loc) | |
9 | int loc; | |
10 | { | |
11 | long word; | |
12 | ||
13 | lseek(kmem, loc, L_SET); | |
14 | if (read(kmem, &word, sizeof (word)) != sizeof (word)) | |
15 | printf("Error reading kmem at %x\n", loc); | |
16 | return (word); | |
17 | } | |
18 | ||
19 | char * | |
20 | getpname(pid, mproc) | |
21 | int pid; | |
22 | register struct proc *mproc; | |
23 | { | |
24 | register struct procs *pp; | |
25 | register char *namp; | |
26 | register int j; | |
27 | char *getcmd(); | |
28 | ||
29 | pp = procs; | |
30 | for (j = numprocs - 1; j >= 0; j--) { | |
31 | if (pp->pid == pid) | |
32 | return (pp->cmd); | |
33 | pp++; | |
34 | } | |
35 | if (j < 0) { | |
36 | if (numprocs < 200) { | |
37 | pp = &procs[numprocs]; | |
38 | namp = strncpy(pp->cmd, getcmd(pid, mproc), 15); | |
39 | pp->cmd[15] = 0; | |
40 | pp->pid = pid; | |
41 | numprocs++; | |
42 | } else | |
43 | namp = getcmd(pid, mproc); | |
44 | } | |
45 | return (namp); | |
46 | } | |
47 | ||
48 | union { | |
49 | struct user user; | |
50 | char upages[UPAGES][NBPG]; | |
51 | } user; | |
52 | #define u user.user | |
53 | ||
54 | char * | |
55 | getcmd(pid, mproc) | |
56 | int pid; | |
57 | register struct proc *mproc; | |
58 | { | |
59 | static char cmd[30]; | |
60 | ||
852c7064 SL |
61 | if (mproc == NULL || mproc->p_stat == SZOMB) |
62 | return (""); | |
63 | if (pid == 1) | |
64 | return ("swapper"); | |
65 | if (pid == 2) | |
66 | return ("pagedaemon"); | |
67 | if (mproc->p_flag&(SSYS|SWEXIT)) | |
be172dde | 68 | return (""); |
852c7064 SL |
69 | if (getu(mproc) == 0) |
70 | return ("???"); | |
be172dde SL |
71 | (void) strncpy(cmd, u.u_comm, sizeof (cmd)); |
72 | return (cmd); | |
73 | } | |
74 | ||
d830bff6 SL |
75 | static int argaddr; |
76 | static int pcbpf; | |
77 | ||
be172dde SL |
78 | getu(mproc) |
79 | register struct proc *mproc; | |
80 | { | |
81 | struct pte *pteaddr, apte; | |
82 | struct pte arguutl[UPAGES+CLSIZE]; | |
83 | register int i; | |
84 | int ncl, size; | |
85 | ||
86 | size = sizeof (struct user); | |
87 | if ((mproc->p_flag & SLOAD) == 0) { | |
88 | if (swap < 0) | |
89 | return (0); | |
90 | (void) lseek(swap, (long)dtob(mproc->p_swaddr), L_SET); | |
91 | if (read(swap, (char *)&user.user, size) != size) { | |
852c7064 | 92 | error("cant read u for pid %d", mproc->p_pid); |
be172dde SL |
93 | return (0); |
94 | } | |
95 | pcbpf = 0; | |
96 | argaddr = 0; | |
97 | return (1); | |
98 | } | |
99 | pteaddr = &Usrptma[btokmx(mproc->p_p0br) + mproc->p_szpt - 1]; | |
100 | klseek(kmem, (long)pteaddr, L_SET); | |
101 | if (read(kmem, (char *)&apte, sizeof (apte)) != sizeof (apte)) { | |
852c7064 | 102 | error("cant read indir pte to get u for pid %d", mproc->p_pid); |
be172dde SL |
103 | return (0); |
104 | } | |
105 | klseek(mem, | |
106 | (long)ctob(apte.pg_pfnum+1) - (UPAGES+CLSIZE) * sizeof (struct pte), | |
107 | L_SET); | |
108 | if (read(mem, (char *)arguutl, sizeof (arguutl)) != sizeof (arguutl)) { | |
852c7064 | 109 | error("cant read page table for u of pid %d", mproc->p_pid); |
be172dde SL |
110 | return (0); |
111 | } | |
112 | if (arguutl[0].pg_fod == 0 && arguutl[0].pg_pfnum) | |
113 | argaddr = ctob(arguutl[0].pg_pfnum); | |
114 | else | |
115 | argaddr = 0; | |
116 | pcbpf = arguutl[CLSIZE].pg_pfnum; | |
117 | ncl = (size + NBPG*CLSIZE - 1) / (NBPG*CLSIZE); | |
118 | while (--ncl >= 0) { | |
119 | i = ncl * CLSIZE; | |
120 | klseek(mem, (long)ctob(arguutl[CLSIZE+i].pg_pfnum), L_SET); | |
121 | if (read(mem, user.upages[i], CLSIZE*NBPG) != CLSIZE*NBPG) { | |
852c7064 SL |
122 | error("cant read page %d of u of pid %d\n", |
123 | arguutl[CLSIZE+i].pg_pfnum, mproc->p_pid); | |
124 | return (0); | |
be172dde SL |
125 | } |
126 | } | |
127 | return (1); | |
128 | } | |
129 | ||
130 | klseek(fd, loc, off) | |
131 | int fd; | |
132 | long loc; | |
133 | int off; | |
134 | { | |
135 | ||
136 | (void) lseek(fd, (long)loc, off); | |
137 | } |