]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/man/man9/module.9
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / man / man9 / module.9
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 July 19, 2007
32 .Dt MODULE 9
33 .Os
34 .Sh NAME
35 .Nm module
36 .Nd structure describing a kernel module
37 .Sh DESCRIPTION
38 Each module in the kernel is described by a
39 .Vt module_t
40 structure.
41 The structure contains the name of the device, a unique ID number,
42 a pointer to an event handler function and to an argument,
43 which is given to the event handler,
44 as well as some kernel internal data.
45 .Pp
46 The
47 .Xr DECLARE_MODULE 9
48 macro
49 registers the module with the system.
50 .Pp
51 When the module is loaded, the event handler function is called with
52 the
53 .Fa what
54 argument set to
55 .Dv MOD_LOAD .
56 .Pp
57 On unload it is first called with
58 .Fa what
59 set to
60 .Dv MOD_QUIESCE .
61 If the unload was not forced, a non-zero return will prevent the
62 unload from happening.
63 .Pp
64 If the unload continues
65 .Fa what
66 is set to
67 .Dv MOD_UNLOAD .
68 If the module returns non-zero to this, the unload will not happen.
69 .Pp
70 The difference between
71 .Dv MOD_QUIESCE
72 and
73 .Dv MOD_UNLOAD
74 is that the module should fail
75 .Dv MOD_QUIESCE
76 if it is currently in use, whereas
77 .Dv MOD_UNLOAD
78 should only fail if it is impossible to unload the module, for instance
79 because there are memory references to the module which cannot be revoked.
80 .Pp
81 When the system is shutting down,
82 .Fa what
83 contains the value of
84 .Dv MOD_SHUTDOWN .
85 .Pp
86 The module should return
87 .Er EOPNOTSUPP
88 for unsupported and unrecognized values of
89 .Fa what .
90 .Sh EXAMPLES
91 .Bd -literal
92 #include <sys/param.h>
93 #include <sys/kernel.h>
94 #include <sys/module.h>
95
96 static int foo_handler(module_t mod, int /*modeventtype_t*/ what,
97                        void *arg);
98
99 static moduledata_t mod_data= {
100         "foo",
101         foo_handler,
102         NULL
103 };
104
105 MODULE_VERSION(foo, 1);
106 MODULE_DEPEND(foo, bar, 1, 3, 4);
107
108 DECLARE_MODULE(foo, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);
109 .Ed
110 .Sh SEE ALSO
111 .Xr DECLARE_MODULE 9 ,
112 .Xr DEV_MODULE 9 ,
113 .Xr DRIVER_MODULE 9 ,
114 .Xr MODULE_DEPEND 9 ,
115 .Xr MODULE_VERSION 9 ,
116 .Xr SYSCALL_MODULE 9
117 .Pp
118 .Pa /usr/share/examples/kld
119 .Sh AUTHORS
120 This manual page was written by
121 .An Alexander Langer Aq alex@FreeBSD.org .