1.\" Copyright (c) 1992, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software developed by the Computer Systems 5.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 6.\" BG 91-66 and contributed to Berkeley. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed by the University of 19.\" California, Berkeley and its contributors. 20.\" 4. Neither the name of the University nor the names of its contributors 21.\" may be used to endorse or promote products derived from this software 22.\" without specific prior written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" SUCH DAMAGE. 35.\" 36.\" @(#)kvm_open.3 8.3 (Berkeley) 4/19/94 37.\" 38.Dd April 19, 1994 39.Dt KVM_OPEN 3 40.Os 41.Sh NAME 42.Nm kvm_open , 43.Nm kvm_openfiles , 44.Nm kvm_close 45.Nd initialize kernel virtual memory access 46.Sh SYNOPSIS 47.Fd #include <fcntl.h> 48.Fd #include <kvm.h> 49.br 50.Ft kvm_t * 51.Fn kvm_open "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "const char *errstr" 52.Ft kvm_t * 53.Fn kvm_openfiles "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "char *errbuf" 54.Ft int 55.Fn kvm_close "kvm_t *kd" 56.Sh DESCRIPTION 57The functions 58.Fn kvm_open 59and 60.Fn kvm_openfiles 61return a descriptor used to access kernel virtual memory 62via the 63.Xr kvm 3 64library routines. Both active kernels and crash dumps are accessible 65through this interface. 66.Pp 67.Fa execfile 68is the executable image of the kernel being examined. 69This file must contain a symbol table. 70If this argument is 71.Dv NULL , 72the currently running system is assumed, 73as determined from 74.Xr getbootfile 3 . 75.Pp 76.Fa corefile 77is the kernel memory device file. It can be either /dev/mem 78or a crash dump core generated by 79.Xr savecore 8 . 80If 81.Fa corefile 82is 83.Dv NULL , 84the default indicated by 85.Dv _PATH_MEM 86from <paths.h> is used. 87.Pp 88.Fa swapfile 89should indicate the swap device. If 90.Dv NULL , 91.Dv _PATH_DRUM 92from <paths.h> is used. 93.Pp 94The 95.Fa flags 96argument indicates read/write access as in 97.Xr open 2 98and applies only to the core file. 99Only 100.Dv O_RDONLY , 101.Dv O_WRONLY , 102and 103.Dv O_RDWR 104are permitted. 105.Pp 106There are two open routines which differ only with respect to 107the error mechanism. 108One provides backward compatibility with the SunOS kvm library, while the 109other provides an improved error reporting framework. 110.Pp 111The 112.Fn kvm_open 113function is the Sun kvm compatible open call. Here, the 114.Fa errstr 115argument indicates how errors should be handled. If it is 116.Dv NULL , 117no errors are reported and the application cannot know the 118specific nature of the failed kvm call. 119If it is not 120.Dv NULL , 121errors are printed to stderr with 122.Fa errstr 123prepended to the message, as in 124.Xr perror 3 . 125Normally, the name of the program is used here. 126The string is assumed to persist at least until the corresponding 127.Fn kvm_close 128call. 129.Pp 130The 131.Fn kvm_openfiles 132function provides BSD style error reporting. 133Here, error messages are not printed out by the library. 134Instead, the application obtains the error message 135corresponding to the most recent kvm library call using 136.Fn kvm_geterr 137(see 138.Xr kvm_geterr 3 ). 139The results are undefined if the most recent kvm call did not produce 140an error. 141Since 142.Fn kvm_geterr 143requires a kvm descriptor, but the open routines return 144.Dv NULL 145on failure, 146.Fn kvm_geterr 147cannot be used to get the error message if open fails. 148Thus, 149.Fn kvm_openfiles 150will place any error message in the 151.Fa errbuf 152argument. This buffer should be _POSIX2_LINE_MAX characters large (from 153<limits.h>). 154.Sh RETURN VALUES 155The 156.Fn kvm_open 157and 158.Fn kvm_openfiles 159functions both return a descriptor to be used 160in all subsequent kvm library calls. 161The library is fully re-entrant. 162On failure, 163.Dv NULL 164is returned, in which case 165.Fn kvm_openfiles 166writes the error message into 167.Fa errbuf . 168.Pp 169The 170.Fn kvm_close 171function returns 0 on success and -1 on failure. 172.Sh BUGS 173There should not be two open calls. The ill-defined error semantics 174of the Sun library and the desire to have a backward-compatible library 175for BSD left little choice. 176.Sh SEE ALSO 177.Xr open 2 , 178.Xr kvm 3 , 179.Xr kvm_getargv 3 , 180.Xr kvm_getenvv 3 , 181.Xr kvm_geterr 3 , 182.Xr kvm_getprocs 3 , 183.Xr kvm_nlist 3 , 184.Xr kvm_read 3 , 185.Xr kvm_write 3 186