1.\" Copyright (c) 1993 Christopher G. Demetriou 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. The name of the author may not be used to endorse or promote products 13.\" derived from this software without specific prior written permission 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd November 08, 1998 29.Dt KLD 4 30.\".Os FreeBSD 3.0 31.Sh NAME 32.Nm kld 33.Nd dynamic kernel linker facility 34.Sh DESCRIPTION 35The LKM (Loadable Kernel Modules) facility has been deprecated in FreeBSD 363.0 and above in favor of the 37.Nm 38interface. This interface, like its 39predecessor, allows the system administrator to dynamically add and remove 40functionality from a running system. This ability also helps software 41developers to develop new parts of the kernel without constantly rebooting 42to test their changes. 43.Pp 44Various types of modules can be loaded into the system. 45There are several defined module types, listed below, which can 46be added to the system in a predefined way. In addition, there 47is a generic type, for which the module itself handles loading and 48unloading. 49.Pp 50The 51.Tn FreeBSD 52system makes extensive use of loadable kernel modules, and provides loadable 53versions of most filesystems, the 54.Tn NFS 55client and server, all the screen-savers, and the 56.Tn iBCS2 57and 58.Tn Linux 59emulators. 60.Nm 61modules are placed by default in the 62.Pa /modules 63directory. 64.Pp 65The 66.Nm 67interface is used through the 68.Xr kldload 8 , 69.Xr kldunload 8 70and 71.Xr kldstat 8 72programs. 73.Pp 74The 75.Xr kldload 8 76program can load either 77.Xr a.out 5 78or ELF formatted loadable modules. 79The 80.Xr kldunload 8 81program unloads any given loaded module, if no other module is dependent 82upon the given module. 83The 84.Xr kldstat 8 85program is used to check the status of the modules currently loaded into the 86system. 87.Sh "MODULE TYPES" 88.Bl -ohang 89.It Em "Device Driver modules" 90New block and character device 91drivers may be loaded into the system with 92.Nm KLD . 93The major problem with loading 94a device driver is that the driver's 95device nodes must be exist for the 96devices to be accessed. They are usually 97created by using 98.Xr MAKEDEV 8 99or 100.Xr mknod 8 101(if the device is not supported by the 102.Xr MAKEDEV 8 103script) or, by writing a 104shell script to run 105.Xr kldload 8 106which should run the appropriate program to create the devices when the 107driver has been successfully loaded. 108.El 109.Sh FILES 110.Bl -tag -width /usr/include/sys/module.h -compact 111.It Pa /modules 112directory containing module binaries shipped with the system 113.It Pa /usr/include/sys/module.h 114file containing definitions required to compile a 115.Nm 116module 117.It Pa /usr/share/examples/kld 118example source code implementing a sample kld module 119.Sh SEE ALSO 120.Xr kldfind 2 , 121.Xr kldfirstmod 2 , 122.Xr kldload 2 , 123.Xr kldnext 2 , 124.Xr kldstat 2 , 125.Xr kldunload 2 , 126.Xr kldload 8 , 127.Xr kldstat 8 , 128.Xr kldunload 8 129.Sh BUGS 130If a module B, is dependent on another module A, but is not compiled with 131module A as a dependency, then 132.Xr kldload 8 133fails to load module B, even if module A is already present in the system. 134.Pp 135If multiple modules are dependent on module A, and are compiled with module 136A as a dependency, then 137.Xr kldload 8 138loads an instance of module A when any of the modules are loaded. 139.Pp 140If a custom entry point is used for a module, and the module is compiled as 141an 142.Sq ELF 143binary, then 144.Xr kldload 8 145fails to execute the entry point. 146.Pp 147.Xr kldload 8 148returns the cryptic message 149.Sq ENOEXEC Po Exec format error Pc 150for any error encountered while loading a module. 151.Pp 152When system internal interfaces change, old modules often cannot 153detect this, and such modules when loaded will often cause crashes or 154mysterious failures. 155.Sh AUTHORS 156The 157.Nm 158facility was originally implemented by 159.An Doug Rabson Aq dfr@FreeBSD.org . 160.Sh HISTORY 161The 162.Nm 163facility appeared in 164.Fx 3.0 165and was designed as a replacement for the 166.Xr lkm 4 167facility, which was similar in functionality to the loadable kernel modules 168facility provided by 169.Tn SunOS 1704.1.3. 171