Changeset View
Changeset View
Standalone View
Standalone View
share/man/man9/SYSINIT.9
| Show All 18 Lines | |||||
| .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
| .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
| .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
| .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| .\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
| .\" | .\" | ||||
| .\" $FreeBSD$ | .\" $FreeBSD$ | ||||
| .\" | .\" | ||||
| .Dd December 1, 2010 | .Dd June 7, 2023 | ||||
| .Dt SYSINIT 9 | .Dt SYSINIT 9 | ||||
| .Os | .Os | ||||
| .Sh NAME | .Sh NAME | ||||
| .Nm SYSINIT , | .Nm SYSINIT , | ||||
| .Nm SYSUNINIT | .Nm SYSUNINIT | ||||
| .Nd a framework for dynamic kernel initialization | .Nd a framework for dynamic kernel initialization | ||||
| .Sh SYNOPSIS | .Sh SYNOPSIS | ||||
| .In sys/param.h | .In sys/param.h | ||||
| .In sys/kernel.h | .In sys/kernel.h | ||||
| .Fn SYSINIT "uniquifier" "enum sysinit_sub_id subsystem" "enum sysinit_elem_order order" "sysinit_cfunc_t func" "const void *ident" | .Fn SYSINIT "uniquifier" "enum sysinit_sub_id subsystem" "enum sysinit_elem_order order" "func" "args..." | ||||
| .Fn SYSUNINIT "uniquifier" "enum sysinit_sub_id subsystem" "enum sysinit_elem_order order" "sysinit_cfunc_t func" "const void *ident" | .Fn SYSUNINIT "uniquifier" "enum sysinit_sub_id subsystem" "enum sysinit_elem_order order" "func" "args..." | ||||
| .Sh DESCRIPTION | .Sh DESCRIPTION | ||||
| .Nm | .Nm | ||||
| is a mechanism for scheduling the execution of initialization and teardown | is a mechanism for scheduling the execution of initialization and teardown | ||||
| routines. | routines. | ||||
| This is similar to init and fini routines with the addition of explicit | This is similar to init and fini routines with the addition of explicit | ||||
| ordering metadata. | ordering metadata. | ||||
| It allows runtime ordering of subsystem initialization in the kernel as well | It allows runtime ordering of subsystem initialization in the kernel as well | ||||
| as kernel modules (KLDs). | as kernel modules (KLDs). | ||||
| .Pp | .Pp | ||||
| The | The | ||||
| .Fn SYSINIT | .Fn SYSINIT | ||||
| and | |||||
| .Fn SYSUNINIT | |||||
| macros may not be used inside function blocks. | |||||
| .Pp | |||||
| The | |||||
| .Fn SYSINIT | |||||
| macro creates a | macro creates a | ||||
| .Vt struct sysinit | .Vt struct sysinit | ||||
| and stores it in a startup linker set. | and stores it in a startup linker set. | ||||
| The | The | ||||
| .Vt struct sysinit | .Vt struct sysinit | ||||
| type as well as the subsystem identifier constants | type as well as the subsystem identifier constants | ||||
| .Pq Dv SI_SUB_* | .Pq Dv SI_SUB_* | ||||
| and initialization ordering constants | and initialization ordering constants | ||||
| Show All 15 Lines | |||||
| .Fa uniquifier | .Fa uniquifier | ||||
| argument to identify the particular function dispatch data, | argument to identify the particular function dispatch data, | ||||
| the | the | ||||
| .Fa subsystem | .Fa subsystem | ||||
| type of startup interface, the subsystem element | type of startup interface, the subsystem element | ||||
| .Fa order | .Fa order | ||||
| of initialization within the subsystem, the | of initialization within the subsystem, the | ||||
| .Fa func | .Fa func | ||||
| function to call, | function to call | ||||
| and the data specified in | and the arguments, if any, are given by the | ||||
| .Fa ident | .Fa args . | ||||
| argument to pass the function. | |||||
| .Pp | .Pp | ||||
| The | The | ||||
| .Fn SYSUNINIT | .Fn SYSUNINIT | ||||
| macro behaves similarly to the | macro behaves similarly to the | ||||
| .Fn SYSINIT | .Fn SYSINIT | ||||
| macro except that it adds the data to a shutdown linker set. | macro except that it adds the data to a shutdown linker set. | ||||
| .Pp | .Pp | ||||
| The startup linker set for the kernel is scanned during boot to build a | The startup linker set for the kernel is scanned during boot to build a | ||||
| Show All 32 Lines | |||||
| The shutdown linker set for a kernel module is scanned, sorted, and executed | The shutdown linker set for a kernel module is scanned, sorted, and executed | ||||
| when a kernel module is unloaded. | when a kernel module is unloaded. | ||||
| The teardown routines are sorted in the reverse order of the initialization | The teardown routines are sorted in the reverse order of the initialization | ||||
| routines. | routines. | ||||
| The teardown routines of the kernel and any loaded modules are | The teardown routines of the kernel and any loaded modules are | ||||
| .Sy not | .Sy not | ||||
| executed during shutdown. | executed during shutdown. | ||||
| .Sh EXAMPLES | .Sh EXAMPLES | ||||
| This example shows the SYSINIT which displays the copyright notice during boot: | How to create a SYSINIT() passing no arguments to a callback function: | ||||
| .Bd -literal -offset indent | .Bd -literal -offset indent | ||||
| static void | static void | ||||
| print_caddr_t(void *data) | print_notice(void) | ||||
| { | { | ||||
| printf("%s", (char *)data); | printf("This is a 2-clause-BSD licensed system\n"); | ||||
| } | } | ||||
| SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, | SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_notice, NULL); | ||||
| copyright); | .Pp | ||||
| How to create a SYSINIT() passing a single argument to a callback function: | |||||
| .Bd -literal -offset indent | |||||
| static const char notice[] = "This is a 2-clause-BSD licensed system\n"; | |||||
| static void | |||||
| print_notice(const char *data) | |||||
| { | |||||
| printf("%s", notice); | |||||
| } | |||||
| SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_notice, notice); | |||||
| .Ed | .Ed | ||||
| .Sh SEE ALSO | .Sh SEE ALSO | ||||
| .Xr kld 4 , | .Xr kld 4 , | ||||
| .Xr DECLARE_MODULE 9 , | .Xr DECLARE_MODULE 9 , | ||||
| .Xr DEV_MODULE 9 , | .Xr DEV_MODULE 9 , | ||||
| .Xr DRIVER_MODULE 9 , | .Xr DRIVER_MODULE 9 , | ||||
| .Xr MTX_SYSINIT 9 , | .Xr MTX_SYSINIT 9 , | ||||
| .Xr SYSCALL_MODULE 9 | .Xr RM_SYSINIT 9 , | ||||
| .Xr RW_SYSINIT 9 , | |||||
| .Xr SX_SYSINIT 9 , | |||||
| .Xr SYSCALL_MODULE 9 , | |||||
| .Xr VNET_SYSINIT 9 | |||||
| .Sh HISTORY | .Sh HISTORY | ||||
| The | The | ||||
| .Nm | .Nm | ||||
| framework first appeared in | framework first appeared in | ||||
| .Fx 2.2 . | .Fx 2.2 . | ||||
| .Sh AUTHORS | .Sh AUTHORS | ||||
| .An -nosplit | .An -nosplit | ||||
| The | The | ||||
| .Nm | .Nm | ||||
| framework was written by | framework was written by | ||||
| .An Terrence Lambert Aq Mt terry@FreeBSD.org . | .An Terrence Lambert Aq Mt terry@FreeBSD.org . | ||||
| .Pp | .Pp | ||||
| This manual page was written by | This manual page was written by | ||||
| .An Hiten Pandya Aq Mt hmp@FreeBSD.org . | .An Hiten Pandya Aq Mt hmp@FreeBSD.org . | ||||