p .Fa execfile is the executable image of the kernel being examined. This file must contain a symbol table. If this argument is .Dv NULL , the currently running system is assumed; in this case, the functions will attempt to use the .Xr ksyms 4 device indicated by .Dv _PATH_KSYMS in n paths.h ; if that fails, then they will use the file indicated by the .Xr sysctl 3 variable .Va machdep.booted_kernel , or (if the sysctl information is not available) the default kernel path indicated by .Dv _PATH_UNIX in n paths.h .
p .Fa corefile is the kernel memory device file. It can be either
a /dev/mem or a crash dump core generated by .Xr savecore 8 . If .Fa corefile is .Dv NULL , the default indicated by .Dv _PATH_MEM from n paths.h is used.
p .Fa swapfile should indicate the swap device. If .Dv NULL , .Dv _PATH_DRUM from n paths.h is used.
p The .Fa flags argument indicates read/write access as in .Xr open 2 and applies only to the core file. The only permitted flags from .Xr open 2 are .Dv O_RDONLY , .Dv O_WRONLY , and .Dv O_RDWR .
p As a special case, a .Fa flags argument of .Dv KVM_NO_FILES will initialize the .Xr kvm 3 library for use on active kernels only using .Xr sysctl 3 for retrieving kernel data and ignores the .Fa execfile , .Fa corefile and .Fa swapfile arguments. Only a small subset of the .Xr kvm 3 library functions are available using this method. These are currently .Xr kvm_getproc2 3 , .Xr kvm_getargv2 3 and .Xr kvm_getenvv2 3 .
p 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.
p The .Fn kvm_open function is the Sun kvm compatible open call. Here, the .Fa errstr argument indicates how errors should be handled. If it is .Dv NULL , no errors are reported and the application cannot know the specific nature of the failed kvm call. If it is not .Dv NULL , errors are printed to stderr with .Fa errstr prepended to the message, as in .Xr perror 3 . Normally, the name of the program is used here. The string is assumed to persist at least until the corresponding .Fn kvm_close call.
p The .Fn kvm_openfiles function provides x 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 .Fn kvm_geterr (see .Xr kvm_geterr 3 ) . The results are undefined if the most recent kvm call did not produce an error. Since .Fn kvm_geterr requires a kvm descriptor, but the open routines return .Dv NULL on failure, .Fn kvm_geterr cannot be used to get the error message if open fails. Thus, .Fn kvm_openfiles will place any error message in the .Fa errbuf argument. This buffer should be _POSIX2_LINE_MAX characters large (from n limits.h ) . .Sh RETURN VALUES The .Fn kvm_open and .Fn kvm_openfiles functions both return a descriptor to be used in all subsequent kvm library calls. The library is fully re-entrant. On failure, .Dv NULL is returned, in which case .Fn kvm_openfiles writes the error message into .Fa errbuf .
p The .Fn kvm_close function returns 0 on success and -1 on failure. .Sh SEE ALSO .Xr open 2 , .Xr kvm 3 , .Xr kvm_getargv 3 , .Xr kvm_getenvv 3 , .Xr kvm_geterr 3 , .Xr kvm_getkernelname 3 , .Xr kvm_getprocs 3 , .Xr kvm_nlist 3 , .Xr kvm_read 3 , .Xr kvm_write 3 .Sh 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 x left little choice.