home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1992 Michael A. Cooper.
- * This software may be freely distributed provided it is not sold for
- * profit and the author is credited appropriately.
- */
- #ifndef lint
- static char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/KVM.c,v 1.15 1992/04/26 23:32:06 mcooper Exp $";
- #endif
-
- /*
- * $Log: KVM.c,v $
- * Revision 1.15 1992/04/26 23:32:06 mcooper
- * Add Copyright notice
- *
- * Revision 1.13 1992/04/17 23:28:33 mcooper
- * Fixed NULL deref bug.
- *
- * Revision 1.12 1992/04/17 01:07:59 mcooper
- * More de-linting
- *
- * Revision 1.11 1992/04/16 02:25:39 mcooper
- * Bug fixes, de-linting, and other changes found with CodeCenter.
- *
- * Revision 1.10 1992/03/31 03:10:17 mcooper
- * Put frontend macro around CheckNlist() to avoid
- * broken things in Ultrix.
- *
- * Revision 1.9 1992/03/31 02:44:20 mcooper
- * Add BROKEN_NLIST_CHECK define.
- *
- * Revision 1.8 1992/03/31 01:54:50 mcooper
- * Add CheckNlist().
- *
- * Revision 1.7 1992/03/31 00:34:42 mcooper
- * Make GetNlName() a macro.
- *
- * Revision 1.6 1992/03/30 23:44:05 mcooper
- * *** empty log message ***
- *
- */
-
-
- /*
- * Frontend functions for kvm_*() functions
- *
- * It is assumed we HAVE_NLIST if we HAVE_KVM.
- */
-
- #include <stdio.h>
- #include "system.h"
-
- #if defined(HAVE_KVM)
-
- #include "defs.h"
-
- #include <fcntl.h>
- #if defined(HAVE_NLIST)
- #include <nlist.h>
- #endif /* HAVE_NLIST */
-
- /*
- * Perform a kvm_close(). Really just hear to be compatible.
- */
- extern void KVM_close(kd)
- kvm_t *kd;
- {
- if (kd)
- (void) kvm_close(kd);
- }
-
- /*
- * Perform a kvm_open() and then a kvm_nlist().
- */
- #if defined(HAVE_NLIST)
- /*
- * Do a kvm_open()
- */
- extern kvm_t *KVM_open(PtrNL)
- struct nlist *PtrNL;
- #else
- etern kvm_t *KVM_open()
- #endif /* HAVE_NLIST */
- {
- kvm_t *kd = NULL;
- extern char *ProgramName;
-
- if ((kd = kvm_open((char *)NULL, (char *)NULL, (char *)NULL, O_RDONLY,
- ProgramName)) == NULL) {
- if (Debug) Error("kvm_open failed: %s.", SYSERR);
- return((kvm_t *) NULL);
- }
-
- #if defined(HAVE_NLIST)
- if (PtrNL)
- if (kvm_nlist(kd, PtrNL) != 0) {
- if (Debug) Error("kvm_nlist name \"%s\" failed: %s.",
- GetNlNamePtr(PtrNL), SYSERR);
- KVM_close(kd);
- return((kvm_t *) NULL);
- }
- #endif /* HAVE_NLIST */
-
- return(kd);
- }
-
- /*
- * Perform a kvm_read().
- */
- extern int KVM_read(kd, Addr, Buf, NumBytes)
- kvm_t *kd;
- u_long Addr;
- char *Buf;
- unsigned NumBytes;
- {
- int Count;
-
- if (!kd)
- return(-1);
-
- if ((Count = kvm_read(kd, Addr, Buf, NumBytes)) != NumBytes) {
- if (Debug) Error("kvm_read failed (expected %d, got %d): %s.",
- NumBytes, Count, SYSERR);
- return(-1);
- }
-
- return(0);
- }
-
- /*
- * Check to see if PtrNL is valid.
- */
- extern int _CheckNlist(PtrNL)
- struct nlist *PtrNL;
- {
- /*
- * Should use n_type, but that's not set
- * correctly on some OS's.
- */
- if (!PtrNL || !PtrNL->n_value) {
- if (Debug) Error("Kernel symbol \"%s\" not found.",
- GetNlNamePtr(PtrNL));
- return(-1);
- }
-
- return(0);
- }
-
- #endif /* HAVE_KVM */
-