1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
.\" $NetBSD: ksyms.4,v 1.10 2024/07/27 13:14:04 uwe Exp $
.\"
.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd July 27, 2024
.Dt KSYMS 4
.Os
.Sh NAME
.Nm ksyms
.Nd kernel symbol table interface
.Sh SYNOPSIS
.Cd "pseudo-device ksyms"
.Sh DESCRIPTION
The
.Pa /dev/ksyms
character device provides a read-only interface to the current
kernel symbol table.
It can be accessed either as a sequential
file, where it looks like an executable file but with zero-sized
text and data segments, or via
.Xr ioctl 2 .
.Pp
.Pa /dev/ksyms
represents the symbol table at the time when the device is opened,
and may not change until it is closed.
.Pp
The in-kernel symbol manager is designed to be able to handle
any type of symbol table.
However, only
.Xr elf 5
symbol tables are currently dealt with.
.Sh IOCTLS
The
.Xr ioctl 2
command codes below are defined in
.In sys/ksyms.h .
.Pp
The (third) argument to the
.Xr ioctl 2
should be a pointer to the type indicated.
.Bl -tag -width Dv -offset indent
.It Dv KIOCGSIZE Pq Vt int
Returns the total size of the current symbol table.
This should be used when allocating a buffer to read in the
whole symbol table to memory.
.It Dv KIOCGVALUE Pq Vt struct ksyms_gvalue
Returns the value for the given symbol name in a symtab-independent
fashion.
.Bd -literal -offset indent
struct ksyms_gvalue {
const char *kv_name;
uint64_t kv_value;
};
.Ed
.Pp
The struct member
.Fa kv_name
should be set to the name of the requested value, and upon return
.Fa kv_value
contains the symbol value.
.It Dv KIOCGSYMBOL Pq Vt struct ksyms_gsymbol
Returns the complete symbol for the given symbol name.
.Bd -literal -offset indent
struct ksyms_gsymbol {
const char *kg_name;
void *kg_sym;
};
.Ed
.Pp
The struct member
.Fa kg_name
should be set to the name of the requested symbol, and the found
symbol will be written to the
.Fa kg_sym
address.
It is the callers responsibility to ensure that enough space
for the symbol is allocated.
.El
.Sh FILES
.Bl -tag -width Pa
.It Pa /dev/ksyms
.El
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr nlist 3 ,
.Xr elf 5
.Sh HISTORY
A
.Nm
device exists in many different operating systems.
This implementation is modelled in function after Solaris
.Nm .
This
.Nm
driver was written by Anders Magnusson for
.Nx .
.Pp
The
.Nm
driver first appeared in
.Nx 2.0 .
|