format fixes
[unix-history] / usr / src / lib / libkvm / kvm_open.3
CommitLineData
b8b13822
KM
1.\" Copyright (c) 1992 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\" @(#)kvm_open.3 5.1 (Berkeley) %G%
7.\"
8.Dd
9.Dt KVM_OPEN 3
10.Os
11.Sh NAME
12.Nm kvm_open ,
13.Nm kvm_close
14.Nd initialize kernel virtual memory access
15.Sh SYNOPSIS
16.Fd #include <kvm.h>
17.\" .Fa kvm_t *kd
18.br
19.Ft kvm_t *
20.Fn kvm_open "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "const char *errstr"
21.Ft kvm_t *
22.Fn kvm_openfiles "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "const char *errbuf"
23.Ft int
24.Fn kvm_close "kvm_t *kd"
25.Sh DESCRIPTION
26.Fn kvm_open
27and
28.Fn kvm_openfiles
29return a descriptor used to access kernel virtual memory
30via the
31.Xr kvm 3
32library routines. Both active kernels and crash dumps are accessible
33through this interface.
34.Pp
35.Fa execfile
36is the executable image of the kernel being examined.
37This file must contain a symbol table.
38If this argument is NULL, the currently running system is assumed,
39which is indicated by _PATH_UNIX in <paths.h>.
40.Pp
41.Fa corefile
42is the kernel memory device file. It can be either /dev/mem
43or a crash dump core generated by
44.Xr savecore 8 .
45If
46.Fa corefile
47is null, the default indicated by _PATH_MEM is used.
48.Pp
49.Fa swapfile
50should indicate the swap device. If NULL, _PATH_DRUM from <paths.h>
51is used.
52.Pp
53The
54.Fa flags
55argument indicates the read/write access as in
56.Xr open 2
57and applies to only the core file.
58Only O_RDONLY, O_WRONLY, and O_RDWR are permitted.
59.Pp
60There are two open routines which differ only with respect to
61the error mechanism.
62One provides backward compatibility with the SunOS kvm library, while the
63other provides an improved error reporting framework.
64.Pp
65The
66.Fn kvm_open
67function is the Sun kvm compatible open call. Here, the
68.Fa errstr
69argument indicates how errors should be handled. If it is NULL,
70then no errors are reporting and the application cannot know the
71specific nature of the failed kvm call.
72If it is not NULL, then errors are printed to stderr with
73.Fa errstr
74prepended to the message, as in
75.Xr perror 3 .
76Normally, the name of the program is used here.
77The string is assumed to be persistent.
78.Pp
79The
80.Fn kvm_openfiles
81function provides BSD style error reporting.
82Here, error messages are not printed out by the library.
83Instead, the application obtains the error message
84corresponding to the most recent kvm library call using
85.Fn kvm_geterr
86(see
87.Xr kvm_geterr 3 ).
88The results are undefined if the most recent kvm call did not produce
89an error.
90Since
91.Fn kvm_geterr
92requires a kvm descriptor, but the open routines return NULL on failure,
93.Fn kvm_geterr
94cannot be used to get the error message if open fails.
95Thus,
96.Fn kvm_openfiles ,
97will place any error message in the
98.Fa errbuf
99argument. This buffer should be _POSIX2_LINE_MAX characters large (from
100<limits.h>)
101.Sh RETURN VALUES
102.Fn kvm_open
103and
104.Fn kvm_openfiles
105both return a descriptor to be used in all subsequent kvm library calls.
106The library is fully re-entrant.
107On failure, NULL is returned, in which case
108.Fn kvm_openfiles
109writes the error message into
110.Fa errbuf .
111.Pp
112.Fn kvm_close
113returns 0 on sucess and -1 on failure.
114.Sh BUGS
115There should not be two open calls. The ill-defined error semantics
116of the Sun library and the desire to have a backward-compatible library
117for BSD left little choice.
118.Sh SEE ALSO
119.Xr kvm 3