KVM_OPEN(3) BSD Programmer's Manual KVM_OPEN(3)
NAME
kvmopen, kvmopenfiles, kvmclose - initialize kernel virtual memory ac-
cess
SYNOPSIS
#include <kvm.h>
kvmt *
kvmopen(const char *execfile, const char *corefile, char *swapfile,
int flags, const char *errstr)
kvmt *
kvmopenfiles(const char *execfile, const char *corefile, char *swapfile,
int flags, const char *errbuf)
int
kvmclose(kvmt *kd)
DESCRIPTION
The functions kvmopen() and kvmopenfiles() return a descriptor used to
access kernel virtual memory via the kvm(3) library routines. Both ac-
tive kernels and crash dumps are accessible through this interface.
execfile is the executable image of the kernel being examined. This file
must contain a symbol table. If this argument is NULL, the currently
running system is assumed, which is indicated by _PATH_KERNEL in
<paths.h>.
corefile is the kernel memory device file. It can be either /dev/mem or
a crash dump core generated by savecore(8). If corefile is NULL, the de-
fault indicated by _PATH_MEM from <paths.h> is used.
swapfile should indicate the swap device. If NULL, _PATH_DRUM from
<paths.h> is used.
The flags argument indicates read/write access as in open(2) and applies
to only the core file. Only O_RDONLY, O_WRONLY, and O_RDWR are permit-
ted.
There are two open routines which differ only with respect to the error
mechanism. One provides backward compatibility with the SunOS kvm li-
brary, while the other provides an improved error reporting framework.
The kvmopen() function is the Sun kvm compatible open call. Here, the
errstr argument indicates how errors should be handled. If it is NULL,
no errors are reported and the application cannot know the specific na-
ture of the failed kvm call. If it is not NULL, errors are printed to
stderr with errstr prepended to the message, as in perror(3). Normally,
the name of the program is used here. The string is assumed to persist
at least until the corresponding kvmclose() call.
The kvmopenfiles() function provides BSD style error reporting. Here,
error messages are not printed out by the library. Instead, the applica-
tion obtains the error message corresponding to the most recent kvm li-
brary call using kvmgeterr() (see kvm_geterr(3)). The results are unde-
fined if the most recent kvm call did not produce an error. Since
kvmgeterr() requires a kvm descriptor, but the open routines return NULL
on failure, kvmgeterr() cannot be used to get the error message if open
fails. Thus, kvmopenfiles() will place any error message in the errbuf
argument. This buffer should be _POSIX2_LINE_MAX characters large (from
<limits.h>).
RETURN VALUES
The kvmopen() and kvmopenfiles() functions both return a descriptor to
be used in all subsequent kvm library calls. The library is fully re-
entrant. On failure, NULL is returned, in which case kvmopenfiles()
writes the error message into errbuf.
The kvmclose() function returns 0 on sucess and -1 on failure.
BUGS
There should not be two open calls. The ill-defined error semantics of
the Sun library and the desire to have a backward-compatible library for
BSD left little choice.
SEE ALSO
open(2), kvm(3), kvm_getargv(3), kvm_getenvv(3), kvm_geterr(3),
kvm_getprocs(3), kvm_nlist(3), kvm_read(3), kvm_write(3)
BSDI BSD/386 March 26, 1993 2