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. 39This interface, like its 40predecessor, allows the system administrator to dynamically add and remove 41functionality from a running system. This ability also helps software 42developers to develop new parts of the kernel without constantly rebooting 43to test their changes. 44.Pp 45Various types of modules can be loaded into the system. 46There are several defined module types, listed below, which can 47be added to the system in a predefined way. In addition, there 48is a generic type, for which the module itself handles loading and 49unloading. 50.Pp 51The 52.Tn FreeBSD 53system makes extensive use of loadable kernel modules, and provides loadable 54versions of most filesystems, the 55.Tn NFS 56client and server, all the screen-savers, and the 57.Tn iBCS2 58and 59.Tn Linux 60emulators. 61.Nm 62modules are placed by default in the 63.Pa /modules 64directory. 65.Pp 66The 67.Nm 68interface is used through the 69.Xr kldload 8 , 70.Xr kldunload 8 71and 72.Xr kldstat 8 73programs. 74.Pp 75The 76.Xr kldload 8 77program can load either 78.Xr a.out 5 79or ELF formatted loadable modules. 80The 81.Xr kldunload 8 82program unloads any given loaded module, if no other module is dependent 83upon the given module. 84The 85.Xr kldstat 8 86program is used to check the status of the modules currently loaded into the 87system. 88.Sh "MODULE TYPES" 89.Bl -ohang 90.It Em "Device Driver modules" 91New block and character device 92drivers may be loaded into the system with 93.Nm KLD . 94The major problem with loading 95a device driver is that the driver's 96device nodes must be exist for the 97devices to be accessed. They are usually 98created by using 99.Xr MAKEDEV 8 100or 101.Xr mknod 8 102(if the device is not supported by the 103.Xr MAKEDEV 8 104script) or, by writing a 105shell script to run 106.Xr kldload 8 107which should run the appropriate program to create the devices when the 108driver has been successfully loaded. 109.El 110.Sh FILES 111.Bl -tag -width /usr/include/sys/module.h -compact 112.It Pa /modules 113directory containing module binaries shipped with the system 114.It Pa /usr/include/sys/module.h 115file containing definitions required to compile a 116.Nm 117module 118.It Pa /usr/share/examples/kld 119example source code implementing a sample kld module 120.Sh SEE ALSO 121.Xr kldfind 2 , 122.Xr kldfirstmod 2 , 123.Xr kldload 2 , 124.Xr kldnext 2 , 125.Xr kldstat 2 , 126.Xr kldunload 2 , 127.Xr kldload 8 , 128.Xr kldstat 8 , 129.Xr kldunload 8 130.Sh BUGS 131If a module B, is dependent on another module A, but is not compiled with 132module A as a dependency, then 133.Xr kldload 8 134fails to load module B, even if module A is already present in the system. 135.Pp 136If multiple modules are dependent on module A, and are compiled with module 137A as a dependency, then 138.Xr kldload 8 139loads an instance of module A when any of the modules are loaded. 140.Pp 141If a custom entry point is used for a module, and the module is compiled as 142an 143.Sq ELF 144binary, then 145.Xr kldload 8 146fails to execute the entry point. 147.Pp 148.Xr kldload 8 149returns the cryptic message 150.Sq ENOEXEC Po Exec format error Pc 151for any error encountered while loading a module. 152.Pp 153When system internal interfaces change, old modules often cannot 154detect this, and such modules when loaded will often cause crashes or 155mysterious failures. 156.Sh AUTHORS 157The 158.Nm 159facility was originally implemented by 160.An Doug Rabson Aq dfr@FreeBSD.org . 161.Sh HISTORY 162The 163.Nm 164facility appeared in 165.Fx 3.0 166and was designed as a replacement for the 167.Xr lkm 4 168facility, which was similar in functionality to the loadable kernel modules 169facility provided by 170.Tn SunOS 1714.1.3. 172