xref: /freebsd/share/man/man9/module.9 (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 2000 Alexander Langer
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" $FreeBSD$
30.\"
31.Dd November 11, 2021
32.Dt MODULE 9
33.Os
34.Sh NAME
35.Nm module
36.Nd structure describing a kernel module
37.Sh DESCRIPTION
38Each module in the kernel is described by a
39.Vt module_t
40structure.
41The structure contains the name of the device, a unique ID number,
42a pointer to an event handler function and to an argument,
43which is given to the event handler,
44as well as some kernel internal data.
45If the event handler function is
46.Dv NULL ,
47the module will use a no-operation function handler instead.
48.Pp
49The
50.Xr DECLARE_MODULE 9
51macro
52registers the module with the system.
53.Pp
54When the module is loaded, the event handler function is called with
55the
56.Fa what
57argument set to
58.Dv MOD_LOAD .
59.Pp
60On unload it is first called with
61.Fa what
62set to
63.Dv MOD_QUIESCE .
64If the unload was not forced, a non-zero return will prevent the
65unload from happening.
66.Pp
67If the unload continues
68.Fa what
69is set to
70.Dv MOD_UNLOAD .
71If the module returns non-zero to this, the unload will not happen.
72.Pp
73The difference between
74.Dv MOD_QUIESCE
75and
76.Dv MOD_UNLOAD
77is that the module should fail
78.Dv MOD_QUIESCE
79if it is currently in use, whereas
80.Dv MOD_UNLOAD
81should only fail if it is impossible to unload the module, for instance
82because there are memory references to the module which cannot be revoked.
83.Pp
84When the system is shutting down,
85.Fa what
86contains the value of
87.Dv MOD_SHUTDOWN .
88.Pp
89The module should return
90.Er EOPNOTSUPP
91for unsupported and unrecognized values of
92.Fa what .
93.Sh EXAMPLES
94.Bd -literal
95#include <sys/param.h>
96#include <sys/kernel.h>
97#include <sys/module.h>
98
99static int foo_handler(module_t mod, int /*modeventtype_t*/ what,
100                       void *arg);
101
102static moduledata_t mod_data= {
103        "foo",
104        foo_handler,
105	NULL
106};
107
108MODULE_VERSION(foo, 1);
109MODULE_DEPEND(foo, bar, 1, 3, 4);
110
111DECLARE_MODULE(foo, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);
112.Ed
113.Sh SEE ALSO
114.Xr DECLARE_MODULE 9 ,
115.Xr DEV_MODULE 9 ,
116.Xr DRIVER_MODULE 9 ,
117.Xr MODULE_DEPEND 9 ,
118.Xr MODULE_PNP_INFO 9 ,
119.Xr MODULE_VERSION 9 ,
120.Xr SYSCALL_MODULE 9
121.Pp
122.Pa /usr/share/examples/kld
123.Sh AUTHORS
124This manual page was written by
125.An Alexander Langer Aq Mt alex@FreeBSD.org .
126