Home | History | Annotate | Line # | Download | only in ps
nlist.c revision 1.2
      1 /*-
      2  * Copyright (c) 1990 The Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
     34  * --------------------         -----   ----------------------
     35  * CURRENT PATCH LEVEL:         1       00051
     36  * --------------------         -----   ----------------------
     37  *
     38  * 14 Aug 92	David Greenman		Fixed NEWVM mempages calculation
     39  */
     40 
     41 #ifndef lint
     42 static char sccsid[] = "@(#)nlist.c	5.5 (Berkeley) 7/1/91";
     43 #endif /* not lint */
     44 
     45 #include <sys/param.h>
     46 #include <sys/time.h>
     47 #include <sys/proc.h>
     48 #include <nlist.h>
     49 #include <errno.h>
     50 #include <stdio.h>
     51 #include <string.h>
     52 
     53 #ifdef SPPWAIT
     54 #define NEWVM
     55 #endif
     56 
     57 struct	nlist psnl[] = {
     58 	{"_fscale"},
     59 #define	X_FSCALE	0
     60 	{"_ccpu"},
     61 #define	X_CCPU		1
     62 #ifdef NEWVM
     63 	{"_avail_start"},
     64 #define	X_AVAILSTART	2
     65 	{"_avail_end"},
     66 #define	X_AVAILEND	3
     67 #else
     68 	{"_ecmx"},
     69 #define	X_ECMX		2
     70 #endif
     71 	{NULL}
     72 };
     73 
     74 fixpt_t	ccpu;				/* kernel _ccpu variable */
     75 int	nlistread;			/* if nlist already read. */
     76 int	mempages;			/* number of pages of phys. memory */
     77 int	fscale;				/* kernel _fscale variable */
     78 
     79 #define kread(x, v) \
     80 	kvm_read(psnl[x].n_value, (char *)&v, sizeof v) != sizeof(v)
     81 
     82 donlist()
     83 {
     84 	extern int eval;
     85 	int rval;
     86 #ifdef NEWVM
     87 	int tmp;
     88 #endif
     89 
     90 	rval = 0;
     91 	nlistread = 1;
     92 	if (kvm_nlist(psnl)) {
     93 		nlisterr(psnl);
     94 		eval = 1;
     95 		return(1);
     96 	}
     97 	if (kread(X_FSCALE, fscale)) {
     98 		(void)fprintf(stderr, "ps: fscale: %s\n", kvm_geterr());
     99 		eval = rval = 1;
    100 	}
    101 #ifdef NEWVM
    102 	if (kread(X_AVAILEND, mempages)) {
    103 		(void)fprintf(stderr, "ps: avail_start: %s\n", kvm_geterr());
    104 		eval = rval = 1;
    105 	}
    106 	if (kread(X_AVAILSTART, tmp)) {
    107 		(void)fprintf(stderr, "ps: avail_end: %s\n", kvm_geterr());
    108 		eval = rval = 1;
    109 	}
    110 	mempages -= tmp;
    111 	mempages = mempages / NBPG;			/* 14 Aug 92*/
    112 #else
    113 	if (kread(X_ECMX, mempages)) {
    114 		(void)fprintf(stderr, "ps: ecmx: %s\n", kvm_geterr());
    115 		eval = rval = 1;
    116 	}
    117 #endif
    118 	if (kread(X_CCPU, ccpu)) {
    119 		(void)fprintf(stderr, "ps: ccpu: %s\n", kvm_geterr());
    120 		eval = rval = 1;
    121 	}
    122 	return(rval);
    123 }
    124 
    125 nlisterr(nl)
    126 	struct nlist nl[];
    127 {
    128 	int i;
    129 
    130 	fprintf(stderr, "ps: nlist: can't find following symbols:");
    131 	for (i = 0; nl[i].n_name != NULL; i++)
    132 		if (nl[i].n_value == 0)
    133 			fprintf(stderr, " %s", nl[i].n_name);
    134 	fprintf(stderr, "\n");
    135 }
    136