Merge branch 'vendor/LIBARCHIVE'
[dragonfly.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: src/lib/libkvm/kvm_open.3,v 1.5.2.6 2001/12/17 10:08:30 ru Exp $
34 .\"
35 .Dd May 5, 2009
36 .Dt KVM_OPEN 3
37 .Os
38 .Sh NAME
39 .Nm kvm_open ,
40 .Nm kvm_openfiles ,
41 .Nm kvm_close
42 .Nd initialize kernel virtual memory access
43 .Sh LIBRARY
44 .Lb libkvm
45 .Sh SYNOPSIS
46 .In sys/types.h
47 .In kvm.h
48 .Ft kvm_t *
49 .Fn kvm_open "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "const char *errstr"
50 .Ft kvm_t *
51 .Fn kvm_openfiles "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "char *errbuf"
52 .Ft int
53 .Fn kvm_close "kvm_t *kd"
54 .Sh DESCRIPTION
55 The functions
56 .Fn kvm_open
57 and
58 .Fn kvm_openfiles
59 return a descriptor used to access kernel virtual memory
60 via the
61 .Xr kvm 3
62 library routines.
63 Both active kernels (including vkernels) and crash
64 dumps are accessible through this interface.
65 .Pp
66 .Fa execfile
67 is the executable image of the kernel being examined.
68 This file must contain a symbol table.
69 If this argument is
70 .Dv NULL ,
71 the currently running system is assumed,
72 as determined from
73 .Xr getbootfile 3 .
74 .Pp
75 .Fa corefile
76 is the kernel memory device file.
77 It can be
78 .Pa /dev/mem ,
79 the path to the procfs mem file for a running vkernel (i.e.\&
80 .Pa /proc/$pid/mem )
81 or a crash dump core generated by
82 .Xr savecore 8 .
83 If
84 .Fa corefile
85 is
86 .Dv NULL ,
87 the default indicated by
88 .Dv _PATH_MEM
89 from
90 .In paths.h
91 is used.
92 .Pp
93 .Fa swapfile
94 should indicate the swap device.
95 If
96 .Dv NULL ,
97 .Dv _PATH_DRUM
98 from
99 .In paths.h
100 is used.
101 .Pp
102 The
103 .Fa flags
104 argument indicates read/write access as in
105 .Xr open 2
106 and applies only to the core file.
107 Only
108 .Dv O_RDONLY ,
109 .Dv O_WRONLY ,
110 and
111 .Dv O_RDWR
112 are permitted.
113 .Pp
114 There are two open routines which differ only with respect to
115 the error mechanism.
116 One provides backward compatibility with the SunOS kvm library, while the
117 other provides an improved error reporting framework.
118 .Pp
119 The
120 .Fn kvm_open
121 function is the Sun kvm compatible open call.
122 Here, the
123 .Fa errstr
124 argument indicates how errors should be handled.
125 If it is
126 .Dv NULL ,
127 no errors are reported and the application cannot know the
128 specific nature of the failed kvm call.
129 If it is not
130 .Dv NULL ,
131 errors are printed to stderr with
132 .Fa errstr
133 prepended to the message, as in
134 .Xr perror 3 .
135 Normally, the name of the program is used here.
136 The string is assumed to persist at least until the corresponding
137 .Fn kvm_close
138 call.
139 .Pp
140 The
141 .Fn kvm_openfiles
142 function provides
143 .Bx
144 style error reporting.
145 Here, error messages are not printed out by the library.
146 Instead, the application obtains the error message
147 corresponding to the most recent kvm library call using
148 .Fn kvm_geterr
149 (see
150 .Xr kvm_geterr 3 ) .
151 The results are undefined if the most recent kvm call did not produce
152 an error.
153 Since
154 .Fn kvm_geterr
155 requires a kvm descriptor, but the open routines return
156 .Dv NULL
157 on failure,
158 .Fn kvm_geterr
159 cannot be used to get the error message if open fails.
160 Thus,
161 .Fn kvm_openfiles
162 will place any error message in the
163 .Fa errbuf
164 argument.
165 This buffer should be
166 .Dv _POSIX2_LINE_MAX
167 characters large (from
168 .In limits.h ) .
169 .Sh RETURN VALUES
170 The
171 .Fn kvm_open
172 and
173 .Fn kvm_openfiles
174 functions both return a descriptor to be used
175 in all subsequent kvm library calls.
176 The library is fully re-entrant.
177 On failure,
178 .Dv NULL
179 is returned, in which case
180 .Fn kvm_openfiles
181 writes the error message into
182 .Fa errbuf .
183 .Pp
184 The
185 .Fn kvm_close
186 function returns 0 on success and -1 on failure.
187 .Sh SEE ALSO
188 .Xr open 2 ,
189 .Xr kvm 3 ,
190 .Xr kvm_getargv 3 ,
191 .Xr kvm_getenvv 3 ,
192 .Xr kvm_geterr 3 ,
193 .Xr kvm_getprocs 3 ,
194 .Xr kvm_nlist 3 ,
195 .Xr kvm_read 3 ,
196 .Xr kvm_write 3
197 .Sh BUGS
198 There should not be two open calls.
199 The ill-defined error semantics
200 of the Sun library and the desire to have a backward-compatible library
201 for
202 .Bx
203 left little choice.