kvm_open, kvm_openfiles, kvm_close - initialize kernel virtual memory access
kvm_open(const char *execfile, const char *corefile, char
int flags, const char *errstr);
kvm_openfiles(const char *execfile, const char *corefile,
int flags, char *errbuf);
The functions kvm_open() and kvm_openfiles() return a descriptor used to
access kernel virtual memory via the kvm(3) library routines. Both active
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
running system is assumed, which is indicated by
_PATH_KSYMS, if it exists,
otherwise _PATH_UNIX is used. Both are defined in
corefile is the kernel memory device file. It can be either
a crash dump core generated by savecore(8). If corefile is
NULL, the default
indicated by _PATH_MEM from <paths.h> is used.
swapfile should indicate the swap device. If NULL,
<paths.h> is used.
The flags argument indicates read/write access as in open(2)
only to the core file. Only O_RDONLY, O_WRONLY, and O_RDWR
A special value KVM_NO_FILES can be specified which
will cause no
files to be opened and the handle can only be used on live
kernels on a
limited subset of all kvm operations.
There are two open routines which differ only with respect
to the error
mechanism. One provides backward compatibility with the
SunOS kvm library,
while the other provides an improved error reporting
The kvm_open() function is the Sun kvm compatible open call.
errstr argument indicates how errors should be handled. If
it is NULL,
no errors are reported and the application cannot know the
of the failed kvm call. If it is not NULL, errors are
stderr with errstr prepended to the message, as in perror(3). Normally,
the name of the program is used here. The string is assumed
at least until the corresponding kvm_close() call.
The kvm_openfiles() function provides BSD style error reporting. Here,
error messages are not printed out by the library. Instead,
obtains the error message corresponding to the most recent kvm library
call using kvm_geterr() (see kvm_geterr(3)). The results are undefined
if the most recent kvm call did not produce an error.
kvm_geterr() requires a kvm descriptor, but the open routines return NULL
on failure, kvm_geterr() cannot be used to get the error
message if open
fails. Thus, kvm_openfiles() will place any error message
in the errbuf
argument. This buffer should be _POSIX2_LINE_MAX characters
The kvm_open() and kvm_openfiles() functions both return a
be used in all subsequent kvm library calls. The library is
On failure, NULL is returned, in which case
writes the error message into errbuf.
The kvm_close() function returns 0 on success and -1 on
open(2), kvm(3), kvm_getargv(3), kvm_getenvv(3),
kvm_getprocs(3), kvm_nlist(3), kvm_read(3), kvm_write(3)
There should not be two open calls. The ill-defined error
the Sun library and the desire to have a backward-compatible
BSD left little choice.
OpenBSD 3.6 April 19, 1994
[ Back ]