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.\" 3927692448SRuslan Ermilov.Dd January 29, 2004 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 661a0a9345SRuslan Ermilovlibrary routines. 671a0a9345SRuslan ErmilovBoth active kernels and crash dumps are accessible 6858f0484fSRodney W. Grimesthrough this interface. 6958f0484fSRodney W. Grimes.Pp 704cacb618SPhilippe CharnierThe 7158f0484fSRodney W. Grimes.Fa execfile 724cacb618SPhilippe Charnierargument is the executable image of the kernel being examined. 7358f0484fSRodney W. GrimesThis file must contain a symbol table. 7458f0484fSRodney W. GrimesIf this argument is 7558f0484fSRodney W. Grimes.Dv NULL , 7658f0484fSRodney W. Grimesthe currently running system is assumed, 774be4929cSGarrett Wollmanas determined from 784be4929cSGarrett Wollman.Xr getbootfile 3 . 7958f0484fSRodney W. Grimes.Pp 804cacb618SPhilippe CharnierThe 8158f0484fSRodney W. Grimes.Fa corefile 8227692448SRuslan Ermilovargument is the kernel memory device file. 8327692448SRuslan ErmilovIt can be either 8427692448SRuslan Ermilov.Pa /dev/mem 8558f0484fSRodney W. Grimesor a crash dump core generated by 8658f0484fSRodney W. Grimes.Xr savecore 8 . 8758f0484fSRodney W. GrimesIf 8858f0484fSRodney W. Grimes.Fa corefile 8958f0484fSRodney W. Grimesis 9058f0484fSRodney W. Grimes.Dv NULL , 9158f0484fSRodney W. Grimesthe default indicated by 9258f0484fSRodney W. Grimes.Dv _PATH_MEM 9327692448SRuslan Ermilovfrom 9427692448SRuslan Ermilov.In paths.h 9527692448SRuslan Ermilovis used. 9627692448SRuslan ErmilovIt can also be set to a special value 9727692448SRuslan Ermilov.Pa /dev/null 9827692448SRuslan Ermilovby utilities like 9927692448SRuslan Ermilov.Xr ps 1 10027692448SRuslan Ermilovthat do not directly access kernel memory. 10158f0484fSRodney W. Grimes.Pp 102fe42e96eSRuslan ErmilovThe 10358f0484fSRodney W. Grimes.Fa swapfile 104fe42e96eSRuslan Ermilovargument is currently unused. 10558f0484fSRodney W. Grimes.Pp 10658f0484fSRodney W. GrimesThe 10758f0484fSRodney W. Grimes.Fa flags 10858f0484fSRodney W. Grimesargument indicates read/write access as in 10958f0484fSRodney W. Grimes.Xr open 2 11058f0484fSRodney W. Grimesand applies only to the core file. 11158f0484fSRodney W. GrimesOnly 11258f0484fSRodney W. Grimes.Dv O_RDONLY , 11358f0484fSRodney W. Grimes.Dv O_WRONLY , 11458f0484fSRodney W. Grimesand 11558f0484fSRodney W. Grimes.Dv O_RDWR 11658f0484fSRodney W. Grimesare permitted. 11758f0484fSRodney W. Grimes.Pp 11858f0484fSRodney W. GrimesThere are two open routines which differ only with respect to 11958f0484fSRodney W. Grimesthe error mechanism. 12058f0484fSRodney W. GrimesOne provides backward compatibility with the SunOS kvm library, while the 12158f0484fSRodney W. Grimesother provides an improved error reporting framework. 12258f0484fSRodney W. Grimes.Pp 12358f0484fSRodney W. GrimesThe 12458f0484fSRodney W. Grimes.Fn kvm_open 1251a0a9345SRuslan Ermilovfunction is the Sun kvm compatible open call. 1261a0a9345SRuslan ErmilovHere, the 12758f0484fSRodney W. Grimes.Fa errstr 1281a0a9345SRuslan Ermilovargument indicates how errors should be handled. 1291a0a9345SRuslan ErmilovIf it is 13058f0484fSRodney W. Grimes.Dv NULL , 13158f0484fSRodney W. Grimesno errors are reported and the application cannot know the 13258f0484fSRodney W. Grimesspecific nature of the failed kvm call. 13358f0484fSRodney W. GrimesIf it is not 13458f0484fSRodney W. Grimes.Dv NULL , 135ae828962SRuslan Ermiloverrors are printed to 136ae828962SRuslan Ermilov.Dv stderr 137ae828962SRuslan Ermilovwith 13858f0484fSRodney W. Grimes.Fa errstr 13958f0484fSRodney W. Grimesprepended to the message, as in 14058f0484fSRodney W. Grimes.Xr perror 3 . 14158f0484fSRodney W. GrimesNormally, the name of the program is used here. 14258f0484fSRodney W. GrimesThe string is assumed to persist at least until the corresponding 14358f0484fSRodney W. Grimes.Fn kvm_close 14458f0484fSRodney W. Grimescall. 14558f0484fSRodney W. Grimes.Pp 14658f0484fSRodney W. GrimesThe 14758f0484fSRodney W. Grimes.Fn kvm_openfiles 148753d686dSRuslan Ermilovfunction provides 149753d686dSRuslan Ermilov.Bx 150753d686dSRuslan Ermilovstyle error reporting. 15158f0484fSRodney W. GrimesHere, error messages are not printed out by the library. 15258f0484fSRodney W. GrimesInstead, the application obtains the error message 15358f0484fSRodney W. Grimescorresponding to the most recent kvm library call using 15458f0484fSRodney W. Grimes.Fn kvm_geterr 15558f0484fSRodney W. Grimes(see 15658f0484fSRodney W. Grimes.Xr kvm_geterr 3 ) . 15758f0484fSRodney W. GrimesThe results are undefined if the most recent kvm call did not produce 15858f0484fSRodney W. Grimesan error. 15958f0484fSRodney W. GrimesSince 16058f0484fSRodney W. Grimes.Fn kvm_geterr 16158f0484fSRodney W. Grimesrequires a kvm descriptor, but the open routines return 16258f0484fSRodney W. Grimes.Dv NULL 16358f0484fSRodney W. Grimeson failure, 16458f0484fSRodney W. Grimes.Fn kvm_geterr 16558f0484fSRodney W. Grimescannot be used to get the error message if open fails. 16658f0484fSRodney W. GrimesThus, 16758f0484fSRodney W. Grimes.Fn kvm_openfiles 16858f0484fSRodney W. Grimeswill place any error message in the 16958f0484fSRodney W. Grimes.Fa errbuf 1701a0a9345SRuslan Ermilovargument. 1711a0a9345SRuslan ErmilovThis buffer should be _POSIX2_LINE_MAX characters large (from 17258f0484fSRodney W. Grimes<limits.h>). 17358f0484fSRodney W. Grimes.Sh RETURN VALUES 17458f0484fSRodney W. GrimesThe 17558f0484fSRodney W. Grimes.Fn kvm_open 17658f0484fSRodney W. Grimesand 17758f0484fSRodney W. Grimes.Fn kvm_openfiles 17858f0484fSRodney W. Grimesfunctions both return a descriptor to be used 17958f0484fSRodney W. Grimesin all subsequent kvm library calls. 18058f0484fSRodney W. GrimesThe library is fully re-entrant. 18158f0484fSRodney W. GrimesOn failure, 18258f0484fSRodney W. Grimes.Dv NULL 18358f0484fSRodney W. Grimesis returned, in which case 18458f0484fSRodney W. Grimes.Fn kvm_openfiles 18558f0484fSRodney W. Grimeswrites the error message into 18658f0484fSRodney W. Grimes.Fa errbuf . 18758f0484fSRodney W. Grimes.Pp 18858f0484fSRodney W. GrimesThe 18958f0484fSRodney W. Grimes.Fn kvm_close 19058f0484fSRodney W. Grimesfunction returns 0 on success and -1 on failure. 19158f0484fSRodney W. Grimes.Sh BUGS 1921a0a9345SRuslan ErmilovThere should not be two open calls. 1931a0a9345SRuslan ErmilovThe ill-defined error semantics 19458f0484fSRodney W. Grimesof the Sun library and the desire to have a backward-compatible library 195753d686dSRuslan Ermilovfor 196753d686dSRuslan Ermilov.Bx 197753d686dSRuslan Ermilovleft little choice. 19858f0484fSRodney W. Grimes.Sh SEE ALSO 19958f0484fSRodney W. Grimes.Xr open 2 , 20058f0484fSRodney W. Grimes.Xr kvm 3 , 20158f0484fSRodney W. Grimes.Xr kvm_getargv 3 , 20258f0484fSRodney W. Grimes.Xr kvm_getenvv 3 , 20358f0484fSRodney W. Grimes.Xr kvm_geterr 3 , 20458f0484fSRodney W. Grimes.Xr kvm_getprocs 3 , 20558f0484fSRodney W. Grimes.Xr kvm_nlist 3 , 20658f0484fSRodney W. Grimes.Xr kvm_read 3 , 20727692448SRuslan Ermilov.Xr kvm_write 3 , 20827692448SRuslan Ermilov.Xr kmem 4 , 20927692448SRuslan Ermilov.Xr mem 4 210