init_module — load a kernel module
int
init_module( |
void *module_image, |
unsigned long len, | |
const char *param_values) ; |
![]() |
Note |
---|---|
There is no glibc wrapper for this system call; see NOTES. |
init_module
() loads an ELF
image into kernel space, performs any necessary symbol
relocations, initializes module parameters to values provided
by the caller, and then runs the module's init
function. This system
call requires privilege.
The module_image
argument points to a buffer containing the binary image to be
loaded; len
specifies
the size of that buffer. The module image should be a valid
ELF image, built for the running kernel.
The param_values
argument is a string containing space-delimited
specifications of the values for module parameters (defined
inside the module using module_param
() and module_param_array
()). The kernel parses
this string and initializes the specified parameters. Each of
the parameter specifications has the form:
name
[
=value
[,
value
...]]
The parameter name
is one of those defined
within the module using module_param
() (see the Linux kernel source
file include/linux/moduleparam.h
). The parameter
value
is optional
in the case of bool
and invbool
parameters. Values for array parameters are specified as a
comma-separated list.
Timeout while trying to resolve a symbol reference by this module.
A module with this name is already loaded.
An address argument referred to a location that is outside the process's accessible address space.
param_values
is invalid, or some part of the ELF image in module_image
contains
inconsistencies.
The binary image supplied in module_image
is not an
ELF image, or is an ELF image that is invalid or for a
different architecture.
The caller was not privileged (did not have the
CAP_SYS_MODULE
capability), or module loading is disabled (see
/proc/sys/kernel/modules_disabled
in
proc(5)).
In addition to the above errors, if the module's
init
function is
executed and returns an error, then init_module
() fails and errno
is set to the value returned by the
init
function.
Glibc does not provide a wrapper for this system call; call it using syscall(2).
Information about currently loaded modules can be found in
/proc/modules
and in the file
trees under the per-module subdirectories under /sys/module
.
See the Linux kernel source file include/linux/module.h
for some useful
background information.
In Linux 2.4 and earlier, this system call was rather different:
#include <linux/module.h>
int init_module
(const char *name
,struct module *image
);
(User-space applications can detect which version of
init_module
() is available by
calling query_module
(); the
latter call fails with the error ENOSYS on Linux 2.6 and later.)
The older version of the system call loads the relocated
module image pointed to by image
into kernel space and
runs the module's init
function. The caller
is responsible for providing the relocated image (since
Linux 2.6, the init_module
()
system call does the relocation).
The module image begins with a module structure and is followed by code and data as appropriate. Since Linux 2.2, the module structure is defined as follows:
struct module { unsigned long size_of_struct; struct module *next; const char *name; unsigned long size; long usecount; unsigned long flags; unsigned int nsyms; unsigned int ndeps; struct module_symbol *syms; struct module_ref *deps; struct module_ref *refs; int (*init)(void); void (*cleanup)(void); const struct exception_table_entry *ex_table_start; const struct exception_table_entry *ex_table_end; #ifdef __alpha__ unsigned long gp; #endif };
All of the pointer fields, with the exception of
next
and
refs
, are
expected to point within the module body and be initialized
as appropriate for kernel space, that is, relocated with
the rest of the module.
This page is part of release 3.45 of the Linux man-pages
project. A
description of the project, and information about reporting
bugs, can be found at
http://www.kernel.org/doc/man-pages/.
Copyright (C) 2012 Michael Kerrisk <mtk.manpagesgmail.com> A few fragments remain from a version Copyright (C) 1996 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Since the Linux kernel and libraries are constantly changing, this manual page may be incorrect or out-of-date. The author(s) assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. The author(s) may not have taken the same level of care in the production of this manual, which is licensed free of charge, as they might when working professionally. Formatted or processed versions of this manual, if unaccompanied by the source, must acknowledge the copyright and authors of this work. |