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