summaryrefslogtreecommitdiff
path: root/static/freebsd/man9/module.9 3.html
blob: ad8230b9bb3c9d39898bdabdba04c716d3ca292d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<table class="head">
  <tr>
    <td class="head-ltitle">MODULE(9)</td>
    <td class="head-vol">Kernel Developer's Manual</td>
    <td class="head-rtitle">MODULE(9)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">module</code> &#x2014; <span class="Nd">structure
    describing a kernel module</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">Each module in the kernel is described by a
    <var class="Vt">module_t</var> structure. The structure contains the name of
    the device, a unique ID number, a pointer to an event handler function and
    to an argument, which is given to the event handler, as well as some kernel
    internal data. If the event handler function is
    <code class="Dv">NULL</code>, the module will use a no-operation function
    handler instead.</p>
<p class="Pp">The <a class="Xr">DECLARE_MODULE(9)</a> macro registers the module
    with the system.</p>
<p class="Pp">When the module is loaded, the event handler function is called
    with the <var class="Fa">what</var> argument set to
    <code class="Dv">MOD_LOAD</code>.</p>
<p class="Pp">On unload it is first called with <var class="Fa">what</var> set
    to <code class="Dv">MOD_QUIESCE</code>. If the unload was not forced, a
    non-zero return will prevent the unload from happening.</p>
<p class="Pp">If the unload continues <var class="Fa">what</var> is set to
    <code class="Dv">MOD_UNLOAD</code>. If the module returns non-zero to this,
    the unload will not happen.</p>
<p class="Pp">The difference between <code class="Dv">MOD_QUIESCE</code> and
    <code class="Dv">MOD_UNLOAD</code> is that the module should fail
    <code class="Dv">MOD_QUIESCE</code> if it is currently in use, whereas
    <code class="Dv">MOD_UNLOAD</code> should only fail if it is impossible to
    unload the module, for instance because there are memory references to the
    module which cannot be revoked.</p>
<p class="Pp">When the system is shutting down, <var class="Fa">what</var>
    contains the value of <code class="Dv">MOD_SHUTDOWN</code>.</p>
<p class="Pp">The module should return <code class="Er">EOPNOTSUPP</code> for
    unsupported and unrecognized values of <var class="Fa">what</var>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<div class="Bd Li">
<pre>#include &lt;sys/param.h&gt;
#include &lt;sys/kernel.h&gt;
#include &lt;sys/module.h&gt;

static int foo_handler(module_t mod, int /*modeventtype_t*/ what,
                       void *arg);

static moduledata_t mod_data= {
        &quot;foo&quot;,
        foo_handler,
	NULL
};

MODULE_VERSION(foo, 1);
MODULE_DEPEND(foo, bar, 1, 3, 4);

DECLARE_MODULE(foo, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);</pre>
</div>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">DECLARE_MODULE(9)</a>,
    <a class="Xr">DEV_MODULE(9)</a>, <a class="Xr">DRIVER_MODULE(9)</a>,
    <a class="Xr">MODULE_DEPEND(9)</a>, <a class="Xr">MODULE_PNP_INFO(9)</a>,
    <a class="Xr">MODULE_VERSION(9)</a>, <a class="Xr">SYSCALL_MODULE(9)</a></p>
<p class="Pp"><span class="Pa">/usr/share/examples/kld</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">This manual page was written by <span class="An">Alexander
    Langer</span>
    &lt;<a class="Mt" href="mailto:alex@FreeBSD.org">alex@FreeBSD.org</a>&gt;.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">November 11, 2021</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>