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 | |
8faab6ff | 9 | static char sccsid[] = "@(#)nlist.c 5.7 (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> |
fd57c467 KB |
16 | #include <nlist.h> |
17 | #include <errno.h> | |
18 | #include <stdio.h> | |
9ed1608e | 19 | #include <string.h> |
967726ab | 20 | #include <kvm.h> |
8faab6ff | 21 | #include "ps.h" |
fd57c467 | 22 | |
6e7a85b8 MK |
23 | #ifdef SPPWAIT |
24 | #define NEWVM | |
25 | #endif | |
26 | ||
fd57c467 | 27 | struct nlist psnl[] = { |
fd57c467 | 28 | {"_fscale"}, |
6e7a85b8 | 29 | #define X_FSCALE 0 |
fd57c467 | 30 | {"_ccpu"}, |
6e7a85b8 MK |
31 | #define X_CCPU 1 |
32 | #ifdef NEWVM | |
33 | {"_avail_start"}, | |
34 | #define X_AVAILSTART 2 | |
35 | {"_avail_end"}, | |
36 | #define X_AVAILEND 3 | |
37 | #else | |
38 | {"_ecmx"}, | |
39 | #define X_ECMX 2 | |
40 | #endif | |
fd57c467 KB |
41 | {NULL} |
42 | }; | |
43 | ||
44 | fixpt_t ccpu; /* kernel _ccpu variable */ | |
45 | int nlistread; /* if nlist already read. */ | |
6e7a85b8 | 46 | int mempages; /* number of pages of phys. memory */ |
fd57c467 KB |
47 | int fscale; /* kernel _fscale variable */ |
48 | ||
967726ab KM |
49 | extern kvm_t *kd; |
50 | ||
fd57c467 | 51 | #define kread(x, v) \ |
967726ab | 52 | kvm_read(kd, psnl[x].n_value, (char *)&v, sizeof v) != sizeof(v) |
fd57c467 | 53 | |
8faab6ff | 54 | int |
fd57c467 KB |
55 | donlist() |
56 | { | |
57 | extern int eval; | |
58 | int rval; | |
6e7a85b8 MK |
59 | #ifdef NEWVM |
60 | int tmp; | |
61 | #endif | |
fd57c467 KB |
62 | |
63 | rval = 0; | |
64 | nlistread = 1; | |
967726ab | 65 | if (kvm_nlist(kd, psnl)) { |
7497154e | 66 | nlisterr(psnl); |
fd57c467 KB |
67 | eval = 1; |
68 | return(1); | |
69 | } | |
70 | if (kread(X_FSCALE, fscale)) { | |
967726ab | 71 | (void)fprintf(stderr, "ps: fscale: %s\n", kvm_geterr(kd)); |
fd57c467 KB |
72 | eval = rval = 1; |
73 | } | |
6e7a85b8 MK |
74 | #ifdef NEWVM |
75 | if (kread(X_AVAILEND, mempages)) { | |
967726ab | 76 | (void)fprintf(stderr, "ps: avail_start: %s\n", kvm_geterr(kd)); |
6e7a85b8 MK |
77 | eval = rval = 1; |
78 | } | |
79 | if (kread(X_AVAILSTART, tmp)) { | |
967726ab | 80 | (void)fprintf(stderr, "ps: avail_end: %s\n", kvm_geterr(kd)); |
6e7a85b8 MK |
81 | eval = rval = 1; |
82 | } | |
83 | mempages -= tmp; | |
84 | #else | |
85 | if (kread(X_ECMX, mempages)) { | |
967726ab | 86 | (void)fprintf(stderr, "ps: ecmx: %s\n", kvm_geterr(kd)); |
fd57c467 KB |
87 | eval = rval = 1; |
88 | } | |
6e7a85b8 | 89 | #endif |
fd57c467 | 90 | if (kread(X_CCPU, ccpu)) { |
967726ab | 91 | (void)fprintf(stderr, "ps: ccpu: %s\n", kvm_geterr(kd)); |
fd57c467 KB |
92 | eval = rval = 1; |
93 | } | |
94 | return(rval); | |
95 | } | |
7497154e | 96 | |
8faab6ff | 97 | void |
7497154e MT |
98 | nlisterr(nl) |
99 | struct nlist nl[]; | |
100 | { | |
101 | int i; | |
102 | ||
8faab6ff | 103 | (void)fprintf(stderr, "ps: nlist: can't find following symbols:"); |
7497154e MT |
104 | for (i = 0; nl[i].n_name != NULL; i++) |
105 | if (nl[i].n_value == 0) | |
8faab6ff KB |
106 | (void)fprintf(stderr, " %s", nl[i].n_name); |
107 | (void)fprintf(stderr, "\n"); | |
7497154e | 108 | } |