|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: static char sccsid[] = "@(#)fetch.c 5.1 (Berkeley) 5/30/85";
9: #endif not lint
10:
11: #include "systat.h"
12: #include <sys/dir.h>
13: #include <sys/user.h>
14: #include <sys/proc.h>
15: #include <sys/vmmac.h>
16: #include <machine/pte.h>
17: #include <pwd.h>
18:
19: long
20: getw(loc)
21: int loc;
22: {
23: long word;
24:
25: lseek(kmem, loc, L_SET);
26: if (read(kmem, &word, sizeof (word)) != sizeof (word))
27: printf("Error reading kmem at %x\n", loc);
28: return (word);
29: }
30:
31: char *
32: getpname(pid, mproc)
33: int pid;
34: register struct proc *mproc;
35: {
36: register struct procs *pp;
37: register char *namp;
38: register int j;
39: char *getcmd();
40:
41: pp = procs;
42: for (j = numprocs - 1; j >= 0; j--) {
43: if (pp->pid == pid)
44: return (pp->cmd);
45: pp++;
46: }
47: if (j < 0) {
48: if (numprocs < 200) {
49: pp = &procs[numprocs];
50: namp = strncpy(pp->cmd, getcmd(pid, mproc), 15);
51: pp->cmd[15] = 0;
52: pp->pid = pid;
53: numprocs++;
54: } else
55: namp = getcmd(pid, mproc);
56: }
57: return (namp);
58: }
59:
60: union {
61: struct user user;
62: char upages[UPAGES][NBPG];
63: } user;
64: #define u user.user
65:
66: char *
67: getcmd(pid, mproc)
68: int pid;
69: register struct proc *mproc;
70: {
71: static char cmd[30];
72:
73: if (mproc == NULL || mproc->p_stat == SZOMB)
74: return ("");
75: if (pid == 1)
76: return ("swapper");
77: if (pid == 2)
78: return ("pagedaemon");
79: if (mproc->p_flag&(SSYS|SWEXIT))
80: return ("");
81: if (getu(mproc) == 0)
82: return ("???");
83: (void) strncpy(cmd, u.u_comm, sizeof (cmd));
84: return (cmd);
85: }
86:
87: static int argaddr;
88: static int pcbpf;
89:
90: getu(mproc)
91: register struct proc *mproc;
92: {
93: struct pte *pteaddr, apte;
94: struct pte arguutl[UPAGES+CLSIZE];
95: register int i;
96: int ncl, size;
97:
98: size = sizeof (struct user);
99: if ((mproc->p_flag & SLOAD) == 0) {
100: if (swap < 0)
101: return (0);
102: (void) lseek(swap, (long)dtob(mproc->p_swaddr), L_SET);
103: if (read(swap, (char *)&user.user, size) != size) {
104: error("cant read u for pid %d", mproc->p_pid);
105: return (0);
106: }
107: pcbpf = 0;
108: argaddr = 0;
109: return (1);
110: }
111: pteaddr = &Usrptma[btokmx(mproc->p_p0br) + mproc->p_szpt - 1];
112: klseek(kmem, (long)pteaddr, L_SET);
113: if (read(kmem, (char *)&apte, sizeof (apte)) != sizeof (apte)) {
114: error("cant read indir pte to get u for pid %d", mproc->p_pid);
115: return (0);
116: }
117: klseek(mem,
118: (long)ctob(apte.pg_pfnum+1) - (UPAGES+CLSIZE) * sizeof (struct pte),
119: L_SET);
120: if (read(mem, (char *)arguutl, sizeof (arguutl)) != sizeof (arguutl)) {
121: error("cant read page table for u of pid %d", mproc->p_pid);
122: return (0);
123: }
124: if (arguutl[0].pg_fod == 0 && arguutl[0].pg_pfnum)
125: argaddr = ctob(arguutl[0].pg_pfnum);
126: else
127: argaddr = 0;
128: pcbpf = arguutl[CLSIZE].pg_pfnum;
129: ncl = (size + NBPG*CLSIZE - 1) / (NBPG*CLSIZE);
130: while (--ncl >= 0) {
131: i = ncl * CLSIZE;
132: klseek(mem, (long)ctob(arguutl[CLSIZE+i].pg_pfnum), L_SET);
133: if (read(mem, user.upages[i], CLSIZE*NBPG) != CLSIZE*NBPG) {
134: error("cant read page %d of u of pid %d\n",
135: arguutl[CLSIZE+i].pg_pfnum, mproc->p_pid);
136: return (0);
137: }
138: }
139: return (1);
140: }
141:
142: klseek(fd, loc, off)
143: int fd;
144: long loc;
145: int off;
146: {
147:
148: (void) lseek(fd, (long)loc, off);
149: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.