Linux and UNIX Man Pages

Test Your Knowledge in Computers #498
Difficulty: Medium
Learning a computer programming language is harder than learning a new spoken language.
True or False?
Linux & Unix Commands - Search Man Pages

kvm_open(3) [freebsd man page]

KVM_OPEN(3)						   BSD Library Functions Manual 					       KVM_OPEN(3)

kvm_open, kvm_openfiles, kvm_close -- initialize kernel virtual memory access LIBRARY
Kernel Data Access Library (libkvm, -lkvm) SYNOPSIS
#include <fcntl.h> #include <kvm.h> kvm_t * kvm_open(const char *execfile, const char *corefile, const char *swapfile, int flags, const char *errstr); kvm_t * kvm_openfiles(const char *execfile, const char *corefile, const char *swapfile, int flags, char *errbuf); int kvm_close(kvm_t *kd); DESCRIPTION
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. The execfile argument 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, as determined from getbootfile(3). The corefile argument 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 default indicated by _PATH_MEM from <paths.h> is used. It can also be set to a special value /dev/null by utilities like ps(1) that do not directly access kernel memory. The swapfile argument is currently unused. The flags argument indicates read/write access as in open(2) and applies only to the core file. Only O_RDONLY, O_WRONLY, and O_RDWR are per- mitted. 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 framework. The kvm_open() 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 nature 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 kvm_close() call. The kvm_openfiles() function provides BSD style error reporting. Here, error messages are not printed out by the library. Instead, the application 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. Since 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 mes- sage in the errbuf argument. This buffer should be _POSIX2_LINE_MAX characters large (from <limits.h>). RETURN VALUES
The kvm_open() and kvm_openfiles() 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 kvm_openfiles() writes the error message into errbuf. The kvm_close() function returns 0 on success and -1 on failure. 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), kmem(4), mem(4) 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. BSD
January 29, 2004 BSD

Check Out this Related Man Page

kvm_open(3KVM)						    Kernel VM Library Functions 					    kvm_open(3KVM)

kvm_open, kvm_close - specify a kernel to examine SYNOPSIS
cc [ flag... ] file... -lkvm [ library...] #include <kvm.h> #include <fcntl.h> kvm_t *kvm_open(char *namelist, char *corefile, char *swapfile, int flag, char *errstr); int kvm_close(kvm_t *kd); DESCRIPTION
The kvm_open() function initializes a set of file descriptors to be used in subsequent calls to kernel virtual memory ( VM) routines. It returns a pointer to a kernel identifier that must be used as the kd argument in subsequent kernel VM function calls. The namelist argument specifies an unstripped executable file whose symbol table will be used to locate various offsets in corefile. If namelist is NULL, the symbol table of the currently running kernel is used to determine offsets in the core image. In this case, it is up to the implementation to select an appropriate way to resolve symbolic references, for instance, using /dev/ksyms as a default namelist file. The corefile argument specifies a file that contains an image of physical memory, for instance, a kernel crash dump file (see savecore(1M)) or the special device /dev/mem. If corefile is NULL, the currently running kernel is accessed, using /dev/mem and /dev/kmem. The swapfile argument specifies a file that represents the swap device. If both corefile and swapfile are NULL, the swap device of the cur- rently running kernel is accessed. Otherwise, if swapfile is NULL, kvm_open() may succeed but subsequent kvm_getu(3KVM) function calls may fail if the desired information is swapped out. The flag function is used to specify read or write access for corefile and may have one of the following values: O_RDONLY open for reading O_RDWR open for reading and writing The errstr argument is used to control error reporting. If it is a null pointer, no error messages will be printed. If it is non-null, it is assumed to be the address of a string that will be used to prefix error messages generated by kvm_open. Errors are printed to stderr. A useful value to supply for errstr would be argv[0]. This has the effect of printing the process name in front of any error messages. Applications using libkvm are dependent on the underlying data model of the kernel image, that is, whether it is a 32-bit or 64-bit ker- nel. The data model of these applications must match the data model of the kernel in order to correctly interpret the size and offsets of kernel data structures. For example, a 32-bit application that uses the 32-bit version of the libkvm interfaces will fail to open a 64-bit kernel image. Similarly, a 64-bit application that uses the 64-bit version of the libkvm interfaces will fail to open a 32-bit kernel image. The kvm_close() function closes all file descriptors that were associated with kd. These files are also closed on exit(2) and execve() (see exec(2)). kvm_close() also resets the proc pointer associated with kvm_nextproc(3KVM) and flushes any cached kernel data. RETURN VALUES
The kvm_open() function returns a non-null value suitable for use with subsequent kernel VM function calls. On failure, it returns NULL and no files are opened. The kvm_close() function returns 0 on success and -1 on failure. FILES
/dev/kmem /dev/ksyms /dev/mem ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
savecore(1M), exec(2), exit(2), pathconf(2), getloadavg(3C), kstat(3KSTAT), kvm_getu(3KVM), kvm_nextproc(3KVM), kvm_nlist(3KVM), kvm_kread(3KVM), libkvm(3LIB),sysconf(3C), proc(4), attributes(5), lfcompile(5) NOTES
Kernel core dumps should be examined on the platform on which they were created. While a 32-bit application running on a 64-bit kernel can examine a 32-bit core dump, a 64-bit application running on a 64-bit kernel cannot examine a kernel core dump from the 32-bit system. On 32-bit systems, applications that use libkvm to access the running kernel must be 32-bit applications. On systems that support both 32-bit and 64-bit applications, applications that use the libkvm interfaces to access the running kernel must themselves be 64-bit applica- tions. Although the libkvm API is Stable, the symbol names and data values that can be accessed through this set of interfaces are Private and are subject to ongoing change. Applications using libkvm are likely to be platform- and release-dependent. Most of the traditional uses of libkvm have been superseded by more stable interfaces that allow the same information to be extracted more efficiently, yet independent of the kernel data model. For examples, see sysconf(3C), proc(4), kstat(3KSTAT), getloadavg(3C), and path- conf(2). SunOS 5.11 2 May 2002 kvm_open(3KVM)