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