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 currently 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 kernel.
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.
|