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