diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:55:15 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:55:15 -0400 |
| commit | 253e67c8b3a72b3a4757fdbc5845297628db0a4a (patch) | |
| tree | adf53b66087aa30dfbf8bf391a1dadb044c3bf4d /static/netbsd/man9/module.9 3.html | |
| parent | a9157ce950dfe2fc30795d43b9d79b9d1bffc48b (diff) | |
docs: Added All NetBSD Manuals
Diffstat (limited to 'static/netbsd/man9/module.9 3.html')
| -rw-r--r-- | static/netbsd/man9/module.9 3.html | 539 |
1 files changed, 539 insertions, 0 deletions
diff --git a/static/netbsd/man9/module.9 3.html b/static/netbsd/man9/module.9 3.html new file mode 100644 index 00000000..f8cf2512 --- /dev/null +++ b/static/netbsd/man9/module.9 3.html @@ -0,0 +1,539 @@ +<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>, + <code class="Nm">module_load</code>, + <code class="Nm">module_autoload</code>, + <code class="Nm">module_unload</code>, + <code class="Nm">module_init_class</code>, + <code class="Nm">module_hold</code>, <code class="Nm">module_rele</code>, + <code class="Nm">module_find_section</code>, + <code class="Nm">module_kernel</code>, <code class="Nm">module_name</code>, + <code class="Nm">module_source</code>, + <code class="Nm">module_register_callbacks</code>, + <code class="Nm">module_unregister_callbacks</code>, + <code class="Nm">module_specific_key_create</code>, + <code class="Nm">module_specific_key_delete</code>, + <code class="Nm">module_getspecific</code>, + <code class="Nm">module_setspecific</code> — <span class="Nd">kernel + module loader</span></p> +</section> +<section class="Sh"> +<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1> +<p class="Pp"><code class="In">#include + <<a class="In">sys/module.h</a>></code></p> +<p class="Pp"><code class="Fn">MODULE</code>(<var class="Fa" style="white-space: nowrap;">class</var>, + <var class="Fa" style="white-space: nowrap;">name</var>, + <var class="Fa" style="white-space: nowrap;">required</var>);</p> +<p class="Pp"><var class="Ft">int</var> + <br/> + <code class="Fn">module_load</code>(<var class="Fa" style="white-space: nowrap;">const + char *name</var>, <var class="Fa" style="white-space: nowrap;">int + flags</var>, <var class="Fa" style="white-space: nowrap;">prop_dictionary_t + props</var>, <var class="Fa" style="white-space: nowrap;">modclass_t + class</var>);</p> +<p class="Pp"><var class="Ft">int</var> + <br/> + <code class="Fn">module_autoload</code>(<var class="Fa" style="white-space: nowrap;">const + char *name</var>, <var class="Fa" style="white-space: nowrap;">modclass_t + class</var>);</p> +<p class="Pp"><var class="Ft">int</var> + <br/> + <code class="Fn">module_unload</code>(<var class="Fa" style="white-space: nowrap;">const + char *name</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_init_class</code>(<var class="Fa" style="white-space: nowrap;">modclass_t + class</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_hold</code>(<var class="Fa" style="white-space: nowrap;">module_t + *module</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_rele</code>(<var class="Fa" style="white-space: nowrap;">module_t + *module</var>);</p> +<p class="Pp"><var class="Ft">int</var> + <br/> + <code class="Fn">module_find_section</code>(<var class="Fa" style="white-space: nowrap;">const + char *</var>, <var class="Fa" style="white-space: nowrap;">void **</var>, + <var class="Fa" style="white-space: nowrap;">size_t *</var>);</p> +<p class="Pp"><var class="Ft">module_t *</var> + <br/> + <code class="Fn">module_kernel</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p> +<p class="Pp"><var class="Ft">const char *</var> + <br/> + <code class="Fn">module_name</code>(<var class="Fa" style="white-space: nowrap;">struct + module *module</var>);</p> +<p class="Pp"><var class="Ft">modsrc_t</var> + <br/> + <code class="Fn">module_source</code>(<var class="Fa" style="white-space: nowrap;">struct + module *module</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_init</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_start_unload_thread</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_builtin_require_force</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_load_vfs_init</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p> +<p class="Pp"><var class="Ft">void *</var> + <br/> + <code class="Fn">module_register_callbacks</code>(<var class="Fa" style="white-space: nowrap;">void + (*)(struct module *)</var>, + <var class="Fa" style="white-space: nowrap;">void (*unload)(struct module + *)</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_unregister_callbacks</code>(<var class="Fa" style="white-space: nowrap;">void + *</var>);</p> +<p class="Pp"><var class="Ft">specificdata_key_t</var> + <br/> + <code class="Fn">module_specific_key_create</code>(<var class="Fa" style="white-space: nowrap;">specificdata_key_t + *keyp</var>, + <var class="Fa" style="white-space: nowrap;">specificdata_dtor_t + dtor</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">module_specific_key_delete</code>(<var class="Fa" style="white-space: nowrap;">specificdata_key_t + key</var>);</p> +<p class="Pp"><var class="Ft">void *</var> + <br/> + <code class="Fn">module_getspecific</code>(<var class="Fa" style="white-space: nowrap;">module_t + *mod</var>, <var class="Fa" style="white-space: nowrap;">specificdata_key_t + key</var>);</p> +<p class="Pp"><var class="Ft">void *</var> + <br/> + <code class="Fn">module_setspecific</code>(<var class="Fa" style="white-space: nowrap;">module_t + *mod</var>, <var class="Fa" style="white-space: nowrap;">specificdata_key_t + key</var>, <var class="Fa" style="white-space: nowrap;">void + *data</var>);</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1> +<p class="Pp">Modules are sections of code that can be independently linked and + selectively loaded into or unloaded from a running kernel. This provides a + mechanism to update the module without having to relink the kernel and + reboot. Modules can be loaded from within the kernel image, provided by the + boot loader, or loaded from the file system.</p> +<p class="Pp">The <code class="Nm">module</code> subsystem includes two data + types:</p> +<ol class="Bl-enum Bd-indent"> + <li>The <var class="Vt">module_t</var> type provides storage to describe a + module.</li> + <li>The <var class="Vt">modinfo_t</var> type resides within + <var class="Vt">module_t</var> and contains module header info.</li> +</ol> +<p class="Pp">The module subsystem is protected by the global + <var class="Va">kernconfig_mutex</var>.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="FUNCTIONS"><a class="permalink" href="#FUNCTIONS">FUNCTIONS</a></h1> +<dl class="Bl-tag"> + <dt id="MODULE"><a class="permalink" href="#MODULE"><code class="Fn">MODULE</code></a>(<var class="Fa">class</var>, + <var class="Fa">name</var>, <var class="Fa">required</var>)</dt> + <dd>The <code class="Fn">MODULE</code>() macro creates and initializes a + <var class="Vt">modinfo_t</var> structure. The <var class="Fa">class</var> + argument identifies the class of module, and must be one of the following + (note that <code class="Dv">MODULE_CLASS_ANY</code> should not be used + here): + <div class="Bd-indent"> + <dl class="Bl-tag"> + <dt id="MODULE_CLASS_VFS"><a class="permalink" href="#MODULE_CLASS_VFS"><code class="Dv">MODULE_CLASS_VFS</code></a></dt> + <dd>The module provide a virtual file system - see + <a class="Xr">vfs(9)</a></dd> + <dt id="MODULE_CLASS_DRIVER"><a class="permalink" href="#MODULE_CLASS_DRIVER"><code class="Dv">MODULE_CLASS_DRIVER</code></a></dt> + <dd>The module is a device driver - see <a class="Xr">driver(9)</a></dd> + <dt id="MODULE_CLASS_EXEC"><a class="permalink" href="#MODULE_CLASS_EXEC"><code class="Dv">MODULE_CLASS_EXEC</code></a></dt> + <dd>The module provides an alternate execution environment - see the + various <code class="Dv">COMPAT_xxx</code> options in + <a class="Xr">options(4)</a></dd> + <dt id="MODULE_CLASS_SECMODEL"><a class="permalink" href="#MODULE_CLASS_SECMODEL"><code class="Dv">MODULE_CLASS_SECMODEL</code></a></dt> + <dd>The module provides a security model - see + <a class="Xr">secmodel(9)</a></dd> + <dt id="MODULE_CLASS_BUFQ"><a class="permalink" href="#MODULE_CLASS_BUFQ"><code class="Dv">MODULE_CLASS_BUFQ</code></a></dt> + <dd>The module provides a buffer queue strategy - see + <a class="Xr">bufq(9)</a></dd> + <dt id="MODULE_CLASS_MISC"><a class="permalink" href="#MODULE_CLASS_MISC"><code class="Dv">MODULE_CLASS_MISC</code></a></dt> + <dd>The module provides miscellaneous kernel services</dd> + </dl> + </div> + <p class="Pp">The <var class="Fa">name</var> argument provides the name of + the module. Loaded modules, including those that are built-in to the + kernel, must all have unique names.</p> + <p class="Pp">The <var class="Fa">required</var> argument is a quoted string + containing a comma-separated list of module names that are required by + this module. The list must not contain any white-space. When a module is + loaded, all of its required modules are auto-loaded and initialized + before the module itself is loaded. Loading of required modules is a + recursive operation.</p> + <p class="Pp">If there are no required modules, this argument should be + specified as <code class="Dv">NULL</code>.</p> + <p class="Pp" id="MODULE~2">In addition to the explicit arguments, the + <a class="permalink" href="#MODULE~2"><code class="Fn">MODULE</code></a>() + macro creates a reference to the module's + <code class="Fn">modcmd</code>() function. This function is defined + as:</p> + <div class="Bd-indent"> + <dl class="Bl-tag"> + <dt id="xxx_modcmd"><var class="Ft">int</var></dt> + <dd><a class="permalink" href="#xxx_modcmd"><code class="Fn">xxx_modcmd</code></a>(<var class="Fa">modcmd_t + cmd</var>, <var class="Fa">void *data</var>)</dd> + </dl> + </div> + <p class="Pp">(where xxx is the name of the module, from the + <code class="Dv">MODULE</code> macro).</p> + <p class="Pp">The <var class="Fa">cmd</var> argument requests one of the + following operations:</p> + <div class="Bd-indent"> + <dl class="Bl-tag"> + <dt id="MODULE_CMD_INIT"><a class="permalink" href="#MODULE_CMD_INIT"><code class="Dv">MODULE_CMD_INIT</code></a></dt> + <dd>Perform module-specific initialization when the module is loaded.</dd> + <dt id="MODULE_CMD_FINI"><a class="permalink" href="#MODULE_CMD_FINI"><code class="Dv">MODULE_CMD_FINI</code></a></dt> + <dd>Perform module-specific clean-up before the module is unloaded.</dd> + <dt id="MODULE_CMD_AUTOUNLOAD"><a class="permalink" href="#MODULE_CMD_AUTOUNLOAD"><code class="Dv">MODULE_CMD_AUTOUNLOAD</code></a></dt> + <dd>Notify the module that it is about to be unloaded.</dd> + <dt id="MODULE_CMD_STAT"><a class="permalink" href="#MODULE_CMD_STAT"><code class="Dv">MODULE_CMD_STAT</code></a></dt> + <dd>Request the module to provide status information (not currently + implemented).</dd> + </dl> + </div> + <p class="Pp" id="modcmd">All modules' + <a class="permalink" href="#modcmd"><code class="Fn">modcmd</code></a>() + functions must implement the <code class="Dv">MODULE_CMD_INIT</code> and + <code class="Dv">MODULE_CMD_FINI</code> commands. The other commands are + optional, and should return <code class="Er">ENOTTY</code> if not + implemented.</p> + <p class="Pp">For the <code class="Dv">MODULE_CMD_INIT</code> command, the + <var class="Fa">data</var> argument is used to pass a pointer to the + module's <a class="Xr">prop_dictionary(3)</a>. For the + <code class="Dv">MODULE_CMD_STAT</code> command, the + <var class="Fa">data</var> argument points to a buffer where the status + information should be placed.</p> + <p class="Pp">The __link_set mechanism is used to enable the + <code class="Nm">module</code> subsystem to locate the + <var class="Vt">modinfo_t</var> structure.</p> + </dd> + <dt id="module_load"><a class="permalink" href="#module_load"><code class="Fn">module_load</code></a>(<var class="Fa">name</var>, + <var class="Fa">flags</var>, <var class="Fa">props</var>, + <var class="Fa">class</var>)</dt> + <dd>Load a module, link it into the running kernel, and call the module's + <code class="Fn">modcmd</code>() routine with a <var class="Fa">cmd</var> + argument of <code class="Dv">MODULE_CMD_INIT</code>. If the specified + module requires other modules, they are loaded first; if any required + module cannot be loaded or if any of their + <code class="Fn">modcmd</code>() 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. + <p class="Pp" id="module_unload">The loader will look first for a built-in + module with the specified <var class="Fa">name</var> that has not been + disabled (see + <a class="permalink" href="#module_unload"><code class="Fn">module_unload</code></a>() + below). If a built-in module with that <var class="Fa">name</var> 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 + module within the file system, provided it has been mounted by the + initialization code.</p> + <p class="Pp">The <var class="Fa">flags</var> argument can include:</p> + <div class="Bd-indent"> + <dl class="Bl-tag"> + <dt id="MODCTL_NO_PROP"><a class="permalink" href="#MODCTL_NO_PROP"><code class="Dv">MODCTL_NO_PROP</code></a></dt> + <dd>When loading a module from the file system, do not attempt to locate a + corresponding prop_dictionary file.</dd> + <dt id="MODCTL_LOAD_FORCE"><a class="permalink" href="#MODCTL_LOAD_FORCE"><code class="Dv">MODCTL_LOAD_FORCE</code></a></dt> + <dd>Force loading of disabled built-in modules and modules built for a + different version of the operating system.</dd> + </dl> + </div> + <p class="Pp" id="modcmd~2">The <var class="Fa">props</var> argument points + to an externalized property list which is passed to the module's + <a class="permalink" href="#modcmd~2"><code class="Fn">modcmd</code></a>() + routine. If a module is being loaded from the file system, and the + <code class="Dv">MODCTL_NO_PROP</code> flag is not set, the system + searches for a file with the same name as the module file, but with the + suffix “<span class="Pa">.plist</span>”. If this file is + found, the prop_dictionary it contains is loaded and merged with the + prop_dictionary from the <var class="Fa">props</var> argument.</p> + <p class="Pp">The <var class="Fa">class</var> argument can be any of:</p> + <p class="Pp"></p> + <div class="Bd-indent"> + <dl class="Bl-tag Bl-compact"> + <dt id="MODULE_CLASS_ANY"><a class="permalink" href="#MODULE_CLASS_ANY"><code class="Dv">MODULE_CLASS_ANY</code></a></dt> + <dd style="width: auto;"> </dd> + <dt id="MODULE_CLASS_DRIVER~2"><a class="permalink" href="#MODULE_CLASS_DRIVER~2"><code class="Dv">MODULE_CLASS_DRIVER</code></a></dt> + <dd>Device driver</dd> + <dt id="MODULE_CLASS_EXEC~2"><a class="permalink" href="#MODULE_CLASS_EXEC~2"><code class="Dv">MODULE_CLASS_EXEC</code></a></dt> + <dd>Executable image handler</dd> + <dt id="MODULE_CLASS_MISC~2"><a class="permalink" href="#MODULE_CLASS_MISC~2"><code class="Dv">MODULE_CLASS_MISC</code></a></dt> + <dd>Miscellaneous module</dd> + <dt id="MODULE_CLASS_SECMODEL~2"><a class="permalink" href="#MODULE_CLASS_SECMODEL~2"><code class="Dv">MODULE_CLASS_SECMODEL</code></a></dt> + <dd>Security model (see <a class="Xr">secmodel(9)</a> for more + details)</dd> + <dt id="MODULE_CLASS_VFS~2"><a class="permalink" href="#MODULE_CLASS_VFS~2"><code class="Dv">MODULE_CLASS_VFS</code></a></dt> + <dd>Virtual file system</dd> + </dl> + </div> + <p class="Pp" id="secmodel_register">If the class is not + <code class="Dv">MODULE_CLASS_ANY</code>, the class of the module being + loaded must match the requested <var class="Fa">class</var>. Except when + verifying a module's class when it is being loaded, module classes other + than <code class="Dv">MODULE_CLASS_SECMODEL</code> are transparent to + the module subsystem. They are provided only for the benefit of the + subsystem's clients. Modules with class + <code class="Dv">MODULE_CLASS_SECMODEL</code> are automatically + registered with + <a class="permalink" href="#secmodel_register"><code class="Fn">secmodel_register</code></a>() + after being successfully loaded, and automatically deregistered with + <a class="permalink" href="#secmodel_deregister"><code class="Fn" id="secmodel_deregister">secmodel_deregister</code></a>() + when being unloaded.</p> + <p class="Pp" id="module_load~2">The + <a class="permalink" href="#module_load~2"><code class="Fn">module_load</code></a>() + routine is primarily intended as the implementation of the + <code class="Dv">MODCTL_LOAD</code> option of the + <a class="Xr">modctl(2)</a> system call.</p> + </dd> + <dt><code class="Fn">module_autoload</code>(<var class="Fa">name</var>, + <var class="Fa">class</var>)</dt> + <dd>Auto-load a module, making it available for automatic unloading. The + <var class="Fa">name</var> and <var class="Fa">class</var> arguments are + the same as for the <code class="Fn">module_load</code>() routine. + <p class="Pp" id="module_autoload">The module subsystem uses a kernel thread + to attempt to automatically unload modules a short time (currently, 10 + seconds) after being loaded by + <a class="permalink" href="#module_autoload"><code class="Fn">module_autoload</code></a>(). + Before the module is unloaded by this thread, its + <code class="Fn">modcmd</code>() is called with the + <var class="Fa">cmd</var> argument specified as + <code class="Dv">MODULE_CMD_AUTOUNLOAD</code>. A module can prevent + itself from being unloaded by returning a non-zero value. Exception: If + <code class="Li">kern.module.autounload_unsafe</code> is set, a module + that returns <code class="Er">ENOTTY</code>, meaning it does not + understand the command, may still be autounloaded.</p> + <p class="Pp" id="module_autoload~2">The + <a class="permalink" href="#module_autoload~2"><code class="Fn">module_autoload</code></a>() + function is intended for use by kernel components to locate and load + optional system components. The function is also used to load modules + that are required by other modules.</p> + <p class="Pp" id="modcmd~3">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 “<span class="Pa">.plist</span>”. If this + file is found, the prop_dictionary it contains will be loaded and passed + to the module's + <a class="permalink" href="#modcmd~3"><code class="Fn">modcmd</code></a>() + routine. If this prop_dictionary contains a + “<span class="Pa">noautoload</span>” property which is set + to “<span class="Pa">true</span>” then the system will + refuse to load the module.</p> + </dd> + <dt><code class="Fn">module_unload</code>(<var class="Fa">name</var>)</dt> + <dd>Unload a module. If the module's reference count is non-zero, the function + returns <code class="Er">EBUSY</code>. Otherwise, the module's + <code class="Fn">modcmd</code>() routine is called with a + <var class="Fa">cmd</var> argument of + <code class="Dv">MODULE_CMD_FINI</code>. If the + <code class="Fn">modcmd</code>() routine returns with an error, then the + error is returned to the caller otherwise the module is unloaded. + <p class="Pp" id="module_unload~2">The reference counts of all modules that + were required by this module are decremented, but the required modules + are not unloaded by the call to + <a class="permalink" href="#module_unload~2"><code class="Fn">module_unload</code></a>(). + Instead, the required modules may be unloaded by subsequent calls to + <code class="Fn">module_unload</code>().</p> + <p class="Pp" id="module_load~3">Unloading a built-in module causes the + module to be marked as disabled. This prevents the module from being + re-loaded, except by the + <a class="permalink" href="#module_load~3"><code class="Fn">module_load</code></a>() + function with the <var class="Fa">flags</var> argument set to + <code class="Dv">MODULE_FORCE_LOAD</code>.</p> + <p class="Pp" id="module_unload~3">The + <a class="permalink" href="#module_unload~3"><code class="Fn">module_unload</code></a>() + function may be called by the <a class="Xr">modctl(2)</a> system call, + by the module subsystem's internal auto-unload thread, or by other + kernel facilities. Generally, other kernel facilities should not be + calling this function.</p> + </dd> + <dt id="module_init_class"><a class="permalink" href="#module_init_class"><code class="Fn">module_init_class</code></a>(<var class="Fa">class</var>)</dt> + <dd>Load and initialize all available modules of the specified + <var class="Fa">class</var>. Any built-in modules that have not been + disabled, and any modules provided by the boot loader are loaded.</dd> + <dt id="module_hold"><a class="permalink" href="#module_hold"><code class="Fn">module_hold</code></a>(<var class="Fa">module</var>)</dt> + <dd>Increment the reference count of a module. A module cannot be unloaded if + its reference count is non-zero.</dd> + <dt id="module_rele"><a class="permalink" href="#module_rele"><code class="Fn">module_rele</code></a>(<var class="Fa">module</var>)</dt> + <dd>Decrement the reference count of a module.</dd> + <dt id="module_find_section"><a class="permalink" href="#module_find_section"><code class="Fn">module_find_section</code></a>(<var class="Fa">name</var>, + <var class="Fa">addr</var>, <var class="Fa">size</var>)</dt> + <dd>Find the start address and size of linker section + <var class="Ar">name</var> within a module. The miniroot module uses this + routine to find the address and size of the embedded file system image. + This routine can only examine the linker data for the module that is + currently being initialized; it cannot examine data for any other + module.</dd> + <dt id="module_kernel"><a class="permalink" href="#module_kernel"><code class="Fn">module_kernel</code></a>(<var class="Fa">void</var>)</dt> + <dd>Returns a pointer to a <var class="Ft">module_t</var> structure describing + the kernel module.</dd> + <dt id="module_name"><a class="permalink" href="#module_name"><code class="Fn">module_name</code></a>(<var class="Fa">module</var>)</dt> + <dd>Returns a pointer to the module's name.</dd> + <dt id="module_source"><a class="permalink" href="#module_source"><code class="Fn">module_source</code></a>(<var class="Fa">module</var>)</dt> + <dd>Returns the source of the module, one of + <code class="Dv">MODULE_SOURCE_KERNEL</code>, + <code class="Dv">MODULE_SOURCE_BOOT</code>, or + <code class="Dv">MODULE_SOURCE_FILESYS</code>.</dd> + <dt id="module_init"><a class="permalink" href="#module_init"><code class="Fn">module_init</code></a>(<var class="Fa">void</var>)</dt> + <dd>Initialize the module subsystem. Creates and initializes various data + structures, locates all built-in modules, and establishes the sub-system's + <a class="Xr">sysctl(8)</a> tree. <code class="Fn">module_init</code>() is + called early in system initialization to facilitate use of security model + modules.</dd> + <dt id="module_start_unload_thread"><a class="permalink" href="#module_start_unload_thread"><code class="Fn">module_start_unload_thread</code></a>(<var class="Fa">void</var>)</dt> + <dd>Create the thread that attempts to automatically unload modules that were + loaded via the <code class="Fn">module_autoload</code>() routine. The + function is called only once, after the scheduler and timer functions are + initialized.</dd> + <dt id="module_builtin_require_force"><a class="permalink" href="#module_builtin_require_force"><code class="Fn">module_builtin_require_force</code></a>(<var class="Fa">void</var>)</dt> + <dd>Mark as "disabled" any built-in modules that have not been + successfully initialized. Modules marked "disabled" can only be + loaded if the <code class="Dv">MODCTL_LOAD_FORCE</code> is specified. + <code class="Fn">module_builtin_require_force</code>() is called near the + end of system initialization, after the <a class="Xr">init(8)</a> process + is created.</dd> + <dt id="module_load_vfs_init"><a class="permalink" href="#module_load_vfs_init"><code class="Fn">module_load_vfs_init</code></a>(<var class="Fa">void</var>)</dt> + <dd>The module subsystem is initialized early, long before any file systems + are available. After the root file system is mounted, + <code class="Fn">module_load_vfs_init</code>(<var class="Fa">void</var>) + is used to enable loading modules from the file system. 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.</dd> + <dt id="module_register_callbacks"><a class="permalink" href="#module_register_callbacks"><code class="Fn">module_register_callbacks</code></a>(<var class="Fa">void + (*load)(struct module *)</var>, <var class="Fa">void (*unload)(struct module + *)</var>)</dt> + <dd>Register a new set of callbacks. The <var class="Fa">load</var> callback + is invoked after any module (including this module) is successfully + loaded; the <var class="Fa">unload</var> callback is invoked before any + module is unloaded. Each load or unload event can result in multiple + invocations of the callback routines. An opaque cookie is returned which + can be passed to + <a class="permalink" href="#module_unregister_callbacks"><code class="Fn" id="module_unregister_callbacks">module_unregister_callbacks</code></a>().</dd> + <dt><code class="Fn">module_unregister_callbacks</code>(<var class="Fa">void + *opaque</var>)</dt> + <dd>Unregister a set of callback routines previously registered with + <code class="Fn">module_register_callbacks</code>(). The + <var class="Fa">opaque</var> argument should be the return value from the + previous <code class="Fn">module_register_callbacks</code>() call.</dd> + <dt id="module_specific_key_create"><a class="permalink" href="#module_specific_key_create"><code class="Fn">module_specific_key_create</code></a>(<var class="Fa">specificdata_key_t + *keyp</var>, <var class="Fa">specificdata_dtor_t dtor</var>)</dt> + <dd>Creates a new specificdata_key for use within the + <code class="Nm">module</code> domain. The key identifier is returned in + <var class="Fa">keyp</var>.</dd> + <dt id="module_specific_key_delete"><a class="permalink" href="#module_specific_key_delete"><code class="Fn">module_specific_key_delete</code></a>(<var class="Fa">specificdata_key_t + key</var>)</dt> + <dd>Deletes the specified specificdata_key <var class="Fa">key</var> from the + <code class="Nm">module</code> domain.</dd> + <dt id="module_getspecific"><a class="permalink" href="#module_getspecific"><code class="Fn">module_getspecific</code></a>(<var class="Fa">module_t + *mod</var>, <var class="Fa">specificdata_key_t key</var>)</dt> + <dd>Retrieves the value associated with <var class="Fa">key</var> from module + <var class="Fa">mod</var>.</dd> + <dt id="module_setspecific"><a class="permalink" href="#module_setspecific"><code class="Fn">module_setspecific</code></a>(<var class="Fa">module_t + *mod</var>, <var class="Fa">specificdata_key_t key</var>, + <var class="Fa">void *data</var>)</dt> + <dd>Stores <var class="Fa">data</var> as the value associated with + <var class="Fa">key</var> for module <var class="Fa">mod</var>.</dd> +</dl> +</section> +<section class="Sh"> +<h1 class="Sh" id="PROGRAMMING_CONSIDERATIONS"><a class="permalink" href="#PROGRAMMING_CONSIDERATIONS">PROGRAMMING + CONSIDERATIONS</a></h1> +<p class="Pp">The module subsystem is designed to be called recursively, but + only within a single LWP. This permits one module's + <code class="Fn">modcmd</code>() routine to load or unload other + modules.</p> +<p class="Pp">Additional considerations:</p> +<ul class="Bl-bullet Bd-indent"> + <li id="modcmd~4">A module is not permitted to load or unload itself. Attempts + to load or unload a module from within its own + <a class="permalink" href="#modcmd~4"><code class="Fn">modcmd</code></a>() + routine will fail with <code class="Er">EEXIST</code> or + <code class="Er">EBUSY</code>, respectively.</li> + <li>Although a module can be loaded by using either + <code class="Fn">module_load</code>() or + <code class="Fn">module_autoload</code>(), it is not possible for the + module's <code class="Fn">modcmd</code>() routine to distinguish between + the two methods. Any module which needs to ensure that it does not get + auto-unloaded must either handle the + <code class="Dv">MODULE_CMD_AUTOUNLOAD</code> command in its + <code class="Fn">modcmd</code>() routine, or use + <code class="Fn">module_hold</code>() to increment its reference count. + Note however that modules loaded manually with + <a class="Xr">modload(8)</a> are never auto-unloaded.</li> +</ul> +</section> +<section class="Sh"> +<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1> +<p class="Pp">A set of example modules is available in the + <span class="Pa">src/sys/modules/examples</span> directory hierarchy.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="CODE_REFERENCES"><a class="permalink" href="#CODE_REFERENCES">CODE + REFERENCES</a></h1> +<p class="Pp">The core of the kernel module implementation is in + <span class="Pa">sys/kern/kern_module.c</span> and + <span class="Pa">sys/kern/kern_module_vfs.c</span>.</p> +<p class="Pp">The routines for linking the module are in + <span class="Pa">sys/kern/subr_kobj.c</span>.</p> +<p class="Pp">The routines for reading a module from the file system are in + <span class="Pa">sys/kern/subr_kobj_vfs.c</span>.</p> +<p class="Pp">The header file + <code class="In"><<a class="In">sys/sys/module.h</a>></code> describes + the public interface.</p> +<p class="Pp" id="kobj_machdep">In addition, each architecture is expected to + provide + <a class="permalink" href="#kobj_machdep"><code class="Fn">kobj_machdep</code></a>(), + <a class="permalink" href="#kobj_reloc"><code class="Fn" id="kobj_reloc">kobj_reloc</code></a>(), + and + <a class="permalink" href="#module_init_md"><code class="Fn" id="module_init_md">module_init_md</code></a>(). + <code class="Fn">kobj_machdep</code>() is for any machine dependent actions, + such as flushing caches, that are needed when a module is loaded or + unloaded. <code class="Fn">kobj_reloc</code>() deals with resolution of + relocatable symbols. <code class="Fn">module_init_md</code>() is for finding + modules passed in by the boot loader.</p> +</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">modctl(2)</a>, <a class="Xr">module(7)</a>, + <a class="Xr">specificdata(9)</a>, <a class="Xr">intro(9lua)</a></p> +</section> +<section class="Sh"> +<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1> +<p class="Pp">The kernel module subsystem first appeared in + <span class="Ux">NetBSD 5.0</span>. It replaces the “LKM” + subsystem from earlier releases.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1> +<p class="Pp">The <code class="Nm">module</code> system was written by + <span class="An">Andrew Doran</span> + <<a class="Mt" href="mailto:ad@NetBSD.org">ad@NetBSD.org</a>>. This + manual page was written by <span class="An">Paul Goyette</span> + <<a class="Mt" href="mailto:pgoyette@NetBSD.org">pgoyette@NetBSD.org</a>>.</p> +</section> +</div> +<table class="foot"> + <tr> + <td class="foot-date">July 21, 2021</td> + <td class="foot-os">NetBSD 10.1</td> + </tr> +</table> |
