1 /*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)nlist.c 8.4 (Berkeley) 04/02/94";
10 #endif /* not lint */
11
12 #include <sys/param.h>
13 #include <sys/time.h>
14 #include <sys/proc.h>
15 #include <sys/resource.h>
16
17 #include <err.h>
18 #include <errno.h>
19 #include <kvm.h>
20 #include <nlist.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "ps.h"
25
26 #ifdef P_PPWAIT
27 #define NEWVM
28 #endif
29
30 struct nlist psnl[] = {
31 {"_fscale"},
32 #define X_FSCALE 0
33 {"_ccpu"},
34 #define X_CCPU 1
35 #ifdef NEWVM
36 {"_avail_start"},
37 #define X_AVAILSTART 2
38 {"_avail_end"},
39 #define X_AVAILEND 3
40 #else
41 {"_ecmx"},
42 #define X_ECMX 2
43 #endif
44 {NULL}
45 };
46
47 fixpt_t ccpu; /* kernel _ccpu variable */
48 int nlistread; /* if nlist already read. */
49 int mempages; /* number of pages of phys. memory */
50 int fscale; /* kernel _fscale variable */
51
52 extern kvm_t *kd;
53
54 #define kread(x, v) \
55 kvm_read(kd, psnl[x].n_value, (char *)&v, sizeof v) != sizeof(v)
56
57 int
donlist()58 donlist()
59 {
60 int rval;
61 #ifdef NEWVM
62 int tmp;
63 #endif
64
65 rval = 0;
66 nlistread = 1;
67 if (kvm_nlist(kd, psnl)) {
68 nlisterr(psnl);
69 eval = 1;
70 return (1);
71 }
72 if (kread(X_FSCALE, fscale)) {
73 warnx("fscale: %s", kvm_geterr(kd));
74 eval = rval = 1;
75 }
76 #ifdef NEWVM
77 if (kread(X_AVAILEND, mempages)) {
78 warnx("avail_start: %s", kvm_geterr(kd));
79 eval = rval = 1;
80 }
81 if (kread(X_AVAILSTART, tmp)) {
82 warnx("avail_end: %s", kvm_geterr(kd));
83 eval = rval = 1;
84 }
85 mempages -= tmp;
86 #else
87 if (kread(X_ECMX, mempages)) {
88 warnx("ecmx: %s", kvm_geterr(kd));
89 eval = rval = 1;
90 }
91 #endif
92 if (kread(X_CCPU, ccpu)) {
93 warnx("ccpu: %s", kvm_geterr(kd));
94 eval = rval = 1;
95 }
96 return (rval);
97 }
98
99 void
nlisterr(nl)100 nlisterr(nl)
101 struct nlist nl[];
102 {
103 int i;
104
105 (void)fprintf(stderr, "ps: nlist: can't find following symbols:");
106 for (i = 0; nl[i].n_name != NULL; i++)
107 if (nl[i].n_value == 0)
108 (void)fprintf(stderr, " %s", nl[i].n_name);
109 (void)fprintf(stderr, "\n");
110 }
111