Clean up #include's in the SYNOPSIS.
[dragonfly.git] / lib / libkvm / kvm_open.3
CommitLineData
984263bc
MD
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. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" @(#)kvm_open.3 8.3 (Berkeley) 4/19/94
37.\" $FreeBSD: src/lib/libkvm/kvm_open.3,v 1.5.2.6 2001/12/17 10:08:30 ru Exp $
44cb301e 38.\" $DragonFly: src/lib/libkvm/kvm_open.3,v 1.4 2006/05/26 19:39:38 swildner Exp $
984263bc
MD
39.\"
40.Dd April 19, 1994
41.Dt KVM_OPEN 3
42.Os
43.Sh NAME
44.Nm kvm_open ,
45.Nm kvm_openfiles ,
46.Nm kvm_close
47.Nd initialize kernel virtual memory access
48.Sh LIBRARY
49.Lb libkvm
50.Sh SYNOPSIS
a9f0312e 51.In sys/types.h
984263bc
MD
52.In kvm.h
53.Ft kvm_t *
54.Fn kvm_open "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "const char *errstr"
55.Ft kvm_t *
56.Fn kvm_openfiles "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "char *errbuf"
57.Ft int
58.Fn kvm_close "kvm_t *kd"
59.Sh DESCRIPTION
60The functions
61.Fn kvm_open
62and
63.Fn kvm_openfiles
64return a descriptor used to access kernel virtual memory
65via the
66.Xr kvm 3
67library routines. Both active kernels and crash dumps are accessible
68through this interface.
69.Pp
70.Fa execfile
71is the executable image of the kernel being examined.
72This file must contain a symbol table.
73If this argument is
74.Dv NULL ,
75the currently running system is assumed,
76as determined from
77.Xr getbootfile 3 .
78.Pp
79.Fa corefile
80is the kernel memory device file. It can be either /dev/mem
81or a crash dump core generated by
82.Xr savecore 8 .
83If
84.Fa corefile
85is
86.Dv NULL ,
87the default indicated by
88.Dv _PATH_MEM
44cb301e
SW
89from
90.In paths.h
91is used.
984263bc
MD
92.Pp
93.Fa swapfile
94should indicate the swap device. If
95.Dv NULL ,
96.Dv _PATH_DRUM
44cb301e
SW
97from
98.In paths.h
99is used.
984263bc
MD
100.Pp
101The
102.Fa flags
103argument indicates read/write access as in
104.Xr open 2
105and applies only to the core file.
106Only
107.Dv O_RDONLY ,
108.Dv O_WRONLY ,
109and
110.Dv O_RDWR
111are permitted.
112.Pp
113There are two open routines which differ only with respect to
114the error mechanism.
115One provides backward compatibility with the SunOS kvm library, while the
116other provides an improved error reporting framework.
117.Pp
118The
119.Fn kvm_open
120function is the Sun kvm compatible open call. Here, the
121.Fa errstr
122argument indicates how errors should be handled. If it is
123.Dv NULL ,
124no errors are reported and the application cannot know the
125specific nature of the failed kvm call.
126If it is not
127.Dv NULL ,
128errors are printed to stderr with
129.Fa errstr
130prepended to the message, as in
131.Xr perror 3 .
132Normally, the name of the program is used here.
133The string is assumed to persist at least until the corresponding
134.Fn kvm_close
135call.
136.Pp
137The
138.Fn kvm_openfiles
139function provides
140.Bx
141style error reporting.
142Here, error messages are not printed out by the library.
143Instead, the application obtains the error message
144corresponding to the most recent kvm library call using
145.Fn kvm_geterr
146(see
147.Xr kvm_geterr 3 ) .
148The results are undefined if the most recent kvm call did not produce
149an error.
150Since
151.Fn kvm_geterr
152requires a kvm descriptor, but the open routines return
153.Dv NULL
154on failure,
155.Fn kvm_geterr
156cannot be used to get the error message if open fails.
157Thus,
158.Fn kvm_openfiles
159will place any error message in the
160.Fa errbuf
161argument. This buffer should be _POSIX2_LINE_MAX characters large (from
44cb301e 162.In limits.h ) .
984263bc
MD
163.Sh RETURN VALUES
164The
165.Fn kvm_open
166and
167.Fn kvm_openfiles
168functions both return a descriptor to be used
169in all subsequent kvm library calls.
170The library is fully re-entrant.
171On failure,
172.Dv NULL
173is returned, in which case
174.Fn kvm_openfiles
175writes the error message into
176.Fa errbuf .
177.Pp
178The
179.Fn kvm_close
180function returns 0 on success and -1 on failure.
984263bc
MD
181.Sh SEE ALSO
182.Xr open 2 ,
183.Xr kvm 3 ,
184.Xr kvm_getargv 3 ,
185.Xr kvm_getenvv 3 ,
186.Xr kvm_geterr 3 ,
187.Xr kvm_getprocs 3 ,
188.Xr kvm_nlist 3 ,
189.Xr kvm_read 3 ,
190.Xr kvm_write 3
0b84df5c
SW
191.Sh BUGS
192There should not be two open calls. The ill-defined error semantics
193of the Sun library and the desire to have a backward-compatible library
194for
195.Bx
196left little choice.