158f0484fSRodney W. Grimes.\" Copyright (c) 1992, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" This code is derived from software developed by the Computer Systems 558f0484fSRodney W. Grimes.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 658f0484fSRodney W. Grimes.\" BG 91-66 and contributed to Berkeley. 758f0484fSRodney W. Grimes.\" 858f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 958f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 1058f0484fSRodney W. Grimes.\" are met: 1158f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 1258f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 1358f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1458f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1558f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 1658f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 1758f0484fSRodney W. Grimes.\" must display the following acknowledgement: 1858f0484fSRodney W. Grimes.\" This product includes software developed by the University of 1958f0484fSRodney W. Grimes.\" California, Berkeley and its contributors. 2058f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 2158f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 2258f0484fSRodney W. Grimes.\" without specific prior written permission. 2358f0484fSRodney W. Grimes.\" 2458f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2558f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2658f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2758f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2858f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2958f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3058f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3158f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3258f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3358f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3458f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3558f0484fSRodney W. Grimes.\" 3658f0484fSRodney W. Grimes.\" @(#)kvm_open.3 8.3 (Berkeley) 4/19/94 377f3dea24SPeter Wemm.\" $FreeBSD$ 3858f0484fSRodney W. Grimes.\" 3958f0484fSRodney W. Grimes.Dd April 19, 1994 4058f0484fSRodney W. Grimes.Dt KVM_OPEN 3 4158f0484fSRodney W. Grimes.Os 4258f0484fSRodney W. Grimes.Sh NAME 4358f0484fSRodney W. Grimes.Nm kvm_open , 4458f0484fSRodney W. Grimes.Nm kvm_openfiles , 4558f0484fSRodney W. Grimes.Nm kvm_close 4658f0484fSRodney W. Grimes.Nd initialize kernel virtual memory access 477f5e8c84SAlexey Zelkin.Sh LIBRARY 487f5e8c84SAlexey Zelkin.Lb libkvm 4958f0484fSRodney W. Grimes.Sh SYNOPSIS 5032eef9aeSRuslan Ermilov.In fcntl.h 5132eef9aeSRuslan Ermilov.In kvm.h 5258f0484fSRodney W. Grimes.Ft kvm_t * 5377667e9eSBruce Evans.Fn kvm_open "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "const char *errstr" 5458f0484fSRodney W. Grimes.Ft kvm_t * 5577667e9eSBruce Evans.Fn kvm_openfiles "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "char *errbuf" 5658f0484fSRodney W. Grimes.Ft int 5758f0484fSRodney W. Grimes.Fn kvm_close "kvm_t *kd" 5858f0484fSRodney W. Grimes.Sh DESCRIPTION 5958f0484fSRodney W. GrimesThe functions 6058f0484fSRodney W. Grimes.Fn kvm_open 6158f0484fSRodney W. Grimesand 6258f0484fSRodney W. Grimes.Fn kvm_openfiles 6358f0484fSRodney W. Grimesreturn a descriptor used to access kernel virtual memory 6458f0484fSRodney W. Grimesvia the 6558f0484fSRodney W. Grimes.Xr kvm 3 6658f0484fSRodney W. Grimeslibrary routines. Both active kernels and crash dumps are accessible 6758f0484fSRodney W. Grimesthrough this interface. 6858f0484fSRodney W. Grimes.Pp 6958f0484fSRodney W. Grimes.Fa execfile 7058f0484fSRodney W. Grimesis the executable image of the kernel being examined. 7158f0484fSRodney W. GrimesThis file must contain a symbol table. 7258f0484fSRodney W. GrimesIf this argument is 7358f0484fSRodney W. Grimes.Dv NULL , 7458f0484fSRodney W. Grimesthe currently running system is assumed, 754be4929cSGarrett Wollmanas determined from 764be4929cSGarrett Wollman.Xr getbootfile 3 . 7758f0484fSRodney W. Grimes.Pp 7858f0484fSRodney W. Grimes.Fa corefile 7958f0484fSRodney W. Grimesis the kernel memory device file. It can be either /dev/mem 8058f0484fSRodney W. Grimesor a crash dump core generated by 8158f0484fSRodney W. Grimes.Xr savecore 8 . 8258f0484fSRodney W. GrimesIf 8358f0484fSRodney W. Grimes.Fa corefile 8458f0484fSRodney W. Grimesis 8558f0484fSRodney W. Grimes.Dv NULL , 8658f0484fSRodney W. Grimesthe default indicated by 8758f0484fSRodney W. Grimes.Dv _PATH_MEM 8858f0484fSRodney W. Grimesfrom <paths.h> is used. 8958f0484fSRodney W. Grimes.Pp 90fe42e96eSRuslan ErmilovThe 9158f0484fSRodney W. Grimes.Fa swapfile 92fe42e96eSRuslan Ermilovargument is currently unused. 9358f0484fSRodney W. Grimes.Pp 9458f0484fSRodney W. GrimesThe 9558f0484fSRodney W. Grimes.Fa flags 9658f0484fSRodney W. Grimesargument indicates read/write access as in 9758f0484fSRodney W. Grimes.Xr open 2 9858f0484fSRodney W. Grimesand applies only to the core file. 9958f0484fSRodney W. GrimesOnly 10058f0484fSRodney W. Grimes.Dv O_RDONLY , 10158f0484fSRodney W. Grimes.Dv O_WRONLY , 10258f0484fSRodney W. Grimesand 10358f0484fSRodney W. Grimes.Dv O_RDWR 10458f0484fSRodney W. Grimesare permitted. 10558f0484fSRodney W. Grimes.Pp 10658f0484fSRodney W. GrimesThere are two open routines which differ only with respect to 10758f0484fSRodney W. Grimesthe error mechanism. 10858f0484fSRodney W. GrimesOne provides backward compatibility with the SunOS kvm library, while the 10958f0484fSRodney W. Grimesother provides an improved error reporting framework. 11058f0484fSRodney W. Grimes.Pp 11158f0484fSRodney W. GrimesThe 11258f0484fSRodney W. Grimes.Fn kvm_open 11358f0484fSRodney W. Grimesfunction is the Sun kvm compatible open call. Here, the 11458f0484fSRodney W. Grimes.Fa errstr 11558f0484fSRodney W. Grimesargument indicates how errors should be handled. If it is 11658f0484fSRodney W. Grimes.Dv NULL , 11758f0484fSRodney W. Grimesno errors are reported and the application cannot know the 11858f0484fSRodney W. Grimesspecific nature of the failed kvm call. 11958f0484fSRodney W. GrimesIf it is not 12058f0484fSRodney W. Grimes.Dv NULL , 12158f0484fSRodney W. Grimeserrors are printed to stderr with 12258f0484fSRodney W. Grimes.Fa errstr 12358f0484fSRodney W. Grimesprepended to the message, as in 12458f0484fSRodney W. Grimes.Xr perror 3 . 12558f0484fSRodney W. GrimesNormally, the name of the program is used here. 12658f0484fSRodney W. GrimesThe string is assumed to persist at least until the corresponding 12758f0484fSRodney W. Grimes.Fn kvm_close 12858f0484fSRodney W. Grimescall. 12958f0484fSRodney W. Grimes.Pp 13058f0484fSRodney W. GrimesThe 13158f0484fSRodney W. Grimes.Fn kvm_openfiles 132753d686dSRuslan Ermilovfunction provides 133753d686dSRuslan Ermilov.Bx 134753d686dSRuslan Ermilovstyle error reporting. 13558f0484fSRodney W. GrimesHere, error messages are not printed out by the library. 13658f0484fSRodney W. GrimesInstead, the application obtains the error message 13758f0484fSRodney W. Grimescorresponding to the most recent kvm library call using 13858f0484fSRodney W. Grimes.Fn kvm_geterr 13958f0484fSRodney W. Grimes(see 14058f0484fSRodney W. Grimes.Xr kvm_geterr 3 ) . 14158f0484fSRodney W. GrimesThe results are undefined if the most recent kvm call did not produce 14258f0484fSRodney W. Grimesan error. 14358f0484fSRodney W. GrimesSince 14458f0484fSRodney W. Grimes.Fn kvm_geterr 14558f0484fSRodney W. Grimesrequires a kvm descriptor, but the open routines return 14658f0484fSRodney W. Grimes.Dv NULL 14758f0484fSRodney W. Grimeson failure, 14858f0484fSRodney W. Grimes.Fn kvm_geterr 14958f0484fSRodney W. Grimescannot be used to get the error message if open fails. 15058f0484fSRodney W. GrimesThus, 15158f0484fSRodney W. Grimes.Fn kvm_openfiles 15258f0484fSRodney W. Grimeswill place any error message in the 15358f0484fSRodney W. Grimes.Fa errbuf 15458f0484fSRodney W. Grimesargument. This buffer should be _POSIX2_LINE_MAX characters large (from 15558f0484fSRodney W. Grimes<limits.h>). 15658f0484fSRodney W. Grimes.Sh RETURN VALUES 15758f0484fSRodney W. GrimesThe 15858f0484fSRodney W. Grimes.Fn kvm_open 15958f0484fSRodney W. Grimesand 16058f0484fSRodney W. Grimes.Fn kvm_openfiles 16158f0484fSRodney W. Grimesfunctions both return a descriptor to be used 16258f0484fSRodney W. Grimesin all subsequent kvm library calls. 16358f0484fSRodney W. GrimesThe library is fully re-entrant. 16458f0484fSRodney W. GrimesOn failure, 16558f0484fSRodney W. Grimes.Dv NULL 16658f0484fSRodney W. Grimesis returned, in which case 16758f0484fSRodney W. Grimes.Fn kvm_openfiles 16858f0484fSRodney W. Grimeswrites the error message into 16958f0484fSRodney W. Grimes.Fa errbuf . 17058f0484fSRodney W. Grimes.Pp 17158f0484fSRodney W. GrimesThe 17258f0484fSRodney W. Grimes.Fn kvm_close 17358f0484fSRodney W. Grimesfunction returns 0 on success and -1 on failure. 17458f0484fSRodney W. Grimes.Sh BUGS 17558f0484fSRodney W. GrimesThere should not be two open calls. The ill-defined error semantics 17658f0484fSRodney W. Grimesof the Sun library and the desire to have a backward-compatible library 177753d686dSRuslan Ermilovfor 178753d686dSRuslan Ermilov.Bx 179753d686dSRuslan Ermilovleft little choice. 18058f0484fSRodney W. Grimes.Sh SEE ALSO 18158f0484fSRodney W. Grimes.Xr open 2 , 18258f0484fSRodney W. Grimes.Xr kvm 3 , 18358f0484fSRodney W. Grimes.Xr kvm_getargv 3 , 18458f0484fSRodney W. Grimes.Xr kvm_getenvv 3 , 18558f0484fSRodney W. Grimes.Xr kvm_geterr 3 , 18658f0484fSRodney W. Grimes.Xr kvm_getprocs 3 , 18758f0484fSRodney W. Grimes.Xr kvm_nlist 3 , 18858f0484fSRodney W. Grimes.Xr kvm_read 3 , 18958f0484fSRodney W. Grimes.Xr kvm_write 3 190