xref: /freebsd/share/man/man4/ksyms.4 (revision 00a5db46de56179184c0f000eaacad695e2b0859)
100a5db46SStacey Son.\" Copyright (c) 2008-2009 Stacey Son <sson@freebsd.org>
200a5db46SStacey Son.\"	The Regents of the University of California.  All rights reserved.
300a5db46SStacey Son.\"
400a5db46SStacey Son.\" Redistribution and use in source and binary forms, with or without
500a5db46SStacey Son.\" modification, are permitted provided that the following conditions
600a5db46SStacey Son.\" are met:
700a5db46SStacey Son.\" 1. Redistributions of source code must retain the above copyright
800a5db46SStacey Son.\"    notice, this list of conditions and the following disclaimer.
900a5db46SStacey Son.\" 2. Redistributions in binary form must reproduce the above copyright
1000a5db46SStacey Son.\"    notice, this list of conditions and the following disclaimer in the
1100a5db46SStacey Son.\"    documentation and/or other materials provided with the distribution.
1200a5db46SStacey Son.\" 3. All advertising materials mentioning features or use of this software
1300a5db46SStacey Son.\"    must display the following acknowledgement:
1400a5db46SStacey Son.\"	This product includes software developed by the University of
1500a5db46SStacey Son.\"	California, Berkeley and its contributors.
1600a5db46SStacey Son.\" 4. Neither the name of the University nor the names of its contributors
1700a5db46SStacey Son.\"    may be used to endorse or promote products derived from this software
1800a5db46SStacey Son.\"    without specific prior written permission.
1900a5db46SStacey Son.\"
2000a5db46SStacey Son.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2100a5db46SStacey Son.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2200a5db46SStacey Son.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2300a5db46SStacey Son.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2400a5db46SStacey Son.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2500a5db46SStacey Son.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2600a5db46SStacey Son.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2700a5db46SStacey Son.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2800a5db46SStacey Son.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2900a5db46SStacey Son.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3000a5db46SStacey Son.\" SUCH DAMAGE.
3100a5db46SStacey Son.\"
3200a5db46SStacey Son.\" $FreeBSD$
3300a5db46SStacey Son.\"
3400a5db46SStacey Son.Dd April 5, 2009
3500a5db46SStacey Son.Dt KSYMS 4
3600a5db46SStacey Son.Os
3700a5db46SStacey Son.Sh NAME
3800a5db46SStacey Son.Nm ksyms
3900a5db46SStacey Son.Nd kernel symbol table interface
4000a5db46SStacey Son.Sh SYNOPSIS
4100a5db46SStacey Son.Cd "device ksyms"
4200a5db46SStacey Son.Sh DESCRIPTION
4300a5db46SStacey SonThe
4400a5db46SStacey Son.Pa /dev/ksyms
4500a5db46SStacey Soncharacter device provides a read-only interface to a snapshot of the kernel
4600a5db46SStacey Sonsymbol table.  The in-kernel symbol manager is designed to be able to handle
4700a5db46SStacey Sonmany types of symbols tables, however, only
4800a5db46SStacey Son.Xr elf 5
4900a5db46SStacey Sonsymbol tables are supported by this device.  The ELF format image contains two
5000a5db46SStacey Sonsections: a symbol table and a corresponding string table.
5100a5db46SStacey Son.Bl -tag -width indent -offset indent
5200a5db46SStacey Son.It Dv Symbol Table
5300a5db46SStacey SonThe SYMTAB section contains the symbol table entries present in the current
5400a5db46SStacey Sonrunning kernel, including the symbol table entries of any loaded modules. The
5500a5db46SStacey Sonsymbols are ordered by the kernel module load time starting with kernel file
5600a5db46SStacey Sonsymbols first, followed by the first loaded module's symbols and so on.
5700a5db46SStacey Son.It Dv String Table
5800a5db46SStacey SonThe STRTAB section contains the symbol name strings from the kernel and any
5900a5db46SStacey Sonloaded modules that the symbol table entries reference.
6000a5db46SStacey Son.El
6100a5db46SStacey Son.Pp
6200a5db46SStacey SonElf formated symbol table data read from the
6300a5db46SStacey Son.Pa /dev/ksyms
6400a5db46SStacey Sonfile represents the state of the kernel at the time when the device is opened.
6500a5db46SStacey SonSince
6600a5db46SStacey Son.Pa /dev/ksyms
6700a5db46SStacey Sonhas no text or data, most of the fields are initialized to NULL.
6800a5db46SStacey SonThe
6900a5db46SStacey Son.Nm
7000a5db46SStacey Sondriver does not block the loading or unloading of modules into the kernel
7100a5db46SStacey Sonwhile the
7200a5db46SStacey Son.Pa /dev/ksyms
7300a5db46SStacey Sonfile is open but may contain stale data.
7400a5db46SStacey Son.Sh IOCTLS
7500a5db46SStacey SonThe
7600a5db46SStacey Son.Xr ioctl 2
7700a5db46SStacey Soncommand codes below are defined in
7800a5db46SStacey Son.Aq Pa sys/ksyms.h .
7900a5db46SStacey Son.Pp
8000a5db46SStacey SonThe (third) argument to the
8100a5db46SStacey Son.Xr ioctl 2
8200a5db46SStacey Sonshould be a pointer to the type indicated.
8300a5db46SStacey Son.Bl -tag -width indent -offset indent
8400a5db46SStacey Son.It Dv KIOCGSIZE (size_t)
8500a5db46SStacey SonReturns the total size of the current symbol table.
8600a5db46SStacey SonThis can be used when allocating a buffer to make a copy of
8700a5db46SStacey Sonthe kernel symbol table.
8800a5db46SStacey Son.It Dv KIOCGADDR (void *)
8900a5db46SStacey SonReturns the address of the kernel symbol table mapped in
9000a5db46SStacey Sonthe process memory.
9100a5db46SStacey Son.El
9200a5db46SStacey Son.Sh FILES
9300a5db46SStacey Son.Bl -tag -width /dev/ksymsX
9400a5db46SStacey Son.It Pa /dev/ksyms
9500a5db46SStacey Son.El
9600a5db46SStacey Son.Sh ERRORS
9700a5db46SStacey SonAn
9800a5db46SStacey Son.Xr open 2
9900a5db46SStacey Sonof
10000a5db46SStacey Son.Pa /dev/ksyms
10100a5db46SStacey Sonwill fail if:
10200a5db46SStacey Son.Bl -tag -width Er
10300a5db46SStacey Son.It Bq Er EBUSY
10400a5db46SStacey SonThe device is already open.  A process must close
10500a5db46SStacey Son.Pa /dev/ksyms
10600a5db46SStacey Sonbefore it can be opened again.
10700a5db46SStacey Son.It Bq Er ENOMEM
10800a5db46SStacey SonThere is a resource shortage in the kernel.
10900a5db46SStacey Son.It Bq Er ENXIO
11000a5db46SStacey SonThe driver was unsuccessful in creating a snapshot of the kernel symbol
11100a5db46SStacey Sontable.  This may occur if the kernel was in the process of loading or
11200a5db46SStacey Sonunloading a module.
11300a5db46SStacey Son.El
11400a5db46SStacey Son.Sh SEE ALSO
11500a5db46SStacey Son.Xr ioctl 2 ,
11600a5db46SStacey Son.Xr nlist 3 ,
11700a5db46SStacey Son.Xr elf 5 ,
11800a5db46SStacey Son.Xr kldload 8
11900a5db46SStacey Son.Sh HISTORY
12000a5db46SStacey SonA
12100a5db46SStacey Son.Nm
12200a5db46SStacey Sondevice exists in many different operating systems.
12300a5db46SStacey SonThis implementation is similar in function to the Solaris and NetBSD
12400a5db46SStacey Son.Nm
12500a5db46SStacey Sondriver.
12600a5db46SStacey Son.Pp
12700a5db46SStacey SonThe
12800a5db46SStacey Son.Nm
12900a5db46SStacey Sondriver first appeared in
13000a5db46SStacey Son.Fx 8.0
13100a5db46SStacey Sonto support
13200a5db46SStacey Son.Xr lockstat 1 .
13300a5db46SStacey Son.Sh BUGS
13400a5db46SStacey SonBecause files can be dynamically linked into the kernel at any time the symbol
13500a5db46SStacey Soninformation can vary.  When you open the
13600a5db46SStacey Son.Pa /dev/ksyms
13700a5db46SStacey Sonfile, 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.
13800a5db46SStacey Son.Pp
13900a5db46SStacey SonA process is only allowed to open the
14000a5db46SStacey Son.Pa /dev/ksyms
14100a5db46SStacey Sonfile once at a time.  The process must close the
14200a5db46SStacey Son.Pa /dev/ksyms
14300a5db46SStacey Sonbefore it is allowed to open it again.
14400a5db46SStacey Son.Pp
14500a5db46SStacey SonThe
14600a5db46SStacey Son.Nm
14700a5db46SStacey Sondriver uses the calling process' memory address space to store the snapshot.
14800a5db46SStacey Son.Xr ioctl 2
14900a5db46SStacey Soncan be used to get the memory address where the symbol table is stored to
15000a5db46SStacey Sonsave kernel memory.
15100a5db46SStacey Son.Xr mmap 2
15200a5db46SStacey Sonmay also be used but it will map it to another address.
15300a5db46SStacey Son.Sh AUTHORS
15400a5db46SStacey SonThe
15500a5db46SStacey Son.Nm
15600a5db46SStacey Sondriver was written by
15700a5db46SStacey Son.An Stacey Son
15800a5db46SStacey Son.Aq sson@freebsd.org .
159