xref: /netbsd-src/lib/libkvm/kvm_open.3 (revision b8c5a24416d48a54c6eabe8e58e4ba5f8ac8b3ca)
1*b8c5a244Schristos.\"	$NetBSD: kvm_open.3,v 1.18 2011/09/12 21:11:32 christos Exp $
2346e67f8Sthorpej.\"
30215cc7dScgd.\" Copyright (c) 1992, 1993
40215cc7dScgd.\"	The Regents of the University of California.  All rights reserved.
50215cc7dScgd.\"
60215cc7dScgd.\" This code is derived from software developed by the Computer Systems
70215cc7dScgd.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
80215cc7dScgd.\" BG 91-66 and contributed to Berkeley.
90215cc7dScgd.\"
100215cc7dScgd.\" Redistribution and use in source and binary forms, with or without
110215cc7dScgd.\" modification, are permitted provided that the following conditions
120215cc7dScgd.\" are met:
130215cc7dScgd.\" 1. Redistributions of source code must retain the above copyright
140215cc7dScgd.\"    notice, this list of conditions and the following disclaimer.
150215cc7dScgd.\" 2. Redistributions in binary form must reproduce the above copyright
160215cc7dScgd.\"    notice, this list of conditions and the following disclaimer in the
170215cc7dScgd.\"    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc.\" 3. Neither the name of the University nor the names of its contributors
190215cc7dScgd.\"    may be used to endorse or promote products derived from this software
200215cc7dScgd.\"    without specific prior written permission.
210215cc7dScgd.\"
220215cc7dScgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
230215cc7dScgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
240215cc7dScgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250215cc7dScgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
260215cc7dScgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
270215cc7dScgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
280215cc7dScgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
290215cc7dScgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
300215cc7dScgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
310215cc7dScgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
320215cc7dScgd.\" SUCH DAMAGE.
330215cc7dScgd.\"
340215cc7dScgd.\"     @(#)kvm_open.3	8.3 (Berkeley) 4/19/94
350215cc7dScgd.\"
36*b8c5a244Schristos.Dd September 14, 2011
370215cc7dScgd.Dt KVM_OPEN 3
380215cc7dScgd.Os
390215cc7dScgd.Sh NAME
400215cc7dScgd.Nm kvm_open ,
410215cc7dScgd.Nm kvm_openfiles ,
420215cc7dScgd.Nm kvm_close
430215cc7dScgd.Nd initialize kernel virtual memory access
44312aca53Sperry.Sh LIBRARY
45312aca53Sperry.Lb libkvm
460215cc7dScgd.Sh SYNOPSIS
47472351e1Swiz.In fcntl.h
48472351e1Swiz.In kvm.h
490215cc7dScgd.Ft kvm_t *
500215cc7dScgd.Fn kvm_open "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "const char *errstr"
510215cc7dScgd.Ft kvm_t *
520215cc7dScgd.Fn kvm_openfiles "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "char *errbuf"
530215cc7dScgd.Ft int
540215cc7dScgd.Fn kvm_close "kvm_t *kd"
550215cc7dScgd.Sh DESCRIPTION
560215cc7dScgdThe functions
570215cc7dScgd.Fn kvm_open
580215cc7dScgdand
590215cc7dScgd.Fn kvm_openfiles
600215cc7dScgdreturn a descriptor used to access kernel virtual memory
610215cc7dScgdvia the
620215cc7dScgd.Xr kvm 3
63bec910b3Swizlibrary routines.
64bec910b3SwizBoth active kernels and crash dumps are accessible
650215cc7dScgdthrough this interface.
660215cc7dScgd.Pp
670215cc7dScgd.Fa execfile
680215cc7dScgdis the executable image of the kernel being examined.
690215cc7dScgdThis file must contain a symbol table.
700215cc7dScgdIf this argument is
710215cc7dScgd.Dv NULL ,
7250a2fd24Sapbthe currently running system is assumed; in this case, the functions will
7350a2fd24Sapbattempt to use the
7450a2fd24Sapb.Xr ksyms 4
7550a2fd24Sapbdevice indicated by
7650a2fd24Sapb.Dv _PATH_KSYMS
7750a2fd24Sapbin
783c70878eSjoerg.In paths.h ;
7950a2fd24Sapbif that fails, then they will use the file indicated by the
8050a2fd24Sapb.Xr sysctl 3
8150a2fd24Sapbvariable
8250a2fd24Sapb.Va machdep.booted_kernel ,
8350a2fd24Sapbor (if the sysctl information is not available)
8450a2fd24Sapbthe default kernel path indicated by
850215cc7dScgd.Dv _PATH_UNIX
866e0792feSmikelin
873c70878eSjoerg.In paths.h .
880215cc7dScgd.Pp
890215cc7dScgd.Fa corefile
90bec910b3Swizis the kernel memory device file.
91bec910b3SwizIt can be either
926e0792feSmikel.Pa /dev/mem
930215cc7dScgdor a crash dump core generated by
940215cc7dScgd.Xr savecore 8 .
950215cc7dScgdIf
960215cc7dScgd.Fa corefile
970215cc7dScgdis
980215cc7dScgd.Dv NULL ,
990215cc7dScgdthe default indicated by
1000215cc7dScgd.Dv _PATH_MEM
1016e0792feSmikelfrom
1023c70878eSjoerg.In paths.h
1036e0792feSmikelis used.
1040215cc7dScgd.Pp
1050215cc7dScgd.Fa swapfile
106bec910b3Swizshould indicate the swap device.
107bec910b3SwizIf
1080215cc7dScgd.Dv NULL ,
1090215cc7dScgd.Dv _PATH_DRUM
1106e0792feSmikelfrom
1113c70878eSjoerg.In paths.h
1126e0792feSmikelis used.
1130215cc7dScgd.Pp
1140215cc7dScgdThe
1150215cc7dScgd.Fa flags
1160215cc7dScgdargument indicates read/write access as in
1170215cc7dScgd.Xr open 2
1180215cc7dScgdand applies only to the core file.
119ec323af4SsimonbThe only permitted flags from
120ec323af4Ssimonb.Xr open 2
121ec323af4Ssimonbare
1220215cc7dScgd.Dv O_RDONLY ,
1230215cc7dScgd.Dv O_WRONLY ,
1240215cc7dScgdand
125ec323af4Ssimonb.Dv O_RDWR .
126ec323af4Ssimonb.Pp
127ec323af4SsimonbAs a special case, a
128ec323af4Ssimonb.Fa flags
129ec323af4Ssimonbargument of
130ec323af4Ssimonb.Dv KVM_NO_FILES
1310b87087dSwizwill initialize the
132ec323af4Ssimonb.Xr kvm 3
133ec323af4Ssimonblibrary for use on active kernels only using
134ec323af4Ssimonb.Xr sysctl 3
135ec323af4Ssimonbfor retrieving kernel data and ignores the
136ec323af4Ssimonb.Fa execfile ,
137ec323af4Ssimonb.Fa corefile
138ec323af4Ssimonband
139ec323af4Ssimonb.Fa swapfile
140bec910b3Swizarguments.
141bec910b3SwizOnly a small subset of the
142ec323af4Ssimonb.Xr kvm 3
143bec910b3Swizlibrary functions are available using this method.
144bec910b3SwizThese are currently
145ec323af4Ssimonb.Xr kvm_getproc2 3 ,
146ec323af4Ssimonb.Xr kvm_getargv2 3
147ec323af4Ssimonband
148ec323af4Ssimonb.Xr kvm_getenvv2 3 .
1490215cc7dScgd.Pp
1500215cc7dScgdThere are two open routines which differ only with respect to
1510215cc7dScgdthe error mechanism.
1520215cc7dScgdOne provides backward compatibility with the SunOS kvm library, while the
1530215cc7dScgdother provides an improved error reporting framework.
1540215cc7dScgd.Pp
1550215cc7dScgdThe
1560215cc7dScgd.Fn kvm_open
157bec910b3Swizfunction is the Sun kvm compatible open call.
158bec910b3SwizHere, the
1590215cc7dScgd.Fa errstr
160bec910b3Swizargument indicates how errors should be handled.
161bec910b3SwizIf it is
1620215cc7dScgd.Dv NULL ,
1630215cc7dScgdno errors are reported and the application cannot know the
1640215cc7dScgdspecific nature of the failed kvm call.
1650215cc7dScgdIf it is not
1660215cc7dScgd.Dv NULL ,
1670215cc7dScgderrors are printed to stderr with
1680215cc7dScgd.Fa errstr
1690215cc7dScgdprepended to the message, as in
1700215cc7dScgd.Xr perror 3 .
1710215cc7dScgdNormally, the name of the program is used here.
1720215cc7dScgdThe string is assumed to persist at least until the corresponding
1730215cc7dScgd.Fn kvm_close
1740215cc7dScgdcall.
1750215cc7dScgd.Pp
1760215cc7dScgdThe
1770215cc7dScgd.Fn kvm_openfiles
1786982982fSperryfunction provides
1796982982fSperry.Bx
1806982982fSperrystyle error reporting.
1810215cc7dScgdHere, error messages are not printed out by the library.
1820215cc7dScgdInstead, the application obtains the error message
1830215cc7dScgdcorresponding to the most recent kvm library call using
1840215cc7dScgd.Fn kvm_geterr
1850215cc7dScgd(see
1860215cc7dScgd.Xr kvm_geterr 3 ) .
1870215cc7dScgdThe results are undefined if the most recent kvm call did not produce
1880215cc7dScgdan error.
1890215cc7dScgdSince
1900215cc7dScgd.Fn kvm_geterr
1910215cc7dScgdrequires a kvm descriptor, but the open routines return
1920215cc7dScgd.Dv NULL
1930215cc7dScgdon failure,
1940215cc7dScgd.Fn kvm_geterr
1950215cc7dScgdcannot be used to get the error message if open fails.
1960215cc7dScgdThus,
1970215cc7dScgd.Fn kvm_openfiles
1980215cc7dScgdwill place any error message in the
1990215cc7dScgd.Fa errbuf
200bec910b3Swizargument.
201bec910b3SwizThis buffer should be _POSIX2_LINE_MAX characters large (from
2023c70878eSjoerg.In limits.h ) .
2030215cc7dScgd.Sh RETURN VALUES
2040215cc7dScgdThe
2050215cc7dScgd.Fn kvm_open
2060215cc7dScgdand
2070215cc7dScgd.Fn kvm_openfiles
2080215cc7dScgdfunctions both return a descriptor to be used
2090215cc7dScgdin all subsequent kvm library calls.
2100215cc7dScgdThe library is fully re-entrant.
2110215cc7dScgdOn failure,
2120215cc7dScgd.Dv NULL
2130215cc7dScgdis returned, in which case
2140215cc7dScgd.Fn kvm_openfiles
2150215cc7dScgdwrites the error message into
2160215cc7dScgd.Fa errbuf .
2170215cc7dScgd.Pp
2180215cc7dScgdThe
2190215cc7dScgd.Fn kvm_close
2200215cc7dScgdfunction returns 0 on success and -1 on failure.
2210215cc7dScgd.Sh SEE ALSO
2220215cc7dScgd.Xr open 2 ,
2230215cc7dScgd.Xr kvm 3 ,
2240215cc7dScgd.Xr kvm_getargv 3 ,
2250215cc7dScgd.Xr kvm_getenvv 3 ,
2260215cc7dScgd.Xr kvm_geterr 3 ,
227*b8c5a244Schristos.Xr kvm_getkernelname 3 ,
2280215cc7dScgd.Xr kvm_getprocs 3 ,
2290215cc7dScgd.Xr kvm_nlist 3 ,
2300215cc7dScgd.Xr kvm_read 3 ,
2310215cc7dScgd.Xr kvm_write 3
23235fa939aSwiz.Sh BUGS
233bec910b3SwizThere should not be two open calls.
234bec910b3SwizThe ill-defined error semantics of the Sun library
235bec910b3Swizand the desire to have a backward-compatible library for
23635fa939aSwiz.Bx
23735fa939aSwizleft little choice.
238