]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libkvm/kvm_open.3
Move SYSCTL_ADD_PROC() to unlocked context in if_ure to avoid lock order reversal.
[FreeBSD/FreeBSD.git] / lib / libkvm / kvm_open.3
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. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)kvm_open.3  8.3 (Berkeley) 4/19/94
33 .\" $FreeBSD$
34 .\"
35 .Dd March 20, 2017
36 .Dt KVM_OPEN 3
37 .Os
38 .Sh NAME
39 .Nm kvm_open ,
40 .Nm kvm_open2 ,
41 .Nm kvm_openfiles ,
42 .Nm kvm_close
43 .Nd initialize kernel virtual memory access
44 .Sh LIBRARY
45 .Lb libkvm
46 .Sh SYNOPSIS
47 .In fcntl.h
48 .In kvm.h
49 .Ft kvm_t *
50 .Fn kvm_open "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "const char *errstr"
51 .Ft kvm_t *
52 .Fo kvm_open2
53 .Fa "const char *execfile"
54 .Fa "const char *corefile"
55 .Fa "int flags"
56 .Fa "char *errbuf"
57 .Fa "int (*resolver)(const char *name, kvaddr_t *addr)"
58 .Fc
59 .Ft kvm_t *
60 .Fn kvm_openfiles "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "char *errbuf"
61 .Ft int
62 .Fn kvm_close "kvm_t *kd"
63 .Sh DESCRIPTION
64 The functions
65 .Fn kvm_open ,
66 .Fn kvm_open2 ,
67 and
68 .Fn kvm_openfiles
69 return a descriptor used to access kernel virtual memory
70 via the
71 .Xr kvm 3
72 library routines.
73 Both active kernels and crash dumps are accessible
74 through this interface.
75 .Pp
76 The
77 .Fa execfile
78 argument is the executable image of the kernel being examined.
79 This file must contain a symbol table.
80 If this argument is
81 .Dv NULL ,
82 the currently running system is assumed,
83 as determined from
84 .Xr getbootfile 3 .
85 .Pp
86 The
87 .Fa corefile
88 argument is the kernel memory device file.
89 It can be either
90 .Pa /dev/mem
91 or a crash dump core generated by
92 .Xr savecore 8 .
93 If
94 .Fa corefile
95 is
96 .Dv NULL ,
97 the default indicated by
98 .Dv _PATH_MEM
99 from
100 .In paths.h
101 is used.
102 It can also be set to a special value
103 .Pa /dev/null
104 by utilities like
105 .Xr ps 1
106 that do not directly access kernel memory.
107 .Pp
108 The
109 .Fa swapfile
110 argument is currently unused.
111 .Pp
112 The
113 .Fa flags
114 argument indicates read/write access as in
115 .Xr open 2
116 and applies only to the core file.
117 Only
118 .Dv O_RDONLY ,
119 .Dv O_WRONLY ,
120 and
121 .Dv O_RDWR
122 are permitted.
123 .Pp
124 The
125 .Nm kvm
126 library provides two different error reporting mechanisms.
127 One provides backward compatibility with the SunOS kvm library, while the
128 other provides an improved error reporting framework.
129 The mechanism used by a descriptor is determined by the function used to
130 open the descriptor.
131 .Pp
132 The
133 .Fn kvm_open
134 function is the Sun kvm compatible open call.
135 Here, the
136 .Fa errstr
137 argument indicates how errors should be handled.
138 If it is
139 .Dv NULL ,
140 no errors are reported and the application cannot know the
141 specific nature of the failed kvm call.
142 If it is not
143 .Dv NULL ,
144 errors are printed to
145 .Dv stderr
146 with
147 .Fa errstr
148 prepended to the message, as in
149 .Xr perror 3 .
150 Normally, the name of the program is used here.
151 The string is assumed to persist at least until the corresponding
152 .Fn kvm_close
153 call.
154 .Pp
155 The
156 .Fn kvm_open2
157 and
158 .Fn kvm_openfiles
159 functions provide
160 .Bx
161 style error reporting.
162 Here, error messages are not printed out by the library.
163 Instead, the application obtains the error message
164 corresponding to the most recent kvm library call using
165 .Fn kvm_geterr
166 (see
167 .Xr kvm_geterr 3 ) .
168 The results are undefined if the most recent kvm call did not produce
169 an error.
170 Since
171 .Fn kvm_geterr
172 requires a kvm descriptor, but the open routines return
173 .Dv NULL
174 on failure,
175 .Fn kvm_geterr
176 cannot be used to get the error message if open fails.
177 Thus,
178 .Fn kvm_open2
179 and
180 .Fn kvm_openfiles
181 will place any error message in the
182 .Fa errbuf
183 argument.
184 This buffer should be _POSIX2_LINE_MAX characters large (from
185 <limits.h>).
186 .Pp
187 The
188 .Fa resolver
189 argument points to a function used by the
190 .Nm kvm
191 library to map symbol names to kernel virtual addresses.
192 When the
193 .Fa resolver
194 function is called,
195 .Fa name
196 specifies the requested symbol name.
197 If the function is able to resolve the name to an address,
198 the address should be set in
199 .Fa addr
200 and the function should return zero.
201 If the function is not able to resolve the name to an address,
202 it should return a non-zero value.
203 When opening a native kernel image,
204 .Fa resolver
205 may be set to
206 .Dv NULL
207 to use an internal function to resolve symbol names.
208 Non-native kernel images
209 .Pq such as when cross-debugging a crash dump
210 require a valid
211 .Fa resolver .
212 .Sh RETURN VALUES
213 The
214 .Fn kvm_open ,
215 .Fn kvm_open2 ,
216 and
217 .Fn kvm_openfiles
218 functions return a descriptor to be used
219 in all subsequent kvm library calls.
220 The library is fully re-entrant.
221 On failure,
222 .Dv NULL
223 is returned, in which case
224 .Fn kvm_open2
225 and
226 .Fn kvm_openfiles
227 write the error message into
228 .Fa errbuf .
229 .Pp
230 .Rv -std kvm_close
231 .Sh ERRORS
232 The
233 .Fn kvm_close
234 function may fail and set the global variable
235 .Va errno
236 for any of the errors specified for
237 .Xr close 2 .
238 .Pp
239 The
240 .Fn kvm_close
241 function may also fail and set
242 .Va errno
243 if:
244 .Bl -tag -width Er
245 .It Bq Er EINVAL
246 The value passed via
247 .Fa kd
248 was
249 .Dv NULL .
250 .El
251 .Sh SEE ALSO
252 .Xr close 2 ,
253 .Xr open 2 ,
254 .Xr kvm 3 ,
255 .Xr kvm_getargv 3 ,
256 .Xr kvm_getenvv 3 ,
257 .Xr kvm_geterr 3 ,
258 .Xr kvm_getprocs 3 ,
259 .Xr kvm_native 3 ,
260 .Xr kvm_nlist 3 ,
261 .Xr kvm_read 3 ,
262 .Xr kvm_write 3 ,
263 .Xr kmem 4 ,
264 .Xr mem 4
265 .Sh BUGS
266 There should not be three open calls.
267 The ill-defined error semantics
268 of the Sun library and the desire to have a backward-compatible library
269 for
270 .Bx
271 left little choice.