xref: /freebsd/lib/libkvm/kvm_open.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
158f0484fSRodney W. Grimes.\" Copyright (c) 1992, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" This code is derived from software developed by the Computer Systems
558f0484fSRodney W. Grimes.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
658f0484fSRodney W. Grimes.\" BG 91-66 and contributed to Berkeley.
758f0484fSRodney W. Grimes.\"
858f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
958f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
1058f0484fSRodney W. Grimes.\" are met:
1158f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1258f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1358f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1458f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1558f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
16fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
3254fc00f7SEnji Cooper.Dd March 20, 2017
3358f0484fSRodney W. Grimes.Dt KVM_OPEN 3
3458f0484fSRodney W. Grimes.Os
3558f0484fSRodney W. Grimes.Sh NAME
3658f0484fSRodney W. Grimes.Nm kvm_open ,
377f911abeSJohn Baldwin.Nm kvm_open2 ,
3858f0484fSRodney W. Grimes.Nm kvm_openfiles ,
3958f0484fSRodney W. Grimes.Nm kvm_close
4058f0484fSRodney W. Grimes.Nd initialize kernel virtual memory access
417f5e8c84SAlexey Zelkin.Sh LIBRARY
427f5e8c84SAlexey Zelkin.Lb libkvm
4358f0484fSRodney W. Grimes.Sh SYNOPSIS
4432eef9aeSRuslan Ermilov.In fcntl.h
4532eef9aeSRuslan Ermilov.In kvm.h
4658f0484fSRodney W. Grimes.Ft kvm_t *
4777667e9eSBruce Evans.Fn kvm_open "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "const char *errstr"
4858f0484fSRodney W. Grimes.Ft kvm_t *
497f911abeSJohn Baldwin.Fo kvm_open2
507f911abeSJohn Baldwin.Fa "const char *execfile"
517f911abeSJohn Baldwin.Fa "const char *corefile"
527f911abeSJohn Baldwin.Fa "int flags"
537f911abeSJohn Baldwin.Fa "char *errbuf"
547f911abeSJohn Baldwin.Fa "int (*resolver)(const char *name, kvaddr_t *addr)"
557f911abeSJohn Baldwin.Fc
567f911abeSJohn Baldwin.Ft kvm_t *
5777667e9eSBruce Evans.Fn kvm_openfiles "const char *execfile" "const char *corefile" "const char *swapfile" "int flags" "char *errbuf"
5858f0484fSRodney W. Grimes.Ft int
5958f0484fSRodney W. Grimes.Fn kvm_close "kvm_t *kd"
6058f0484fSRodney W. Grimes.Sh DESCRIPTION
6158f0484fSRodney W. GrimesThe functions
627f911abeSJohn Baldwin.Fn kvm_open ,
637f911abeSJohn Baldwin.Fn kvm_open2 ,
6458f0484fSRodney W. Grimesand
6558f0484fSRodney W. Grimes.Fn kvm_openfiles
6658f0484fSRodney W. Grimesreturn a descriptor used to access kernel virtual memory
6758f0484fSRodney W. Grimesvia the
6858f0484fSRodney W. Grimes.Xr kvm 3
691a0a9345SRuslan Ermilovlibrary routines.
701a0a9345SRuslan ErmilovBoth active kernels and crash dumps are accessible
7158f0484fSRodney W. Grimesthrough this interface.
7258f0484fSRodney W. Grimes.Pp
734cacb618SPhilippe CharnierThe
7458f0484fSRodney W. Grimes.Fa execfile
754cacb618SPhilippe Charnierargument is the executable image of the kernel being examined.
7658f0484fSRodney W. GrimesThis file must contain a symbol table.
7758f0484fSRodney W. GrimesIf this argument is
7858f0484fSRodney W. Grimes.Dv NULL ,
7958f0484fSRodney W. Grimesthe currently running system is assumed,
804be4929cSGarrett Wollmanas determined from
814be4929cSGarrett Wollman.Xr getbootfile 3 .
8258f0484fSRodney W. Grimes.Pp
834cacb618SPhilippe CharnierThe
8458f0484fSRodney W. Grimes.Fa corefile
8527692448SRuslan Ermilovargument is the kernel memory device file.
8627692448SRuslan ErmilovIt can be either
8727692448SRuslan Ermilov.Pa /dev/mem
8858f0484fSRodney W. Grimesor a crash dump core generated by
8958f0484fSRodney W. Grimes.Xr savecore 8 .
9058f0484fSRodney W. GrimesIf
9158f0484fSRodney W. Grimes.Fa corefile
9258f0484fSRodney W. Grimesis
9358f0484fSRodney W. Grimes.Dv NULL ,
9458f0484fSRodney W. Grimesthe default indicated by
9558f0484fSRodney W. Grimes.Dv _PATH_MEM
9627692448SRuslan Ermilovfrom
9727692448SRuslan Ermilov.In paths.h
9827692448SRuslan Ermilovis used.
9927692448SRuslan ErmilovIt can also be set to a special value
10027692448SRuslan Ermilov.Pa /dev/null
10127692448SRuslan Ermilovby utilities like
10227692448SRuslan Ermilov.Xr ps 1
10327692448SRuslan Ermilovthat do not directly access kernel memory.
10458f0484fSRodney W. Grimes.Pp
105fe42e96eSRuslan ErmilovThe
10658f0484fSRodney W. Grimes.Fa swapfile
107fe42e96eSRuslan Ermilovargument is currently unused.
10858f0484fSRodney W. Grimes.Pp
10958f0484fSRodney W. GrimesThe
11058f0484fSRodney W. Grimes.Fa flags
11158f0484fSRodney W. Grimesargument indicates read/write access as in
11258f0484fSRodney W. Grimes.Xr open 2
11358f0484fSRodney W. Grimesand applies only to the core file.
11458f0484fSRodney W. GrimesOnly
11558f0484fSRodney W. Grimes.Dv O_RDONLY ,
11658f0484fSRodney W. Grimes.Dv O_WRONLY ,
11758f0484fSRodney W. Grimesand
11858f0484fSRodney W. Grimes.Dv O_RDWR
11958f0484fSRodney W. Grimesare permitted.
12058f0484fSRodney W. Grimes.Pp
1217f911abeSJohn BaldwinThe
1227f911abeSJohn Baldwin.Nm kvm
1237f911abeSJohn Baldwinlibrary provides two different error reporting mechanisms.
12458f0484fSRodney W. GrimesOne provides backward compatibility with the SunOS kvm library, while the
12558f0484fSRodney W. Grimesother provides an improved error reporting framework.
1267f911abeSJohn BaldwinThe mechanism used by a descriptor is determined by the function used to
1277f911abeSJohn Baldwinopen the descriptor.
12858f0484fSRodney W. Grimes.Pp
12958f0484fSRodney W. GrimesThe
13058f0484fSRodney W. Grimes.Fn kvm_open
1311a0a9345SRuslan Ermilovfunction is the Sun kvm compatible open call.
1321a0a9345SRuslan ErmilovHere, the
13358f0484fSRodney W. Grimes.Fa errstr
1341a0a9345SRuslan Ermilovargument indicates how errors should be handled.
1351a0a9345SRuslan ErmilovIf it is
13658f0484fSRodney W. Grimes.Dv NULL ,
13758f0484fSRodney W. Grimesno errors are reported and the application cannot know the
13858f0484fSRodney W. Grimesspecific nature of the failed kvm call.
13958f0484fSRodney W. GrimesIf it is not
14058f0484fSRodney W. Grimes.Dv NULL ,
141ae828962SRuslan Ermiloverrors are printed to
142ae828962SRuslan Ermilov.Dv stderr
143ae828962SRuslan Ermilovwith
14458f0484fSRodney W. Grimes.Fa errstr
14558f0484fSRodney W. Grimesprepended to the message, as in
14658f0484fSRodney W. Grimes.Xr perror 3 .
14758f0484fSRodney W. GrimesNormally, the name of the program is used here.
14858f0484fSRodney W. GrimesThe string is assumed to persist at least until the corresponding
14958f0484fSRodney W. Grimes.Fn kvm_close
15058f0484fSRodney W. Grimescall.
15158f0484fSRodney W. Grimes.Pp
15258f0484fSRodney W. GrimesThe
1537f911abeSJohn Baldwin.Fn kvm_open2
1547f911abeSJohn Baldwinand
15558f0484fSRodney W. Grimes.Fn kvm_openfiles
1567f911abeSJohn Baldwinfunctions provide
157753d686dSRuslan Ermilov.Bx
158753d686dSRuslan Ermilovstyle error reporting.
15958f0484fSRodney W. GrimesHere, error messages are not printed out by the library.
16058f0484fSRodney W. GrimesInstead, the application obtains the error message
16158f0484fSRodney W. Grimescorresponding to the most recent kvm library call using
16258f0484fSRodney W. Grimes.Fn kvm_geterr
16358f0484fSRodney W. Grimes(see
16458f0484fSRodney W. Grimes.Xr kvm_geterr 3 ) .
16558f0484fSRodney W. GrimesThe results are undefined if the most recent kvm call did not produce
16658f0484fSRodney W. Grimesan error.
16758f0484fSRodney W. GrimesSince
16858f0484fSRodney W. Grimes.Fn kvm_geterr
16958f0484fSRodney W. Grimesrequires a kvm descriptor, but the open routines return
17058f0484fSRodney W. Grimes.Dv NULL
17158f0484fSRodney W. Grimeson failure,
17258f0484fSRodney W. Grimes.Fn kvm_geterr
17358f0484fSRodney W. Grimescannot be used to get the error message if open fails.
17458f0484fSRodney W. GrimesThus,
1757f911abeSJohn Baldwin.Fn kvm_open2
1767f911abeSJohn Baldwinand
17758f0484fSRodney W. Grimes.Fn kvm_openfiles
17858f0484fSRodney W. Grimeswill place any error message in the
17958f0484fSRodney W. Grimes.Fa errbuf
1801a0a9345SRuslan Ermilovargument.
1811a0a9345SRuslan ErmilovThis buffer should be _POSIX2_LINE_MAX characters large (from
18258f0484fSRodney W. Grimes<limits.h>).
1837f911abeSJohn Baldwin.Pp
1847f911abeSJohn BaldwinThe
1857f911abeSJohn Baldwin.Fa resolver
1867f911abeSJohn Baldwinargument points to a function used by the
1877f911abeSJohn Baldwin.Nm kvm
1887f911abeSJohn Baldwinlibrary to map symbol names to kernel virtual addresses.
1897f911abeSJohn BaldwinWhen the
1907f911abeSJohn Baldwin.Fa resolver
1917f911abeSJohn Baldwinfunction is called,
1927f911abeSJohn Baldwin.Fa name
1937f911abeSJohn Baldwinspecifies the requested symbol name.
1947f911abeSJohn BaldwinIf the function is able to resolve the name to an address,
1957f911abeSJohn Baldwinthe address should be set in
1963eb11185SEnji Cooper.Fa addr
1977f911abeSJohn Baldwinand the function should return zero.
1987f911abeSJohn BaldwinIf the function is not able to resolve the name to an address,
1997f911abeSJohn Baldwinit should return a non-zero value.
2007f911abeSJohn BaldwinWhen opening a native kernel image,
2017f911abeSJohn Baldwin.Fa resolver
2027f911abeSJohn Baldwinmay be set to
2037f911abeSJohn Baldwin.Dv NULL
2047f911abeSJohn Baldwinto use an internal function to resolve symbol names.
2057f911abeSJohn BaldwinNon-native kernel images
2067f911abeSJohn Baldwin.Pq such as when cross-debugging a crash dump
2077f911abeSJohn Baldwinrequire a valid
2087f911abeSJohn Baldwin.Fa resolver .
20958f0484fSRodney W. Grimes.Sh RETURN VALUES
21058f0484fSRodney W. GrimesThe
2117f911abeSJohn Baldwin.Fn kvm_open ,
2127f911abeSJohn Baldwin.Fn kvm_open2 ,
21358f0484fSRodney W. Grimesand
21458f0484fSRodney W. Grimes.Fn kvm_openfiles
2157f911abeSJohn Baldwinfunctions return a descriptor to be used
21658f0484fSRodney W. Grimesin all subsequent kvm library calls.
21758f0484fSRodney W. GrimesThe library is fully re-entrant.
21858f0484fSRodney W. GrimesOn failure,
21958f0484fSRodney W. Grimes.Dv NULL
22058f0484fSRodney W. Grimesis returned, in which case
2217f911abeSJohn Baldwin.Fn kvm_open2
2227f911abeSJohn Baldwinand
22358f0484fSRodney W. Grimes.Fn kvm_openfiles
2247f911abeSJohn Baldwinwrite the error message into
22558f0484fSRodney W. Grimes.Fa errbuf .
22658f0484fSRodney W. Grimes.Pp
22754fc00f7SEnji Cooper.Rv -std kvm_close
22854fc00f7SEnji Cooper.Sh ERRORS
22958f0484fSRodney W. GrimesThe
23058f0484fSRodney W. Grimes.Fn kvm_close
23154fc00f7SEnji Cooperfunction may fail and set the global variable
23254fc00f7SEnji Cooper.Va errno
23354fc00f7SEnji Cooperfor any of the errors specified for
23454fc00f7SEnji Cooper.Xr close 2 .
23554fc00f7SEnji Cooper.Pp
23654fc00f7SEnji CooperThe
23754fc00f7SEnji Cooper.Fn kvm_close
23854fc00f7SEnji Cooperfunction may also fail and set
23954fc00f7SEnji Cooper.Va errno
24054fc00f7SEnji Cooperif:
24154fc00f7SEnji Cooper.Bl -tag -width Er
24254fc00f7SEnji Cooper.It Bq Er EINVAL
24354fc00f7SEnji CooperThe value passed via
24454fc00f7SEnji Cooper.Fa kd
24554fc00f7SEnji Cooperwas
24654fc00f7SEnji Cooper.Dv NULL .
24754fc00f7SEnji Cooper.El
24858f0484fSRodney W. Grimes.Sh SEE ALSO
24954fc00f7SEnji Cooper.Xr close 2 ,
25058f0484fSRodney W. Grimes.Xr open 2 ,
25158f0484fSRodney W. Grimes.Xr kvm 3 ,
25258f0484fSRodney W. Grimes.Xr kvm_getargv 3 ,
25358f0484fSRodney W. Grimes.Xr kvm_getenvv 3 ,
25458f0484fSRodney W. Grimes.Xr kvm_geterr 3 ,
25558f0484fSRodney W. Grimes.Xr kvm_getprocs 3 ,
2567f911abeSJohn Baldwin.Xr kvm_native 3 ,
25758f0484fSRodney W. Grimes.Xr kvm_nlist 3 ,
25858f0484fSRodney W. Grimes.Xr kvm_read 3 ,
25927692448SRuslan Ermilov.Xr kvm_write 3 ,
26027692448SRuslan Ermilov.Xr kmem 4 ,
26127692448SRuslan Ermilov.Xr mem 4
26224a0682cSRuslan Ermilov.Sh BUGS
2637f911abeSJohn BaldwinThere should not be three open calls.
26424a0682cSRuslan ErmilovThe ill-defined error semantics
26524a0682cSRuslan Ermilovof the Sun library and the desire to have a backward-compatible library
26624a0682cSRuslan Ermilovfor
26724a0682cSRuslan Ermilov.Bx
26824a0682cSRuslan Ermilovleft little choice.
269*0cd475f8SDavid E. O'Brien.Sh HISTORY
270*0cd475f8SDavid E. O'BrienThe
271*0cd475f8SDavid E. O'Brien.Fn kvm_open2
272*0cd475f8SDavid E. O'Brienfunction first appeared in
273*0cd475f8SDavid E. O'Brien.Fx 11.0 .
274