xref: /freebsd/lib/libkvm/kvm_read.3 (revision 6dced2c6358e467ac1dccd99f6f648d4f71957a8)
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. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd November 27, 2015
33.Dt KVM_READ 3
34.Os
35.Sh NAME
36.Nm kvm_read ,
37.Nm kvm_read2 ,
38.Nm kvm_write
39.Nd read or write kernel virtual memory
40.Sh LIBRARY
41.Lb libkvm
42.Sh SYNOPSIS
43.In kvm.h
44.Ft ssize_t
45.Fn kvm_read "kvm_t *kd" "unsigned long addr" "void *buf" "size_t nbytes"
46.Ft ssize_t
47.Fn kvm_read2 "kvm_t *kd" "kvaddr_t addr" "void *buf" "size_t nbytes"
48.Ft ssize_t
49.Fn kvm_write "kvm_t *kd" "unsigned long addr" "const void *buf" "size_t nbytes"
50.Sh DESCRIPTION
51The
52.Fn kvm_read ,
53.Fn kvm_read2 ,
54and
55.Fn kvm_write
56functions are used to read and write kernel virtual memory (or a crash
57dump file).
58See
59.Fn kvm_open 3
60for information regarding opening kernel virtual memory and crash dumps.
61.Pp
62The
63.Fn kvm_read
64and
65.Fn kvm_read2
66functions transfer
67.Fa nbytes
68bytes of data from
69the kernel space address
70.Fa addr
71to
72.Fa buf .
73Conversely,
74.Fn kvm_write
75transfers data from
76.Fa buf
77to
78.Fa addr .
79Unlike their SunOS counterparts, these functions cannot be used to
80read or write process address spaces.
81.Pp
82The
83.Fn kvm_read2
84function uses a different type
85.Pq Vt kvaddr_t
86for the
87.Fa addr
88argument to allow use of addresses larger than
89.Dv ULONG_MAX
90when examining non-native kernel images.
91.Sh RETURN VALUES
92Upon success, the number of bytes actually transferred is returned.
93Otherwise, -1 is returned.
94.Sh SEE ALSO
95.Xr kvm 3 ,
96.Xr kvm_close 3 ,
97.Xr kvm_getargv 3 ,
98.Xr kvm_getenvv 3 ,
99.Xr kvm_geterr 3 ,
100.Xr kvm_getprocs 3 ,
101.Xr kvm_nlist 3 ,
102.Xr kvm_open 3 ,
103.Xr kvm_openfiles 3
104.Sh HISTORY
105The
106.Fn kvm_read2
107function first appeared in
108.Fx 11.0 .
109