man.bsd.lv manual page server

Manual Page Search Parameters

MODCTL(2) System Calls Manual MODCTL(2)

modctlmodule control

library “libc”

#include <sys/module.h>

int
modctl(int operation, void *argp);

() provides control over loaded kernel modules. The argument operation is one of MODCTL_LOAD, MODCTL_UNLOAD, MODCTL_STAT, or MODCTL_EXISTS. The argument argp depends on the operation to be performed.

Operations are:

Load a module. The argp argument should be a pointer to a modctl_load_t structure, described below.
Unload a module. In this case, argp should be a string containing the name of the module to be unloaded.
Return a list of loaded modules. In this case, the argp argument should be a pointing to a suitable block of memory. The kernel will fill this block with
  • a count of the number of modules loaded (including aliases),
  • an array of modstat_t structures, one per loaded module, and
  • a series of NUL-terminated strings containing the modules' required modules lists.

If the block is not large enough, the data returned will be truncated to fit. The kernel will then update the iov_len member of the to reflect the size of the complete report, regardless of whether this is larger or smaller than the size passed in.

Test to see if the kernel was compiled with “options MODULAR” and whether or not modules may be loaded at the moment. In this case, argp should be an integer. It should be “0” to test if a user can load a module via MODCTL_LOAD, or it should be “1” to test if the system can autoload modules. Note that this test does not consider the sysctl kern.module.autoload.

The modctl_load_t structure used with MODCTL_LOAD contains the following elements, which should be filled in by the caller:

const char *ml_filename
The name/path of the module to load.
int ml_flags
Zero or more of the following flag values:
Don't load ⟨module⟩.plist.
Ignore kernel version mismatch.
const char *ml_props
Externalized proplib dictionary to pass to module.
size_t ml_propslen
Size of the dictionary blob. ml_props may be NULL in which case ml_propslen must be 0. An upper limit of 4096 bytes is imposed on the value of ml_propslen. Attempting to load a proplib dictionary larger than this size will return ENOMEM.

The modstat_t structure used with MODCTL_STAT contains the following elements, which are filled in by the kernel:

char ms_name[MAXMODNAME]
The name of the module.
modsrc_t ms_source
One of the following enumerated constants:
The module is compiled into the kernel.
The module was provided by the bootstrap loader.
The module was loaded from the file system.
modclass_t ms_class
One of the following enumerated constants:
Security model.
File system.
Device driver.
Executable file format.
Miscellaneous.
uint64_t ms_addr
The load address within the kernel. (This value is available only for privileged users.)
u_int ms_size
Loaded size of the module's text section. (This value is available only for privileged users.)
u_int ms_refcnt
Current number of live references to this module.
u_int ms_flags
The module's flags:
The "force" flag must be specified to reload this module.
The module was auto-loaded by the operating system.
uint_ms_reqoffset
The offset (in bytes) from the beginning of the required-module data.

Upon successful completion, the value returned is 0.

Otherwise, a value of -1 is returned and errno is set to indicate the error.

modctl() will fail if:

[]
The argument operation is MODCTL_UNLOAD and the module is in use or the module is compiled into the kernel.
[]
The argument operation is MODCTL_LOAD and there is a circular dependency in the module's dependency chain.
[]
The argument operation is MODCTL_LOAD and the module is already loaded.
[]
A bad address was given for argp.
[]
The argument operation is MODCTL_LOAD, the specified module resides in the file system, and the module's default proplib file was too large.
[]
The argument operation is invalid.

The argument operation is MODCTL_LOAD and ml_props is not NULL and “ml_propslen” is 0, or ml_props is NULL and “ml_propslen” is not 0. The kernel is unable to internalize the plist. Or, there is a problem with the module or <module>.plist.

The argument operation is MODCTL_LOAD and the module has too many dependencies.
[]
A module name/path is too long.
[]
The argument operation is MODCTL_LOAD and the module or a dependency can't be found.

The argument operation is MODCTL_UNLOAD and no module by the name of argp is loaded.

[]
The argument operation is MODCTL_LOAD and the module is not a valid object for the system. Most likely, one or more undefined symbols could not be resolved by the in-kernel linker.
[]
There was not enough memory to perform the operation.
[]
Not allowed to perform the operation.
[]
The argument operation is MODCTL_LOAD, the ml_flags field in the modctl_load_t structure does not include MODCTL_LOAD_FORCE, and the requested module does not match the current kernel's version information.

module(7), sysctl(7), module(9)

The modctl() function call first appeared in NetBSD 5.0.

December 4, 2019 NetBSD-9.2