xref: /freebsd/share/man/man9/DECLARE_MODULE.9 (revision 315ee00f)
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.Dd February 13, 2018
30.Dt DECLARE_MODULE 9
31.Os
32.Sh NAME
33.Nm DECLARE_MODULE
34.Nd kernel module declaration macro
35.Sh SYNOPSIS
36.In sys/param.h
37.In sys/kernel.h
38.In sys/module.h
39.Fn DECLARE_MODULE "name" "moduledata_t data" "sub" "order"
40.Fn DECLARE_MODULE_TIED "name" "moduledata_t data" "sub" "order"
41.Sh DESCRIPTION
42The
43.Fn DECLARE_MODULE
44macro declares a generic kernel module.
45It is used to register the module with the system, using the
46.Fn SYSINIT
47macro.
48.Fn DECLARE_MODULE
49is usually used within other macros, such as
50.Xr DRIVER_MODULE 9 ,
51.Xr DEV_MODULE 9
52and
53.Xr SYSCALL_MODULE 9 .
54Of course, it can also be called directly, for example in
55order to implement dynamic sysctls.
56.Pp
57A module declared with
58.Fn DECLARE_MODULE_TIED
59will load only if the running kernel version
60(as specified by
61.Dv __FreeBSD_version )
62is identical to that on which it was built.
63This declaration should be used by modules which depend on interfaces beyond
64the stable kernel KBI (such as ABI emulators or hypervisors that rely on
65internal kernel structures).
66.Fn DECLARE_MODULE
67will behave like
68.Fn DECLARE_MODULE_TIED
69when compiled with modules built with the kernel.
70This allows locks and other synchronization primitives
71to be inlined safely.
72.Pp
73The arguments are:
74.Bl -tag -width indent
75.It Fa name
76The module name, which will be used in the
77.Fn SYSINIT
78call to identify the module.
79.It Fa data
80A
81.Vt moduledata_t
82structure, which contains two main items, the official name of the
83module name, which will be used in the
84.Vt module_t
85structure and a pointer to the event handler function of type
86.Vt modeventhand_t .
87.It Fa sub
88An argument directed to the
89.Fn SYSINIT
90macro.
91Valid values for this are contained in the
92.Vt sysinit_sub_id
93enumeration
94(see
95.In sys/kernel.h )
96and specify the type of system startup interfaces.
97The
98.Xr DRIVER_MODULE 9
99macro uses a value of
100.Dv SI_SUB_DRIVERS
101here for example, since these modules contain a driver for a device.
102For kernel modules that are loaded at runtime, a value of
103.Dv SI_SUB_EXEC
104is common.
105.It Fa order
106An argument for
107.Fn SYSINIT .
108It represents the KLDs order of initialization within the subsystem.
109Valid values are defined in the
110.Vt sysinit_elem_order
111enumeration
112.Pq In sys/kernel.h .
113.El
114.Sh SEE ALSO
115.Xr DEV_MODULE 9 ,
116.Xr DRIVER_MODULE 9 ,
117.Xr module 9 ,
118.Xr SYSCALL_MODULE 9
119.Pp
120.Pa /usr/include/sys/kernel.h ,
121.Pa /usr/share/examples/kld
122.Sh AUTHORS
123.An -nosplit
124This manual page was written by
125.An Alexander Langer Aq Mt alex@FreeBSD.org ,
126inspired by the KLD Facility Programming Tutorial by
127.An Andrew Reiter Aq Mt arr@watson.org .
128