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 42*25972509SEdward Tomasz Napieralasymbol table. 43*25972509SEdward Tomasz NapieralaThe in-kernel symbol manager is designed to be able to handle 4400a5db46SStacey Sonmany types of symbols tables, however, only 4500a5db46SStacey Son.Xr elf 5 46*25972509SEdward Tomasz Napieralasymbol tables are supported by this device. 47*25972509SEdward Tomasz NapieralaThe ELF format image contains two 4800a5db46SStacey Sonsections: a symbol table and a corresponding string table. 4900a5db46SStacey Son.Bl -tag -width indent -offset indent 5000a5db46SStacey Son.It Dv Symbol Table 5100a5db46SStacey SonThe SYMTAB section contains the symbol table entries present in the current 52*25972509SEdward Tomasz Napieralarunning kernel, including the symbol table entries of any loaded modules. 53*25972509SEdward Tomasz NapieralaThe symbols are ordered by the kernel module load time starting with kernel file 5400a5db46SStacey Sonsymbols first, followed by the first loaded module's symbols and so on. 5500a5db46SStacey Son.It Dv String Table 5600a5db46SStacey SonThe STRTAB section contains the symbol name strings from the kernel and any 5700a5db46SStacey Sonloaded modules that the symbol table entries reference. 5800a5db46SStacey Son.El 5900a5db46SStacey Son.Pp 60b06cfd40SJoel DahlElf formatted symbol table data read from the 6100a5db46SStacey Son.Pa /dev/ksyms 6200a5db46SStacey Sonfile represents the state of the kernel at the time when the device is opened. 6300a5db46SStacey SonSince 6400a5db46SStacey Son.Pa /dev/ksyms 6500a5db46SStacey Sonhas no text or data, most of the fields are initialized to NULL. 6600a5db46SStacey SonThe 6700a5db46SStacey Son.Nm 6800a5db46SStacey Sondriver does not block the loading or unloading of modules into the kernel 6900a5db46SStacey Sonwhile the 7000a5db46SStacey Son.Pa /dev/ksyms 7100a5db46SStacey Sonfile is open but may contain stale data. 7200a5db46SStacey Son.Sh IOCTLS 7300a5db46SStacey SonThe 7400a5db46SStacey Son.Xr ioctl 2 7500a5db46SStacey Soncommand codes below are defined in 7600a5db46SStacey Son.Aq Pa sys/ksyms.h . 7700a5db46SStacey Son.Pp 7800a5db46SStacey SonThe (third) argument to the 7900a5db46SStacey Son.Xr ioctl 2 8000a5db46SStacey Sonshould be a pointer to the type indicated. 8100a5db46SStacey Son.Bl -tag -width indent -offset indent 8200a5db46SStacey Son.It Dv KIOCGSIZE (size_t) 8300a5db46SStacey SonReturns the total size of the current symbol table. 8400a5db46SStacey SonThis can be used when allocating a buffer to make a copy of 8500a5db46SStacey Sonthe kernel symbol table. 8600a5db46SStacey Son.It Dv KIOCGADDR (void *) 8700a5db46SStacey SonReturns the address of the kernel symbol table mapped in 8800a5db46SStacey Sonthe process memory. 8900a5db46SStacey Son.El 9000a5db46SStacey Son.Sh FILES 9100a5db46SStacey Son.Bl -tag -width /dev/ksymsX 9200a5db46SStacey Son.It Pa /dev/ksyms 9300a5db46SStacey Son.El 9400a5db46SStacey Son.Sh ERRORS 9500a5db46SStacey SonAn 9600a5db46SStacey Son.Xr open 2 9700a5db46SStacey Sonof 9800a5db46SStacey Son.Pa /dev/ksyms 9900a5db46SStacey Sonwill fail if: 10000a5db46SStacey Son.Bl -tag -width Er 10100a5db46SStacey Son.It Bq Er EBUSY 102*25972509SEdward Tomasz NapieralaThe device is already open. 103*25972509SEdward Tomasz NapieralaA process must close 10400a5db46SStacey Son.Pa /dev/ksyms 10500a5db46SStacey Sonbefore it can be opened again. 10600a5db46SStacey Son.It Bq Er ENOMEM 10700a5db46SStacey SonThere is a resource shortage in the kernel. 10800a5db46SStacey Son.It Bq Er ENXIO 10900a5db46SStacey SonThe driver was unsuccessful in creating a snapshot of the kernel symbol 110*25972509SEdward Tomasz Napieralatable. 111*25972509SEdward Tomasz NapieralaThis 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 . 1330afc94c1SUlrich Spörlein.Sh AUTHORS 1340afc94c1SUlrich SpörleinThe 1350afc94c1SUlrich Spörlein.Nm 1360afc94c1SUlrich Spörleindriver was written by 1376c899950SBaptiste Daroussin.An Stacey Son Aq Mt sson@FreeBSD.org . 13800a5db46SStacey Son.Sh BUGS 13900a5db46SStacey SonBecause files can be dynamically linked into the kernel at any time the symbol 140*25972509SEdward Tomasz Napieralainformation can vary. 141*25972509SEdward Tomasz NapieralaWhen you open the 14200a5db46SStacey Son.Pa /dev/ksyms 143*25972509SEdward Tomasz Napieralafile, you have access to an ELF image which represents a snapshot of the state 144*25972509SEdward Tomasz Napieralaof the kernel symbol information at that instant in time. 145*25972509SEdward Tomasz NapieralaKeeping the device open does not block the loading or unloading of kernel 146*25972509SEdward Tomasz Napieralamodules. 147*25972509SEdward Tomasz NapieralaTo get a new snapshot you must close and re-open the device. 14800a5db46SStacey Son.Pp 14900a5db46SStacey SonA process is only allowed to open the 15000a5db46SStacey Son.Pa /dev/ksyms 151*25972509SEdward Tomasz Napieralafile once at a time. 152*25972509SEdward Tomasz NapieralaThe process must close the 15300a5db46SStacey Son.Pa /dev/ksyms 15400a5db46SStacey Sonbefore it is allowed to open it again. 15500a5db46SStacey Son.Pp 15600a5db46SStacey SonThe 15700a5db46SStacey Son.Nm 15800a5db46SStacey Sondriver uses the calling process' memory address space to store the snapshot. 15900a5db46SStacey Son.Xr ioctl 2 16000a5db46SStacey Soncan be used to get the memory address where the symbol table is stored to 16100a5db46SStacey Sonsave kernel memory. 16200a5db46SStacey Son.Xr mmap 2 16300a5db46SStacey Sonmay also be used but it will map it to another address. 164