Home | History | Annotate | Line # | Download | only in ps
nlist.c revision 1.6
      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 
     34 #ifndef lint
     35 /*static char sccsid[] = "from: @(#)nlist.c	5.5 (Berkeley) 7/1/91";*/
     36 static char rcsid[] = "$Id: nlist.c,v 1.6 1994/05/05 02:04:28 cgd Exp $";
     37 #endif /* not lint */
     38 
     39 #include <sys/param.h>
     40 #include <sys/time.h>
     41 #include <sys/proc.h>
     42 #include <nlist.h>
     43 #include <errno.h>
     44 #include <stdio.h>
     45 #include <string.h>
     46 
     47 #ifdef P_PPWAIT
     48 #define NEWVM
     49 #endif
     50 
     51 struct	nlist psnl[] = {
     52 	{"_fscale"},
     53 #define	X_FSCALE	0
     54 	{"_ccpu"},
     55 #define	X_CCPU		1
     56 #ifdef NEWVM
     57 	{"_avail_start"},
     58 #define	X_AVAILSTART	2
     59 	{"_avail_end"},
     60 #define	X_AVAILEND	3
     61 #else
     62 	{"_ecmx"},
     63 #define	X_ECMX		2
     64 #endif
     65 	{NULL}
     66 };
     67 
     68 fixpt_t	ccpu;				/* kernel _ccpu variable */
     69 int	nlistread;			/* if nlist already read. */
     70 int	mempages;			/* number of pages of phys. memory */
     71 int	fscale;				/* kernel _fscale variable */
     72 
     73 #define kread(x, v) \
     74 	kvm_read(psnl[x].n_value, (char *)&v, sizeof v) != sizeof(v)
     75 
     76 donlist()
     77 {
     78 	extern int eval;
     79 	int rval;
     80 #ifdef NEWVM
     81 	int tmp;
     82 #endif
     83 
     84 	rval = 0;
     85 	nlistread = 1;
     86 	if (kvm_nlist(psnl)) {
     87 		nlisterr(psnl);
     88 		eval = 1;
     89 		return(1);
     90 	}
     91 	if (kread(X_FSCALE, fscale)) {
     92 		(void)fprintf(stderr, "ps: fscale: %s\n", kvm_geterr());
     93 		eval = rval = 1;
     94 	}
     95 #ifdef NEWVM
     96 	if (kread(X_AVAILEND, mempages)) {
     97 		(void)fprintf(stderr, "ps: avail_start: %s\n", kvm_geterr());
     98 		eval = rval = 1;
     99 	}
    100 	if (kread(X_AVAILSTART, tmp)) {
    101 		(void)fprintf(stderr, "ps: avail_end: %s\n", kvm_geterr());
    102 		eval = rval = 1;
    103 	}
    104 	mempages -= tmp;
    105 	mempages = mempages / NBPG;			/* 14 Aug 92*/
    106 #else
    107 	if (kread(X_ECMX, mempages)) {
    108 		(void)fprintf(stderr, "ps: ecmx: %s\n", kvm_geterr());
    109 		eval = rval = 1;
    110 	}
    111 #endif
    112 	if (kread(X_CCPU, ccpu)) {
    113 		(void)fprintf(stderr, "ps: ccpu: %s\n", kvm_geterr());
    114 		eval = rval = 1;
    115 	}
    116 	return(rval);
    117 }
    118 
    119 nlisterr(nl)
    120 	struct nlist nl[];
    121 {
    122 	int i;
    123 
    124 	fprintf(stderr, "ps: nlist: can't find following symbols:");
    125 	for (i = 0; nl[i].n_name != NULL; i++)
    126 		if (nl[i].n_value == 0)
    127 			fprintf(stderr, " %s", nl[i].n_name);
    128 	fprintf(stderr, "\n");
    129 }
    130