xref: /csrg-svn/lib/libkvm/kvm_open.3 (revision 66949)
161278Sbostic.\" Copyright (c) 1992, 1993
261278Sbostic.\"	The Regents of the University of California.  All rights reserved.
353110Smckusick.\"
453658Sbostic.\" This code is derived from software developed by the Computer Systems
553658Sbostic.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
653658Sbostic.\" BG 91-66 and contributed to Berkeley.
753658Sbostic.\"
853110Smckusick.\" %sccs.include.redist.man%
953110Smckusick.\"
10*66949Sbostic.\"     @(#)kvm_open.3	8.3 (Berkeley) 04/19/94
1153110Smckusick.\"
1253110Smckusick.Dd
1353110Smckusick.Dt KVM_OPEN 3
1453110Smckusick.Os
1553110Smckusick.Sh NAME
1653110Smckusick.Nm kvm_open ,
1753293Sbostic.Nm kvm_openfiles ,
1853110Smckusick.Nm kvm_close
1953110Smckusick.Nd initialize kernel virtual memory access
2053110Smckusick.Sh SYNOPSIS
2154356Sbostic.Fd #include <fcntl.h>
2253110Smckusick.Fd #include <kvm.h>
2353110Smckusick.br
2453110Smckusick.Ft kvm_t *
2553110Smckusick.Fn kvm_open "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "const char *errstr"
2653110Smckusick.Ft kvm_t *
2754551Sbostic.Fn kvm_openfiles "const char *execfile" "const char *corefile" "char *swapfile" "int flags" "char *errbuf"
2853110Smckusick.Ft int
2953110Smckusick.Fn kvm_close "kvm_t *kd"
3053110Smckusick.Sh DESCRIPTION
3153293SbosticThe functions
3253110Smckusick.Fn kvm_open
3353110Smckusickand
3453110Smckusick.Fn kvm_openfiles
3553110Smckusickreturn a descriptor used to access kernel virtual memory
3653110Smckusickvia the
3753110Smckusick.Xr kvm 3
3853110Smckusicklibrary routines.  Both active kernels and crash dumps are accessible
3953110Smckusickthrough this interface.
4053110Smckusick.Pp
4153110Smckusick.Fa execfile
4253110Smckusickis the executable image of the kernel being examined.
4353110SmckusickThis file must contain a symbol table.
4453293SbosticIf this argument is
4553293Sbostic.Dv NULL ,
4653293Sbosticthe currently running system is assumed,
4753293Sbosticwhich is indicated by
4853293Sbostic.Dv _PATH_UNIX
4953293Sbosticin <paths.h>.
5053110Smckusick.Pp
5153110Smckusick.Fa corefile
5253110Smckusickis the kernel memory device file.  It can be either /dev/mem
5353110Smckusickor a crash dump core generated by
5453110Smckusick.Xr savecore 8 .
5553110SmckusickIf
5653110Smckusick.Fa corefile
5753293Sbosticis
5853293Sbostic.Dv NULL ,
5953293Sbosticthe default indicated by
6053293Sbostic.Dv _PATH_MEM
6153293Sbosticfrom <paths.h> is used.
6253110Smckusick.Pp
6353110Smckusick.Fa swapfile
6453293Sbosticshould indicate the swap device.  If
6553293Sbostic.Dv NULL ,
6653293Sbostic.Dv _PATH_DRUM
6753293Sbosticfrom <paths.h> is used.
6853110Smckusick.Pp
6953110SmckusickThe
7053110Smckusick.Fa flags
7153293Sbosticargument indicates read/write access as in
7253110Smckusick.Xr open 2
7365099Smckusickand applies only to the core file.
7453293SbosticOnly
7553293Sbostic.Dv O_RDONLY ,
7653293Sbostic.Dv O_WRONLY ,
7753293Sbosticand
7853293Sbostic.Dv O_RDWR
7953293Sbosticare permitted.
8053110Smckusick.Pp
8153110SmckusickThere are two open routines which differ only with respect to
8253110Smckusickthe error mechanism.
8353110SmckusickOne provides backward compatibility with the SunOS kvm library, while the
8453110Smckusickother provides an improved error reporting framework.
8553110Smckusick.Pp
8653110SmckusickThe
8753110Smckusick.Fn kvm_open
8853110Smckusickfunction is the Sun kvm compatible open call.  Here, the
8953110Smckusick.Fa errstr
9053293Sbosticargument indicates how errors should be handled.  If it is
9153293Sbostic.Dv NULL ,
9253293Sbosticno errors are reported and the application cannot know the
9353110Smckusickspecific nature of the failed kvm call.
9453293SbosticIf it is not
9553293Sbostic.Dv NULL ,
9653293Sbosticerrors are printed to stderr with
9753110Smckusick.Fa errstr
9853110Smckusickprepended to the message, as in
9953110Smckusick.Xr perror 3 .
10053110SmckusickNormally, the name of the program is used here.
10153293SbosticThe string is assumed to persist at least until the corresponding
10253293Sbostic.Fn kvm_close
10353293Sbosticcall.
10453110Smckusick.Pp
10553110SmckusickThe
10653110Smckusick.Fn kvm_openfiles
10753110Smckusickfunction provides BSD style error reporting.
10853110SmckusickHere, error messages are not printed out by the library.
10953110SmckusickInstead, the application obtains the error message
11053110Smckusickcorresponding to the most recent kvm library call using
11153110Smckusick.Fn kvm_geterr
11253110Smckusick(see
11353110Smckusick.Xr kvm_geterr 3 ).
11453110SmckusickThe results are undefined if the most recent kvm call did not produce
11553110Smckusickan error.
11653110SmckusickSince
11753110Smckusick.Fn kvm_geterr
11853293Sbosticrequires a kvm descriptor, but the open routines return
11953293Sbostic.Dv NULL
12053293Sbosticon failure,
12153110Smckusick.Fn kvm_geterr
12253110Smckusickcannot be used to get the error message if open fails.
12353110SmckusickThus,
12453293Sbostic.Fn kvm_openfiles
12553110Smckusickwill place any error message in the
12653110Smckusick.Fa errbuf
12753110Smckusickargument.  This buffer should be _POSIX2_LINE_MAX characters large (from
12853293Sbostic<limits.h>).
12953110Smckusick.Sh RETURN VALUES
13053293SbosticThe
13153110Smckusick.Fn kvm_open
13253110Smckusickand
13353110Smckusick.Fn kvm_openfiles
13453293Sbosticfunctions both return a descriptor to be used
13553293Sbosticin all subsequent kvm library calls.
13653110SmckusickThe library is fully re-entrant.
13753293SbosticOn failure,
13853293Sbostic.Dv NULL
13953293Sbosticis returned, in which case
14053110Smckusick.Fn kvm_openfiles
14153110Smckusickwrites the error message into
14253110Smckusick.Fa errbuf .
14353110Smckusick.Pp
14453293SbosticThe
14553110Smckusick.Fn kvm_close
146*66949Sbosticfunction returns 0 on success and -1 on failure.
14753110Smckusick.Sh BUGS
14853110SmckusickThere should not be two open calls.  The ill-defined error semantics
14953110Smckusickof the Sun library and the desire to have a backward-compatible library
15053110Smckusickfor BSD left little choice.
15153110Smckusick.Sh SEE ALSO
15253293Sbostic.Xr open 2 ,
15353293Sbostic.Xr kvm 3 ,
15453293Sbostic.Xr kvm_getargv 3 ,
15553293Sbostic.Xr kvm_getenvv 3 ,
15653293Sbostic.Xr kvm_geterr 3 ,
15753293Sbostic.Xr kvm_getprocs 3 ,
15853293Sbostic.Xr kvm_nlist 3 ,
15953293Sbostic.Xr kvm_read 3 ,
16053293Sbostic.Xr kvm_write 3
161