2010-05-19 08:57:53 +00:00
. \" Copyright (c) 2008-2009 Stacey Son <sson@FreeBSD.org>
2009-05-26 21:39:09 +00:00
. \" 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
2012-03-29 05:02:12 +00:00
character device provides a read-only interface to a snapshot of the kernel
2009-05-26 21:39:09 +00:00
symbol table. The in-kernel symbol manager is designed to be able to handle
2012-03-29 05:02:12 +00:00
many types of symbols tables, however, only
2009-05-26 21:39:09 +00:00
.Xr elf 5
symbol tables are supported by this device. The ELF format image contains two
2012-03-29 05:02:12 +00:00
sections: a symbol table and a corresponding string table.
2009-05-26 21:39:09 +00:00
.Bl -tag -width indent -offset indent
.It Dv Symbol Table
2012-03-29 05:02:12 +00:00
The SYMTAB section contains the symbol table entries present in the current
2009-05-26 21:39:09 +00:00
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
2010-07-31 12:14:28 +00:00
Elf formatted symbol table data read from the
2009-05-26 21:39:09 +00:00
.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.
2012-03-29 05:02:12 +00:00
The
.Nm
2009-05-26 21:39:09 +00:00
driver does not block the loading or unloading of modules into the kernel
2012-03-29 05:02:12 +00:00
while the
2009-05-26 21:39:09 +00:00
.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
2012-03-29 05:02:12 +00:00
the process memory.
2009-05-26 21:39:09 +00:00
.El
.Sh FILES
.Bl -tag -width /dev/ksymsX
.It Pa /dev/ksyms
.El
.Sh ERRORS
2012-03-29 05:02:12 +00:00
An
2009-05-26 21:39:09 +00:00
.Xr open 2
of
.Pa /dev/ksyms
2012-03-29 05:02:12 +00:00
will fail if:
2009-05-26 21:39:09 +00:00
.Bl -tag -width Er
.It Bq Er EBUSY
2012-03-29 05:02:12 +00:00
The device is already open. A process must close
2009-05-26 21:39:09 +00:00
.Pa /dev/ksyms
2012-03-29 05:02:12 +00:00
before it can be opened again.
2009-05-26 21:39:09 +00:00
.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
2012-03-29 05:02:12 +00:00
unloading a module.
2009-05-26 21:39:09 +00:00
.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
2012-03-29 05:02:12 +00:00
to support
2009-05-26 21:39:09 +00:00
.Xr lockstat 1 .
2010-05-13 12:07:55 +00:00
.Sh AUTHORS
The
.Nm
driver was written by
.An Stacey Son
2010-05-19 08:57:53 +00:00
.Aq sson@FreeBSD.org .
2009-05-26 21:39:09 +00:00
.Sh BUGS
2012-03-29 05:02:12 +00:00
Because files can be dynamically linked into the kernel at any time the symbol
2009-05-26 21:39:09 +00:00
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.
2012-03-29 05:02:12 +00:00
.Pp
2009-05-26 21:39:09 +00:00
The
.Nm
2012-03-29 05:02:12 +00:00
driver uses the calling process' memory address space to store the snapshot.
2009-05-26 21:39:09 +00:00
.Xr ioctl 2
can be used to get the memory address where the symbol table is stored to
2012-03-29 05:02:12 +00:00
save kernel memory.
2009-05-26 21:39:09 +00:00
.Xr mmap 2
2012-03-29 05:02:12 +00:00
may also be used but it will map it to another address.