home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / bin / ps / nlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  3.6 KB  |  128 lines

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