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