This is KVM.c in view mode; [Download] [Up]
/*
* 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.16 1992/11/24 04:05:57 mcooper Exp mcooper $";
#endif
/*
* $Log: KVM.c,v $
* Revision 1.16 1992/11/24 04:05:57 mcooper
* New/cleaner KVM/nlist interface.
*
* 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 KVMclose(kd)
kvm_t *kd;
{
if (kd)
(void) kvm_close(kd);
}
/*
* Perform a kvm_open().
*/
extern kvm_t *KVMopen()
{
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);
}
return(kd);
}
#if defined(HAVE_NLIST)
#if defined(__MACH__)
#define NL_NAME(p) p->n_un.n_name
#else
#define NL_NAME(p) p->n_name
#endif /* __MACH__ */
/*
* Perform an nlist on "kd" looking for "Symbol".
* If NlistPtr is not NULL, use it for storage.
* Return the a pointer to the found nlist structure.
*/
extern struct nlist *KVMnlist(kd, Symbol, NlistPtr)
kvm_t *kd;
char *Symbol;
struct nlist *NlistPtr;
{
static struct nlist nlistbuf;
struct nlist *nlptr;
if (NlistPtr)
nlptr = NlistPtr;
else
nlptr = &nlistbuf;
#if defined(COFF)
/*
* Skip over initial '_'
*/
if (*Symbol == '_')
NL_NAME(nlptr) = Symbol + 1;
else
#endif
NL_NAME(nlptr) = Symbol;
if (kvm_nlist(kd, nlptr) != 0) {
if (Debug) Error("kvm_nlist name \"%s\" failed: %s.",
NL_NAME(nlptr), SYSERR);
KVMclose(kd);
return((struct nlist *) NULL);
}
return(nlptr);
}
#endif /* HAVE_NLIST */
/*
* Perform a kvm_read().
*/
extern int KVMread(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 */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.