]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/SYSINIT.9
Remove $FreeBSD$: two-line nroff pattern
[FreeBSD/FreeBSD.git] / share / man / man9 / SYSINIT.9
1 .\" Copyright (c) 2003 Hiten M. Pandya
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 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .Dd December 1, 2010
26 .Dt SYSINIT 9
27 .Os
28 .Sh NAME
29 .Nm SYSINIT ,
30 .Nm SYSUNINIT
31 .Nd a framework for dynamic kernel initialization
32 .Sh SYNOPSIS
33 .In sys/param.h
34 .In sys/kernel.h
35 .Fn SYSINIT "uniquifier" "enum sysinit_sub_id subsystem" "enum sysinit_elem_order order" "sysinit_cfunc_t func" "const void *ident"
36 .Fn SYSUNINIT "uniquifier" "enum sysinit_sub_id subsystem" "enum sysinit_elem_order order" "sysinit_cfunc_t func" "const void *ident"
37 .Sh DESCRIPTION
38 .Nm
39 is a mechanism for scheduling the execution of initialization and teardown
40 routines.
41 This is similar to init and fini routines with the addition of explicit
42 ordering metadata.
43 It allows runtime ordering of subsystem initialization in the kernel as well
44 as kernel modules (KLDs).
45 .Pp
46 The
47 .Fn SYSINIT
48 macro creates a
49 .Vt struct sysinit
50 and stores it in a startup linker set.
51 The
52 .Vt struct sysinit
53 type as well as the subsystem identifier constants
54 .Pq Dv SI_SUB_*
55 and initialization ordering constants
56 .Pq Dv SI_ORDER_*
57 are defined in
58 .In sys/kernel.h :
59 .Bd -literal
60 struct sysinit {
61         enum sysinit_sub_id subsystem;  /* subsystem identifier*/
62         enum sysinit_elem_order order;  /* init order within subsystem*/
63         sysinit_cfunc_t func;           /* function             */
64         const void      *udata;         /* multiplexer/argument */
65 };
66 .Ed
67 .Pp
68 The
69 .Fn SYSINIT
70 macro takes a
71 .Fa uniquifier
72 argument to identify the particular function dispatch data,
73 the
74 .Fa subsystem
75 type of startup interface, the subsystem element
76 .Fa order
77 of initialization within the subsystem, the
78 .Fa func
79 function to call,
80 and the data specified in
81 .Fa ident
82 argument to pass the function.
83 .Pp
84 The
85 .Fn SYSUNINIT
86 macro behaves similarly to the
87 .Fn SYSINIT
88 macro except that it adds the data to a shutdown linker set.
89 .Pp
90 The startup linker set for the kernel is scanned during boot to build a
91 sorted list of initialization routines.
92 The initialization routines are then executed in the sorted order.
93 The
94 .Fa subsystem
95 is used as the primary key and is sorted in ascending order.
96 The
97 .Fa order
98 is used as the secondary key and is sorted in ascending order.
99 The relative order of two routines that have the same
100 .Fa subsystem
101 and
102 .Fa order
103 is undefined.
104 .Pp
105 The startup linker sets for modules that are loaded together with the kernel
106 by the boot loader are scanned during the
107 .Dv SI_SUB_KLD
108 subsystem initialization.
109 These modules' initialization routines are sorted and merged into the kernel's
110 list of startup routines and are executed during boot along with the kernel's
111 initialization routines.
112 Note that this has the effect that any initialization routines in a kernel
113 module that are scheduled earlier than
114 .Dv SI_SUB_KLD
115 are not executed until after
116 .Dv SI_SUB_KLD
117 during boot.
118 .Pp
119 The startup linker set for a kernel module loaded at runtime via
120 .Xr kldload 2
121 is scanned, sorted, and executed when the module is loaded.
122 .Pp
123 The shutdown linker set for a kernel module is scanned, sorted, and executed
124 when a kernel module is unloaded.
125 The teardown routines are sorted in the reverse order of the initialization
126 routines.
127 The teardown routines of the kernel and any loaded modules are
128 .Sy not
129 executed during shutdown.
130 .Sh EXAMPLES
131 This example shows the SYSINIT which displays the copyright notice during boot:
132 .Bd -literal -offset indent
133 static void
134 print_caddr_t(void *data)
135 {
136         printf("%s", (char *)data);
137 }
138 SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t,
139     copyright);
140 .Ed
141 .Sh SEE ALSO
142 .Xr kld 4 ,
143 .Xr DECLARE_MODULE 9 ,
144 .Xr DEV_MODULE 9 ,
145 .Xr DRIVER_MODULE 9 ,
146 .Xr MTX_SYSINIT 9 ,
147 .Xr SYSCALL_MODULE 9
148 .Sh HISTORY
149 The
150 .Nm
151 framework first appeared in
152 .Fx 2.2 .
153 .Sh AUTHORS
154 .An -nosplit
155 The
156 .Nm
157 framework was written by
158 .An Terrence Lambert Aq Mt terry@FreeBSD.org .
159 .Pp
160 This manual page was written by
161 .An Hiten Pandya Aq Mt hmp@FreeBSD.org .