xref: /original-bsd/lib/libkvm/kvm_open.3 (revision e58c8952)
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.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)kvm_open.3	8.3 (Berkeley) 04/19/94
11.\"
12.Dd
13.Dt KVM_OPEN 3
14.Os
15.Sh NAME
16.Nm kvm_open ,
17.Nm kvm_openfiles ,
18.Nm kvm_close
19.Nd initialize kernel virtual memory access
20.Sh SYNOPSIS
21.Fd #include <fcntl.h>
22.Fd #include <kvm.h>
23.br
24.Ft kvm_t *
25.Fn kvm_open "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "const char *errstr"
26.Ft kvm_t *
27.Fn kvm_openfiles "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "char *errbuf"
28.Ft int
29.Fn kvm_close "kvm_t *kd"
30.Sh DESCRIPTION
31The functions
32.Fn kvm_open
33and
34.Fn kvm_openfiles
35return a descriptor used to access kernel virtual memory
36via the
37.Xr kvm 3
38library routines.  Both active kernels and crash dumps are accessible
39through this interface.
40.Pp
41.Fa execfile
42is the executable image of the kernel being examined.
43This file must contain a symbol table.
44If this argument is
45.Dv NULL ,
46the currently running system is assumed,
47which is indicated by
48.Dv _PATH_UNIX
49in <paths.h>.
50.Pp
51.Fa corefile
52is the kernel memory device file.  It can be either /dev/mem
53or a crash dump core generated by
54.Xr savecore 8 .
55If
56.Fa corefile
57is
58.Dv NULL ,
59the default indicated by
60.Dv _PATH_MEM
61from <paths.h> is used.
62.Pp
63.Fa swapfile
64should indicate the swap device.  If
65.Dv NULL ,
66.Dv _PATH_DRUM
67from <paths.h> is used.
68.Pp
69The
70.Fa flags
71argument indicates read/write access as in
72.Xr open 2
73and applies only to the core file.
74Only
75.Dv O_RDONLY ,
76.Dv O_WRONLY ,
77and
78.Dv O_RDWR
79are permitted.
80.Pp
81There are two open routines which differ only with respect to
82the error mechanism.
83One provides backward compatibility with the SunOS kvm library, while the
84other provides an improved error reporting framework.
85.Pp
86The
87.Fn kvm_open
88function is the Sun kvm compatible open call.  Here, the
89.Fa errstr
90argument indicates how errors should be handled.  If it is
91.Dv NULL ,
92no errors are reported and the application cannot know the
93specific nature of the failed kvm call.
94If it is not
95.Dv NULL ,
96errors are printed to stderr with
97.Fa errstr
98prepended to the message, as in
99.Xr perror 3 .
100Normally, the name of the program is used here.
101The string is assumed to persist at least until the corresponding
102.Fn kvm_close
103call.
104.Pp
105The
106.Fn kvm_openfiles
107function provides BSD style error reporting.
108Here, error messages are not printed out by the library.
109Instead, the application obtains the error message
110corresponding to the most recent kvm library call using
111.Fn kvm_geterr
112(see
113.Xr kvm_geterr 3 ).
114The results are undefined if the most recent kvm call did not produce
115an error.
116Since
117.Fn kvm_geterr
118requires a kvm descriptor, but the open routines return
119.Dv NULL
120on failure,
121.Fn kvm_geterr
122cannot be used to get the error message if open fails.
123Thus,
124.Fn kvm_openfiles
125will place any error message in the
126.Fa errbuf
127argument.  This buffer should be _POSIX2_LINE_MAX characters large (from
128<limits.h>).
129.Sh RETURN VALUES
130The
131.Fn kvm_open
132and
133.Fn kvm_openfiles
134functions both return a descriptor to be used
135in all subsequent kvm library calls.
136The library is fully re-entrant.
137On failure,
138.Dv NULL
139is returned, in which case
140.Fn kvm_openfiles
141writes the error message into
142.Fa errbuf .
143.Pp
144The
145.Fn kvm_close
146function returns 0 on success and -1 on failure.
147.Sh BUGS
148There should not be two open calls.  The ill-defined error semantics
149of the Sun library and the desire to have a backward-compatible library
150for BSD left little choice.
151.Sh SEE ALSO
152.Xr open 2 ,
153.Xr kvm 3 ,
154.Xr kvm_getargv 3 ,
155.Xr kvm_getenvv 3 ,
156.Xr kvm_geterr 3 ,
157.Xr kvm_getprocs 3 ,
158.Xr kvm_nlist 3 ,
159.Xr kvm_read 3 ,
160.Xr kvm_write 3
161