xref: /openbsd-src/lib/libkvm/kvm_open.3 (revision 3866ebe548daf526bcef13e6429768448eba8aca)
1*3866ebe5Sjca.\"	$OpenBSD: kvm_open.3,v 1.18 2015/04/04 18:53:18 jca Exp $
215f0ebb0Sderaadt.\"	$NetBSD: kvm_open.3,v 1.2 1996/03/18 22:33:52 thorpej Exp $
315f0ebb0Sderaadt.\"
4df930be7Sderaadt.\" Copyright (c) 1992, 1993
5df930be7Sderaadt.\"	The Regents of the University of California.  All rights reserved.
6df930be7Sderaadt.\"
7df930be7Sderaadt.\" This code is derived from software developed by the Computer Systems
8df930be7Sderaadt.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9df930be7Sderaadt.\" BG 91-66 and contributed to Berkeley.
10df930be7Sderaadt.\"
11df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
12df930be7Sderaadt.\" modification, are permitted provided that the following conditions
13df930be7Sderaadt.\" are met:
14df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
15df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
16df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
17df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
18df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
196580fee3Smillert.\" 3. Neither the name of the University nor the names of its contributors
20df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
21df930be7Sderaadt.\"    without specific prior written permission.
22df930be7Sderaadt.\"
23df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df930be7Sderaadt.\" SUCH DAMAGE.
34df930be7Sderaadt.\"
35df930be7Sderaadt.\"     @(#)kvm_open.3	8.3 (Berkeley) 4/19/94
36df930be7Sderaadt.\"
37*3866ebe5Sjca.Dd $Mdocdate: April 4 2015 $
38df930be7Sderaadt.Dt KVM_OPEN 3
39df930be7Sderaadt.Os
40df930be7Sderaadt.Sh NAME
41df930be7Sderaadt.Nm kvm_open ,
42df930be7Sderaadt.Nm kvm_openfiles ,
43df930be7Sderaadt.Nm kvm_close
44df930be7Sderaadt.Nd initialize kernel virtual memory access
45df930be7Sderaadt.Sh SYNOPSIS
4686f9d4cdStedu.In fcntl.h
4786f9d4cdStedu.In kvm.h
48df930be7Sderaadt.Ft kvm_t *
49*3866ebe5Sjca.Fn kvm_open "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "const char *errstr"
50df930be7Sderaadt.Ft kvm_t *
51*3866ebe5Sjca.Fn kvm_openfiles "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "char *errbuf"
52df930be7Sderaadt.Ft int
53df930be7Sderaadt.Fn kvm_close "kvm_t *kd"
54df930be7Sderaadt.Sh DESCRIPTION
55df930be7SderaadtThe functions
56df930be7Sderaadt.Fn kvm_open
57df930be7Sderaadtand
58df930be7Sderaadt.Fn kvm_openfiles
59df930be7Sderaadtreturn a descriptor used to access kernel virtual memory
60df930be7Sderaadtvia the
61df930be7Sderaadt.Xr kvm 3
622bb07095Saaronlibrary routines.
632bb07095SaaronBoth active kernels and crash dumps are accessible through this interface.
64df930be7Sderaadt.Pp
65df930be7Sderaadt.Fa execfile
66df930be7Sderaadtis the executable image of the kernel being examined.
67df930be7SderaadtThis file must contain a symbol table.
68df930be7SderaadtIf this argument is
69df930be7Sderaadt.Dv NULL ,
70df930be7Sderaadtthe currently running system is assumed,
71df930be7Sderaadtwhich is indicated by
728f186035Smillert.Dv _PATH_KSYMS ,
738f186035Smillertif it exists, otherwise
74df930be7Sderaadt.Dv _PATH_UNIX
758f186035Smillertis used.
762bb07095SaaronBoth are defined in
77369bef3aSschwarze.In paths.h .
78df930be7Sderaadt.Pp
79df930be7Sderaadt.Fa corefile
802bb07095Saaronis the kernel memory device file.
812bb07095SaaronIt can be either
822bb07095Saaron.Pa /dev/mem
83df930be7Sderaadtor a crash dump core generated by
84df930be7Sderaadt.Xr savecore 8 .
85df930be7SderaadtIf
86df930be7Sderaadt.Fa corefile
87df930be7Sderaadtis
88df930be7Sderaadt.Dv NULL ,
89df930be7Sderaadtthe default indicated by
90df930be7Sderaadt.Dv _PATH_MEM
912bb07095Saaronfrom
92369bef3aSschwarze.In paths.h
932bb07095Saaronis used.
94df930be7Sderaadt.Pp
95df930be7Sderaadt.Fa swapfile
962bb07095Saaronshould indicate the swap device.
972bb07095SaaronIf
98df930be7Sderaadt.Dv NULL ,
99cbe3564fSmiodno swap device will be used.
100df930be7Sderaadt.Pp
101df930be7SderaadtThe
102df930be7Sderaadt.Fa flags
103df930be7Sderaadtargument indicates read/write access as in
104df930be7Sderaadt.Xr open 2
105df930be7Sderaadtand applies only to the core file.
106df930be7SderaadtOnly
107df930be7Sderaadt.Dv O_RDONLY ,
108df930be7Sderaadt.Dv O_WRONLY ,
109df930be7Sderaadtand
110df930be7Sderaadt.Dv O_RDWR
111df930be7Sderaadtare permitted.
1122d420eafSartA special value
1132d420eafSart.Dv KVM_NO_FILES
1142d420eafSartcan be specified which will cause no files to be opened and the handle
1152d420eafSartcan only be used on live kernels on a limited subset of all kvm operations.
116df930be7Sderaadt.Pp
117df930be7SderaadtThere are two open routines which differ only with respect to
118df930be7Sderaadtthe error mechanism.
119df930be7SderaadtOne provides backward compatibility with the SunOS kvm library, while the
120df930be7Sderaadtother provides an improved error reporting framework.
121df930be7Sderaadt.Pp
122df930be7SderaadtThe
123df930be7Sderaadt.Fn kvm_open
1242bb07095Saaronfunction is the Sun kvm compatible open call.
1252bb07095SaaronHere, the
126df930be7Sderaadt.Fa errstr
1272bb07095Saaronargument indicates how errors should be handled.
1282bb07095SaaronIf it is
129df930be7Sderaadt.Dv NULL ,
130df930be7Sderaadtno errors are reported and the application cannot know the
131df930be7Sderaadtspecific nature of the failed kvm call.
132df930be7SderaadtIf it is not
133df930be7Sderaadt.Dv NULL ,
134df930be7Sderaadterrors are printed to stderr with
135df930be7Sderaadt.Fa errstr
136df930be7Sderaadtprepended to the message, as in
137df930be7Sderaadt.Xr perror 3 .
138df930be7SderaadtNormally, the name of the program is used here.
139df930be7SderaadtThe string is assumed to persist at least until the corresponding
140df930be7Sderaadt.Fn kvm_close
141df930be7Sderaadtcall.
142df930be7Sderaadt.Pp
143df930be7SderaadtThe
144df930be7Sderaadt.Fn kvm_openfiles
145720a7a94Sjmcfunction provides
146720a7a94Sjmc.Bx
147720a7a94Sjmcstyle error reporting.
148df930be7SderaadtHere, error messages are not printed out by the library.
149df930be7SderaadtInstead, the application obtains the error message
150df930be7Sderaadtcorresponding to the most recent kvm library call using
151df930be7Sderaadt.Fn kvm_geterr
152df930be7Sderaadt(see
153df930be7Sderaadt.Xr kvm_geterr 3 ) .
154df930be7SderaadtThe results are undefined if the most recent kvm call did not produce
155df930be7Sderaadtan error.
156df930be7SderaadtSince
157df930be7Sderaadt.Fn kvm_geterr
158df930be7Sderaadtrequires a kvm descriptor, but the open routines return
159df930be7Sderaadt.Dv NULL
160df930be7Sderaadton failure,
161df930be7Sderaadt.Fn kvm_geterr
162df930be7Sderaadtcannot be used to get the error message if open fails.
163df930be7SderaadtThus,
164df930be7Sderaadt.Fn kvm_openfiles
165df930be7Sderaadtwill place any error message in the
166df930be7Sderaadt.Fa errbuf
1672bb07095Saaronargument.
1682bb07095SaaronThis buffer should be
1692bb07095Saaron.Dv _POSIX2_LINE_MAX
1702bb07095Saaroncharacters large (from
171369bef3aSschwarze.In limits.h ) .
172df930be7Sderaadt.Sh RETURN VALUES
173df930be7SderaadtThe
174df930be7Sderaadt.Fn kvm_open
175df930be7Sderaadtand
176df930be7Sderaadt.Fn kvm_openfiles
177df930be7Sderaadtfunctions both return a descriptor to be used
178df930be7Sderaadtin all subsequent kvm library calls.
179df930be7SderaadtThe library is fully re-entrant.
180df930be7SderaadtOn failure,
181df930be7Sderaadt.Dv NULL
182df930be7Sderaadtis returned, in which case
183df930be7Sderaadt.Fn kvm_openfiles
184df930be7Sderaadtwrites the error message into
185df930be7Sderaadt.Fa errbuf .
186df930be7Sderaadt.Pp
187df930be7SderaadtThe
188df930be7Sderaadt.Fn kvm_close
18962127031Saaronfunction returns 0 on success and \-1 on failure.
190df930be7Sderaadt.Sh SEE ALSO
191df930be7Sderaadt.Xr open 2 ,
192df930be7Sderaadt.Xr kvm 3 ,
193df930be7Sderaadt.Xr kvm_geterr 3 ,
194df930be7Sderaadt.Xr kvm_getprocs 3 ,
195df930be7Sderaadt.Xr kvm_nlist 3 ,
196376bc393Sjmc.Xr kvm_read 3
197cdafad35Sjmc.Sh BUGS
198cdafad35SjmcThere should not be two open calls.
199cdafad35SjmcThe ill-defined error semantics of the Sun library and the desire to have
200720a7a94Sjmca backward-compatible library for
201720a7a94Sjmc.Bx
202720a7a94Sjmcleft little choice.
203