xref: /freebsd/share/man/man4/kld.4 (revision 4c9a0adad18263ec8725d9bfc5f560c6ad1da8bd)
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.Dd January 13, 2014
27.Dt KLD 4
28.Os
29.Sh NAME
30.Nm kld
31.Nd dynamic kernel linker facility
32.Sh DESCRIPTION
33The LKM (Loadable Kernel Modules) facility has been deprecated in
34.Fx 3.0
35and above in favor of the
36.Nm
37interface.
38This interface, like its
39predecessor, allows the system administrator to dynamically add and remove
40functionality from a running system.
41This 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.
48In addition, there
49is a generic type, for which the module itself handles loading and
50unloading.
51.Pp
52The
53.Fx
54system makes extensive use of loadable kernel modules, and provides loadable
55versions of most file systems, the
56.Tn NFS
57client and server, all the screen-savers, and the
58.Tn Linux
59emulator.
60.Nm
61modules are placed by default in the
62.Pa /boot/kernel
63directory along with their matching kernel.
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.Pp
88Kernel modules may only be loaded or unloaded if the system security level
89.Va kern.securelevel
90is less than one.
91.Sh "MODULE TYPES"
92.Bl -ohang
93.It Em "Device Driver modules"
94New block and character device
95drivers may be loaded into the system with
96.Nm .
97Device nodes for the loaded drivers are automatically created when a
98module is loaded and destroyed when it is unloaded by
99.Xr devfs 5 .
100You can specify userland programs that will run when new devices
101become available as a result of loading modules, or existing devices
102go away when modules are unloaded, by configuring
103.Xr devd 8 .
104.El
105.Sh FILES
106.Bl -tag -width /usr/include/sys/module.h -compact
107.It Pa /boot/kernel
108directory containing module binaries built for the kernel also
109residing in the directory.
110.It Pa /usr/include/sys/module.h
111file containing definitions required to compile a
112.Nm
113module
114.It Pa /usr/share/examples/kld
115example source code implementing a sample kld module
116.El
117.Sh SEE ALSO
118.Xr kldfind 2 ,
119.Xr kldfirstmod 2 ,
120.Xr kldload 2 ,
121.Xr kldnext 2 ,
122.Xr kldstat 2 ,
123.Xr kldunload 2 ,
124.Xr devfs 5 ,
125.Xr devd 8 ,
126.Xr kldload 8 ,
127.Xr kldstat 8 ,
128.Xr kldunload 8 ,
129.Xr sysctl 8
130.Sh HISTORY
131The
132.Nm
133facility appeared in
134.Fx 3.0
135and was designed as a replacement for the
136.Nm lkm
137facility, which was similar in functionality to the loadable kernel modules
138facility provided by
139.Tn SunOS
1404.1.3.
141.Sh AUTHORS
142The
143.Nm
144facility was originally implemented by
145.An Doug Rabson Aq Mt dfr@FreeBSD.org .
146.Sh BUGS
147If a module B, is dependent on another module A, but is not compiled with
148module A as a dependency, then
149.Xr kldload 8
150fails to load module B, even if module A is already present in the system.
151.Pp
152If multiple modules are dependent on module A, and are compiled with module
153A as a dependency, then
154.Xr kldload 8
155loads an instance of module A when any of the modules are loaded.
156.Pp
157If a custom entry point is used for a module, and the module is compiled as
158an
159.Sq ELF
160binary, then
161.Xr kldload 8
162fails to execute the entry point.
163.Pp
164.Xr kldload 8
165points the user to read
166.Xr dmesg 8
167for any error encountered while loading a module.
168.Pp
169When system internal interfaces change, old modules often cannot
170detect this, and such modules when loaded will often cause crashes or
171mysterious failures.
172