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