aboutsummaryrefslogtreecommitdiff
path: root/share/man/man4/ksyms.4
blob: d12f46001b8642a525d81811054d4bc902dc2c9b (plain) (blame)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
.\" Copyright (c) 2008-2009 Stacey Son <sson@freebsd.org> 
.\"	The Regents of the University of California.  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.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
.\"
.\" $FreeBSD$
.\"
.Dd April 5, 2009
.Dt KSYMS 4
.Os
.Sh NAME
.Nm ksyms
.Nd kernel symbol table interface
.Sh SYNOPSIS
.Cd "device ksyms"
.Sh DESCRIPTION
The
.Pa /dev/ksyms
character device provides a read-only interface to a snapshot of the kernel 
symbol table.  The in-kernel symbol manager is designed to be able to handle
many types of symbols tables, however, only 
.Xr elf 5
symbol tables are supported by this device.  The ELF format image contains two
sections: a symbol table and a corresponding string table.  
.Bl -tag -width indent -offset indent
.It Dv Symbol Table
The SYMTAB section contains the symbol table entries present in the current 
running kernel, including the symbol table entries of any loaded modules. The
symbols are ordered by the kernel module load time starting with kernel file
symbols first, followed by the first loaded module's symbols and so on.
.It Dv String Table
The STRTAB section contains the symbol name strings from the kernel and any
loaded modules that the symbol table entries reference.
.El
.Pp
Elf formated symbol table data read from the
.Pa /dev/ksyms
file represents the state of the kernel at the time when the device is opened.
Since
.Pa /dev/ksyms
has no text or data, most of the fields are initialized to NULL.
The 
.Nm 
driver does not block the loading or unloading of modules into the kernel
while the 
.Pa /dev/ksyms
file is open but may contain stale data.
.Sh IOCTLS
The
.Xr ioctl 2
command codes below are defined in
.Aq Pa sys/ksyms.h .
.Pp
The (third) argument to the
.Xr ioctl 2
should be a pointer to the type indicated.
.Bl -tag -width indent -offset indent
.It Dv KIOCGSIZE (size_t)
Returns the total size of the current symbol table.
This can be used when allocating a buffer to make a copy of
the kernel symbol table.
.It Dv KIOCGADDR (void *)
Returns the address of the kernel symbol table mapped in
the process memory.  
.El
.Sh FILES
.Bl -tag -width /dev/ksymsX
.It Pa /dev/ksyms
.El
.Sh ERRORS
An 
.Xr open 2
of
.Pa /dev/ksyms
will fail if: 
.Bl -tag -width Er
.It Bq Er EBUSY
The device is already open.  A process must close 
.Pa /dev/ksyms
before it can be opened again. 
.It Bq Er ENOMEM
There is a resource shortage in the kernel.
.It Bq Er ENXIO
The driver was unsuccessful in creating a snapshot of the kernel symbol
table.  This may occur if the kernel was in the process of loading or
unloading a module. 
.El
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr nlist 3 ,
.Xr elf 5 ,
.Xr kldload 8
.Sh HISTORY
A
.Nm
device exists in many different operating systems.
This implementation is similar in function to the Solaris and NetBSD
.Nm
driver.
.Pp
The
.Nm
driver first appeared in
.Fx 8.0
to support 
.Xr lockstat 1 .
.Sh AUTHORS
The
.Nm
driver was written by
.An Stacey Son
.Aq sson@freebsd.org .
.Sh BUGS
Because files can be dynamically linked into the kernel at any time the symbol 
information can vary.  When you open the
.Pa /dev/ksyms
file, you have access to an ELF image which represents a snapshot of the state of the kernel symbol information at that instant in time. Keeping the device open does not block the loading or unloading of kernel modules.  To get a new snapshot you must close and re-open the device.
.Pp
A process is only allowed to open the
.Pa /dev/ksyms
file once at a time.  The process must close the
.Pa /dev/ksyms
before it is allowed to open it again.
.Pp 
The
.Nm
driver uses the calling process' memory address space to store the snapshot.  
.Xr ioctl 2
can be used to get the memory address where the symbol table is stored to
save kernel memory. 
.Xr mmap 2
may also be used but it will map it to another address.