2015-05-13 13:49:26 +03:00
|
|
|
.\" $NetBSD: module.9,v 1.33 2015/05/13 10:49:26 pgoyette Exp $
|
2010-07-31 07:14:05 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
.\" by Andrew Doran.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT 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 SUCH DAMAGE.
|
|
|
|
.\"
|
2011-10-18 18:12:04 +04:00
|
|
|
.Dd October 18, 2011
|
2010-07-31 07:14:05 +04:00
|
|
|
.Dt MODULE 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm module ,
|
|
|
|
.Nm module_load ,
|
|
|
|
.Nm module_autoload ,
|
|
|
|
.Nm module_unload ,
|
|
|
|
.Nm module_init_class ,
|
|
|
|
.Nm module_hold ,
|
2010-08-08 02:21:30 +04:00
|
|
|
.Nm module_rele ,
|
|
|
|
.Nm module_find_section
|
2010-07-31 07:14:05 +04:00
|
|
|
.Nd kernel module loader
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/module.h
|
|
|
|
.Fn MODULE "class" "name" "required"
|
|
|
|
.Ft int
|
2010-07-31 17:20:08 +04:00
|
|
|
.Fn module_load "const char *name" "int flags" "prop_dictionary_t props" \
|
|
|
|
"modclass_t class"
|
2010-07-31 07:14:05 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn module_autoload "const char *name" "modclass_t class"
|
|
|
|
.Ft int
|
|
|
|
.Fn module_unload "const char *name"
|
|
|
|
.Ft void
|
|
|
|
.Fn module_init_class "modclass_t class"
|
|
|
|
.Ft int
|
|
|
|
.Fn module_hold "const char *name"
|
|
|
|
.Ft void
|
|
|
|
.Fn module_rele "const char *"
|
2010-08-08 02:21:30 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn module_find_section "const char *" "void **" "size_t *"
|
2010-08-11 22:20:09 +04:00
|
|
|
.Ft void
|
|
|
|
.Fn module_init "void"
|
|
|
|
.Ft void
|
|
|
|
.Fn module_start_unload_thread "void"
|
|
|
|
.Ft void
|
|
|
|
.Fn module_builtin_require_force "void"
|
|
|
|
.Ft void
|
|
|
|
.Fn module_load_vfs_init "void"
|
2010-07-31 07:14:05 +04:00
|
|
|
.Sh DESCRIPTION
|
2010-08-04 09:51:20 +04:00
|
|
|
Modules are sections of code that can be independently linked and selectively
|
2010-07-31 07:14:05 +04:00
|
|
|
loaded into or unloaded from a running kernel.
|
|
|
|
This provides a mechanism to update the module without having to relink
|
|
|
|
the kernel and reboot.
|
2010-07-31 17:20:08 +04:00
|
|
|
Modules can be loaded from within the kernel image, provided by the boot
|
2010-07-31 07:14:05 +04:00
|
|
|
loader, or loaded from the file system.
|
|
|
|
.Pp
|
2010-08-04 09:51:20 +04:00
|
|
|
Two data types are relevant for
|
|
|
|
.Nm :
|
|
|
|
.Bl -enum -offset indent
|
|
|
|
.It
|
2010-07-31 07:14:05 +04:00
|
|
|
The
|
|
|
|
.Vt module_t
|
|
|
|
type provides storage to describe a module.
|
2010-08-04 09:51:20 +04:00
|
|
|
.It
|
2010-07-31 07:14:05 +04:00
|
|
|
The
|
|
|
|
.Vt modinfo_t
|
2010-07-31 17:20:08 +04:00
|
|
|
type resides within the module itself, and contains module header info.
|
2010-08-04 09:51:20 +04:00
|
|
|
.El
|
2010-08-21 17:17:31 +04:00
|
|
|
.Pp
|
|
|
|
The module subsystem is protected by the global kernconfig_mutex.
|
2010-07-31 07:14:05 +04:00
|
|
|
.Sh FUNCTIONS
|
|
|
|
.Bl -tag -width abcd
|
|
|
|
.It Fn MODULE "class" "name" "required"
|
|
|
|
The
|
|
|
|
.Fn MODULE
|
|
|
|
macro creates and initializes a
|
|
|
|
.Vt modinfo_t
|
|
|
|
structure.
|
2010-07-31 17:20:08 +04:00
|
|
|
In addition to the explicit arguments, the
|
|
|
|
.Fn MODULE
|
|
|
|
macro creates a reference to the module's
|
|
|
|
.Fn modcmd
|
|
|
|
function.
|
2010-08-04 09:51:20 +04:00
|
|
|
This function is defined as:
|
|
|
|
.Bl -tag -width modcmd -offset indent
|
2010-07-31 17:20:08 +04:00
|
|
|
.It Ft int
|
|
|
|
.Fn modcmd "modcmd_t cmd" "void *data"
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa cmd
|
|
|
|
argument requests one of the following operations:
|
2010-08-04 09:51:20 +04:00
|
|
|
.Bl -tag -width MODULE_CMD_AUTOUNLOAD -offset indent
|
|
|
|
.It Dv MODULE_CMD_INIT
|
|
|
|
Perform module-specific initialization when the module is loaded.
|
|
|
|
.It Dv MODULE_CMD_FINI
|
|
|
|
Perform module-specific clean-up before the module is unloaded.
|
|
|
|
.It Dv MODULE_CMD_AUTOUNLOAD
|
|
|
|
Notify the module that it is about to be unloaded.
|
|
|
|
.It Dv MODULE_CMD_STAT
|
|
|
|
Request the module to provide status information (not currently implemented).
|
2010-07-31 17:20:08 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
All modules'
|
|
|
|
.Fn modcmd
|
|
|
|
functions must implement the
|
|
|
|
.Dv MODULE_CMD_INIT
|
|
|
|
and
|
|
|
|
.Dv MODULE_CMD_FINI
|
2010-08-04 09:51:20 +04:00
|
|
|
commands.
|
|
|
|
The other commands are optional,
|
|
|
|
and should return
|
|
|
|
.Er ENOTTY
|
|
|
|
if not implemented.
|
2010-07-31 17:20:08 +04:00
|
|
|
.Pp
|
|
|
|
For the
|
|
|
|
.Dv MODULE_CMD_INIT
|
|
|
|
command, the
|
|
|
|
.Fa data
|
2010-08-08 18:26:22 +04:00
|
|
|
argument is used to pass a pointer to the module's
|
2010-08-04 09:51:20 +04:00
|
|
|
.Xr prop_dictionary 3 .
|
|
|
|
For the
|
2010-07-31 17:20:08 +04:00
|
|
|
.Dv MODULE_CMD_STAT
|
|
|
|
command, the
|
|
|
|
.Fa data
|
|
|
|
argument points to a buffer where the status information should be placed.
|
|
|
|
.Pp
|
2010-07-31 07:14:05 +04:00
|
|
|
The __link_set mechanism is used to enable the
|
|
|
|
.Nm
|
2010-08-08 18:26:22 +04:00
|
|
|
subsystem to locate the
|
|
|
|
.Vt modinfo_t
|
|
|
|
structure.
|
2010-07-31 07:14:05 +04:00
|
|
|
.It Fn module_load "name" "flags" "props" "class"
|
2010-07-31 17:20:08 +04:00
|
|
|
Load a module, link it into the running kernel, and call the module's
|
2010-08-04 09:51:20 +04:00
|
|
|
.Fn modcmd
|
2010-07-31 17:20:08 +04:00
|
|
|
routine with a
|
|
|
|
.Fa cmd
|
|
|
|
argument of
|
|
|
|
.Dv MODULE_CMD_INIT .
|
2010-07-31 07:14:05 +04:00
|
|
|
If the specified module requires other modules, they are loaded first; if
|
2010-07-31 07:43:00 +04:00
|
|
|
any required module cannot be loaded or if any of their
|
2010-07-31 07:14:05 +04:00
|
|
|
.Fn modcmd
|
2010-08-17 08:09:07 +04:00
|
|
|
control routines returns a non-zero status, loading of this module and
|
|
|
|
the specific required module will fail.
|
|
|
|
The required modules are marked for automatic unloading.
|
|
|
|
Thus, if the loading of the module failed, the required modules will
|
|
|
|
be automatically unloaded after a short delay.
|
2010-07-31 07:14:05 +04:00
|
|
|
.Pp
|
|
|
|
The loader will look first for a built-in module with the specified
|
|
|
|
.Fa name
|
|
|
|
that has not been disabled (see
|
|
|
|
.Fn module_unload
|
|
|
|
below).
|
|
|
|
If a built-in module with that
|
|
|
|
.Fa name
|
|
|
|
is not found, the list of modules prepared by the boot loader is searched.
|
|
|
|
If the named module is still not found, an attempt is made to locate the
|
2011-02-13 19:50:16 +03:00
|
|
|
module within the file system, provided it has been mounted by the
|
|
|
|
initialization code.
|
2010-07-31 07:14:05 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa flags
|
2010-08-04 09:51:20 +04:00
|
|
|
argument can include:
|
|
|
|
.Bl -tag -width MODCTL_LOAD_FORCE -offset indent
|
|
|
|
.It Dv MODCTL_NO_PROP
|
2010-08-12 00:10:55 +04:00
|
|
|
When loading a module from the file system, do not attempt to locate a
|
2010-08-08 18:26:22 +04:00
|
|
|
corresponding prop_dictionary file.
|
2010-08-04 09:51:20 +04:00
|
|
|
.It Dv MODCTL_LOAD_FORCE
|
2010-08-08 18:26:22 +04:00
|
|
|
Force loading of disabled built-in modules and modules built for a
|
|
|
|
different version of the operating system.
|
2010-07-31 07:14:05 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa props
|
|
|
|
argument points to an externalized property list which is passed to the
|
|
|
|
module's
|
|
|
|
.Fn modcmd
|
|
|
|
routine.
|
2010-08-12 00:10:55 +04:00
|
|
|
If a module is being loaded from the file system, and the
|
2010-08-08 18:26:22 +04:00
|
|
|
.Dv MODCTL_NO_PROP
|
|
|
|
flag is not set, the system searches for a file with the same name as the
|
2010-08-08 19:23:28 +04:00
|
|
|
module file, but with the suffix
|
2010-11-28 03:26:38 +03:00
|
|
|
.Dq Pa .plist .
|
2010-08-08 18:26:22 +04:00
|
|
|
If this file is found, the prop_dictionary it contains is loaded and
|
2010-08-17 08:09:07 +04:00
|
|
|
merged with the prop_dictionary from the
|
|
|
|
.Fa props
|
|
|
|
argument.
|
2010-07-31 07:14:05 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa class
|
2010-08-04 09:51:20 +04:00
|
|
|
argument can be any of:
|
|
|
|
.Pp
|
2010-08-08 18:26:22 +04:00
|
|
|
.Bl -tag -width MODULE_CLASS_SECMODEL -offset indent -compact
|
2010-08-04 09:51:20 +04:00
|
|
|
.It Dv MODULE_CLASS_ANY
|
|
|
|
.It Dv MODULE_CLASS_DRIVER
|
2010-08-08 18:26:22 +04:00
|
|
|
Device driver
|
2010-08-04 09:51:20 +04:00
|
|
|
.It Dv MODULE_CLASS_EXEC
|
2010-08-08 18:26:22 +04:00
|
|
|
Executable image handler
|
|
|
|
.It Dv MODULE_CLASS_MISC
|
|
|
|
Miscellaneous module
|
2010-08-08 19:23:28 +04:00
|
|
|
.It Dv MODULE_CLASS_SECMODEL
|
2010-08-08 18:26:22 +04:00
|
|
|
Security model (see
|
|
|
|
.Xr secmodel 9
|
|
|
|
for more details)
|
|
|
|
.It Dv MODULE_CLASS_VFS
|
|
|
|
Virtual file system
|
2010-08-04 09:51:20 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
2010-07-31 17:20:08 +04:00
|
|
|
If the class is not
|
|
|
|
.Dv MODULE_CLASS_ANY ,
|
|
|
|
the class of the module being loaded
|
2010-08-04 09:51:20 +04:00
|
|
|
must match the requested
|
|
|
|
.Fa class .
|
2010-08-08 18:26:22 +04:00
|
|
|
Except when verifying a module's class when it is being loaded, module
|
2010-08-18 05:56:45 +04:00
|
|
|
classes other than
|
|
|
|
.Dv MODULE_CLASS_SECMODEL
|
|
|
|
are transparent to the module subsystem.
|
2010-08-08 18:26:22 +04:00
|
|
|
They are provided only for the benefit of the subsystem's clients.
|
2010-08-18 05:56:45 +04:00
|
|
|
Modules with class
|
|
|
|
.Dv MODULE_CLASS_SECMODEL
|
|
|
|
are automatically registered with
|
|
|
|
.Fn secmodel_register
|
2010-08-25 10:45:35 +04:00
|
|
|
after being successfully loaded, and automatically deregistered with
|
|
|
|
.Fn secmodel_deregister
|
|
|
|
when being unloaded.
|
2010-07-31 07:14:05 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn module_load
|
2010-07-31 17:20:08 +04:00
|
|
|
routine is primarily intended as the implementation of the
|
|
|
|
.Dv MODCTL_LOAD
|
2010-07-31 07:14:05 +04:00
|
|
|
option of the
|
|
|
|
.Xr modctl 2
|
|
|
|
system call.
|
|
|
|
.It Fn module_autoload "name" "class"
|
2010-07-31 17:20:08 +04:00
|
|
|
Auto-load a module, making it available for automatic unloading.
|
2010-07-31 07:14:05 +04:00
|
|
|
The
|
|
|
|
.Fa name
|
|
|
|
and
|
|
|
|
.Fa class
|
|
|
|
arguments are the same as for the
|
|
|
|
.Fn module_load
|
|
|
|
routine.
|
|
|
|
.Pp
|
2010-07-31 17:20:08 +04:00
|
|
|
The module subsystem uses a kernel thread to attempt to automatically
|
|
|
|
unload modules a short time (currently, 10 seconds) after being loaded by
|
|
|
|
.Fn module_autoload .
|
2010-07-31 07:14:05 +04:00
|
|
|
Before the module is unloaded, its
|
|
|
|
.Fn modcmd
|
2010-08-04 09:51:20 +04:00
|
|
|
is called with the
|
2010-07-31 17:20:08 +04:00
|
|
|
.Fa cmd
|
2010-08-04 09:51:20 +04:00
|
|
|
argument specified as
|
2010-07-31 17:20:08 +04:00
|
|
|
.Dv MODULE_CMD_AUTOUNLOAD .
|
2010-07-31 07:14:05 +04:00
|
|
|
A module can prevent itself from being unloaded by returning a non-zero
|
|
|
|
value.
|
|
|
|
.Pp
|
2010-08-04 09:51:20 +04:00
|
|
|
The
|
2010-07-31 07:14:05 +04:00
|
|
|
.Fn module_autoload
|
2010-08-04 09:51:20 +04:00
|
|
|
function is intended for use by kernel components to locate and load optional
|
2010-07-31 07:14:05 +04:00
|
|
|
system components.
|
2010-08-04 09:51:20 +04:00
|
|
|
The function is also used to load modules that are required by other modules.
|
2011-01-09 08:05:10 +03:00
|
|
|
.Pp
|
|
|
|
The directory from which the module is loaded will be searched for a file
|
|
|
|
with the same name as the module file, but with the suffix
|
|
|
|
.Dq Pa .plist .
|
|
|
|
If this file is found, the prop_dictionary it contains will be loaded and
|
|
|
|
passed to the module's
|
|
|
|
.Fn modcmd
|
|
|
|
routine.
|
|
|
|
If this prop_dictionary contains a
|
|
|
|
.Dq Pa noautoload
|
|
|
|
property which is set to
|
|
|
|
.Dq Pa true
|
|
|
|
then the system will refuse to load the module.
|
2010-07-31 07:14:05 +04:00
|
|
|
.It Fn module_unload "name"
|
|
|
|
Unload a module.
|
2010-08-04 09:51:20 +04:00
|
|
|
If the module's reference count is non-zero, the function returns
|
|
|
|
.Er EBUSY .
|
2010-07-31 07:14:05 +04:00
|
|
|
Otherwise, the module's
|
|
|
|
.Fn modcmd
|
2010-07-31 17:20:08 +04:00
|
|
|
routine is called with a
|
|
|
|
.Fa cmd
|
|
|
|
argument of
|
2010-08-17 08:09:07 +04:00
|
|
|
.Dv MODULE_CMD_FINI .
|
|
|
|
If the
|
|
|
|
.Fn modcmd
|
|
|
|
routine returns with an error, then the error is returned to the caller
|
|
|
|
otherwise the module is unloaded.
|
2010-08-04 09:51:20 +04:00
|
|
|
.Pp
|
2010-07-31 07:14:05 +04:00
|
|
|
The reference counts of all modules that were required by this module are
|
2010-08-04 09:51:20 +04:00
|
|
|
decremented, but the required modules are not unloaded by the call to
|
|
|
|
.Fn module_unload .
|
|
|
|
Instead, the required modules may be unloaded by subsequent calls to
|
2010-07-31 07:14:05 +04:00
|
|
|
.Fn module_unload .
|
|
|
|
.Pp
|
2010-08-04 09:51:20 +04:00
|
|
|
Unloading a built-in module causes the module to be marked as disabled.
|
2010-07-31 07:14:05 +04:00
|
|
|
This prevents the module from being re-loaded, except by the
|
|
|
|
.Fn module_load
|
|
|
|
function with the
|
|
|
|
.Fa flags
|
2010-07-31 17:20:08 +04:00
|
|
|
argument set to
|
|
|
|
.Dv MODULE_FORCE_LOAD .
|
2010-07-31 07:14:05 +04:00
|
|
|
.Pp
|
2010-08-04 09:51:20 +04:00
|
|
|
The
|
2010-07-31 07:14:05 +04:00
|
|
|
.Fn module_unload
|
2010-08-04 09:51:20 +04:00
|
|
|
function may be called by the
|
2010-07-31 07:14:05 +04:00
|
|
|
.Xr modctl 2
|
|
|
|
system call, by the module subsystem's internal auto-unload thread, or by
|
|
|
|
other kernel facilities.
|
2010-08-17 08:09:07 +04:00
|
|
|
Generally, other kernel facilities should not be calling this function.
|
2010-07-31 07:14:05 +04:00
|
|
|
.It Fn module_init_class "class"
|
|
|
|
Load and initialize all available modules of the specified
|
|
|
|
.Fa class .
|
|
|
|
Any built-in modules that have not been disabled, and any modules provided
|
|
|
|
by the boot loader are loaded.
|
|
|
|
.It Fn module_hold "name"
|
|
|
|
Increment the reference count of a module.
|
2010-07-31 17:20:08 +04:00
|
|
|
A module cannot be unloaded if its reference count is non-zero.
|
2010-07-31 07:14:05 +04:00
|
|
|
.It Fn module_rele "name"
|
|
|
|
Decrement the reference count of a module.
|
2010-08-08 02:21:30 +04:00
|
|
|
.It Fn module_find_section "name" "addr" "size"
|
|
|
|
Find the start address and size of linker section
|
|
|
|
.Ar name
|
|
|
|
within a module.
|
|
|
|
The miniroot module uses this routine to find the address and size of the
|
2010-08-17 10:44:25 +04:00
|
|
|
embedded file system image.
|
2010-08-08 02:21:30 +04:00
|
|
|
This routine can only examine the linker data for the module that is
|
|
|
|
currently being initialized; it cannot examine data for any other module.
|
2010-08-11 22:20:09 +04:00
|
|
|
.It Fn module_init "void"
|
|
|
|
Initialize the module subsystem.
|
|
|
|
Creates and initializes various data structures, locates all built-in
|
|
|
|
modules, and establishes the sub-system's
|
|
|
|
.Xr sysctl 8
|
|
|
|
tree.
|
|
|
|
.Fn module_init
|
|
|
|
is called early in system initialization to facilitate use of security model
|
|
|
|
modules.
|
|
|
|
.It Fn module_start_unload_thread "void"
|
|
|
|
Create the thread that attempts to automatically unload modules that were
|
|
|
|
loaded via the
|
|
|
|
.Fn module_autoload
|
|
|
|
routine.
|
2010-08-24 09:34:15 +04:00
|
|
|
The function is called only once,
|
|
|
|
after the scheduler and timer functions are initialized.
|
2010-08-11 22:20:09 +04:00
|
|
|
.It Fn module_builtin_require_force "void"
|
|
|
|
Mark as "disabled" any built-in modules that have not been successfully
|
2010-08-12 00:10:55 +04:00
|
|
|
initialized.
|
2010-08-11 22:20:09 +04:00
|
|
|
Modules marked "disabled" can only be loaded if the
|
|
|
|
.Dv MODCTL_LOAD_FORCE
|
|
|
|
is specified.
|
|
|
|
.Fn module_builtin_require_force
|
|
|
|
is called near the end of system initialization, after the
|
|
|
|
.Xr init 8
|
|
|
|
process is created.
|
|
|
|
.It Fn module_load_vfs_init
|
2010-08-12 00:10:55 +04:00
|
|
|
The module subsystem is initialized early, long before any file systems
|
2010-08-11 22:20:09 +04:00
|
|
|
are available.
|
2010-08-12 00:10:55 +04:00
|
|
|
After the root file system is mounted,
|
2010-08-11 22:20:09 +04:00
|
|
|
.Fn module_load_vfs_init
|
2010-08-12 00:10:55 +04:00
|
|
|
is used to enable loading modules from the file system.
|
2010-08-11 22:20:09 +04:00
|
|
|
Until this routine is called, modules can only be loaded if they were
|
|
|
|
built-in to the kernel image or provided by the boot loader.
|
2010-07-31 07:14:05 +04:00
|
|
|
.El
|
2010-08-21 17:17:31 +04:00
|
|
|
.Sh PROGRAMMING CONSIDERATIONS
|
|
|
|
The module subsystem is designed to be called recursively, but only within
|
2010-08-24 09:34:15 +04:00
|
|
|
a single LWP.
|
2010-08-21 17:17:31 +04:00
|
|
|
This permits one module's
|
|
|
|
.Fn modcmd
|
|
|
|
routine to load or unload other modules.
|
|
|
|
.Pp
|
2010-08-24 09:34:15 +04:00
|
|
|
Additional considerations:
|
|
|
|
.Bl -bullet -offset indent
|
|
|
|
.It
|
2010-08-21 17:17:31 +04:00
|
|
|
A module is not permitted to load or unload itself.
|
|
|
|
Attempts to load or unload a module from within its own
|
|
|
|
.Fn modcmd
|
|
|
|
routine will fail with
|
|
|
|
.Er EEXIST
|
|
|
|
or
|
2010-08-24 09:34:15 +04:00
|
|
|
.Er EBUSY ,
|
2010-08-21 17:17:31 +04:00
|
|
|
respectively.
|
2010-08-24 09:34:15 +04:00
|
|
|
.It
|
|
|
|
Although a module can be loaded by using either
|
2010-07-31 07:14:05 +04:00
|
|
|
.Fn module_load
|
2010-08-21 17:17:31 +04:00
|
|
|
or
|
2010-08-24 09:34:15 +04:00
|
|
|
.Fn module_autoload ,
|
2010-08-21 17:17:31 +04:00
|
|
|
it is not possible for the module's
|
|
|
|
.Fn modcmd
|
|
|
|
routine to distinguish between the two methods.
|
|
|
|
Any module which needs to ensure that it does not get auto-unloaded must
|
|
|
|
either handle the
|
|
|
|
.Dv MODULE_CMD_AUTOUNLOAD
|
|
|
|
command in its
|
|
|
|
.Fn modcmd
|
|
|
|
routine, or use
|
|
|
|
.Fn module_hold
|
|
|
|
to increment its reference count.
|
2011-10-18 18:12:04 +04:00
|
|
|
Note however that modules loaded manually with
|
|
|
|
.Xr modload 8
|
|
|
|
are never auto-unloaded.
|
2010-08-24 09:34:15 +04:00
|
|
|
.El
|
2010-07-31 07:14:05 +04:00
|
|
|
.Sh CODE REFERENCES
|
|
|
|
The core of the kernel module implementation is in
|
2010-08-04 09:51:20 +04:00
|
|
|
.Pa sys/kern/kern_module.c
|
2010-07-31 07:14:05 +04:00
|
|
|
and
|
2010-08-04 22:52:49 +04:00
|
|
|
.Pa sys/kern/kern_module_vfs.c .
|
2010-07-31 07:14:05 +04:00
|
|
|
.Pp
|
2010-08-17 08:09:07 +04:00
|
|
|
The routines for linking the module are in
|
|
|
|
.Pa sys/kern/subr_kobj.c .
|
|
|
|
.Pp
|
2010-08-17 10:44:25 +04:00
|
|
|
The routines for reading a module from the file system are in
|
2010-08-17 08:09:07 +04:00
|
|
|
.Pa sys/kern/subr_kobj_vfs.c .
|
|
|
|
.Pp
|
2010-07-31 07:14:05 +04:00
|
|
|
The header file
|
2010-08-04 09:51:20 +04:00
|
|
|
.In sys/sys/module.h
|
2010-07-31 07:14:05 +04:00
|
|
|
describes the public interface.
|
2010-08-17 08:09:07 +04:00
|
|
|
.Pp
|
|
|
|
In addition, each architecture is expected to provide
|
|
|
|
.Fn kobj_machdep ,
|
|
|
|
.Fn kobj_reloc ,
|
|
|
|
and
|
|
|
|
.Fn module_init_md .
|
|
|
|
.Fn kobj_machdep
|
|
|
|
is for any machine dependent actions, such as flushing caches, that are
|
|
|
|
needed when a module is loaded or unloaded.
|
|
|
|
.Fn kobj_reloc
|
|
|
|
deals with resolution of relocatable symbols.
|
|
|
|
.Fn module_init_md
|
|
|
|
is for finding modules passed in by the boot loader.
|
2010-07-31 07:14:05 +04:00
|
|
|
.Sh SEE ALSO
|
2015-05-13 13:49:26 +03:00
|
|
|
.Xr modctl 2 ,
|
|
|
|
.Xr module 7
|
2010-07-31 07:14:05 +04:00
|
|
|
.Sh HISTORY
|
|
|
|
The kernel module subsystem first appeared in
|
|
|
|
.Nx 5.0 .
|
2010-08-04 09:51:20 +04:00
|
|
|
It replaces the
|
|
|
|
.Dq Tn LKM
|
|
|
|
subsystem from earlier releases.
|
2010-08-14 21:49:12 +04:00
|
|
|
.Sh AUTHORS
|
|
|
|
.An -nosplit
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
system was written by
|
2013-07-21 01:39:55 +04:00
|
|
|
.An Andrew Doran Aq Mt ad@NetBSD.org .
|
2010-08-14 21:49:12 +04:00
|
|
|
This manual page was written by
|
2013-07-21 01:39:55 +04:00
|
|
|
.An Paul Goyette Aq Mt pgoyette@NetBSD.org .
|