man-pages/man2/init_module.2

181 lines
4.7 KiB
Groff
Raw Normal View History

.\" Copyright (C) 1996 Free Software Foundation, Inc.
.\" and Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
.\" This file is distributed according to the GNU General Public License.
.\" See the file COPYING in the top level source directory for details.
.\"
.\" 2006-02-09, some reformatting by Luc Van Oostenryck; some
.\" reformatting and rewordings by mtk
.\"
.TH INIT_MODULE 2 2012-10-09 "Linux" "Linux Programmer's Manual"
.SH NAME
init_module \- load a kernel module
.SH SYNOPSIS
.nf
.BI "int init_module(void *" module_image ", unsigned long " len ,
.BI " const char *" param_values );
.fi
.IR Note :
There is no glibc wrapper for this system call; see NOTES.
.SH DESCRIPTION
.BR 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
.I init
function.
This system call requires privilege.
The
.I module_image
argument points to a buffer containing the binary image
to be loaded;
.I len
specifies the size of that buffer.
The module image should be a valid ELF image, built for the running kernel.
The
.I param_values
argument is a string containing space-delimited specifications of the
values for module parameters.
The kernel parses this string and initializes the specified
parameters
Each of the parameter specifications has the form:
.RI " " name [ =value [ ,value ...]]
The parameter name is one of those defined within the module using
.IR module_param ()
(see the Linux kernel source file
.IR include/linux/moduleparam.h ).
The parameter value is optional in the case of
.I bool
and
.I invbool
parameters.
Values for array parameters are specified as a comma-separated list.
.SH "RETURN VALUE"
On success, zero is returned.
On error, \-1 is returned and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EBUSY
The module's initialization routine failed.
.TP
.B EEXIST
A module with this name is already loaded.
.TP
.B EFAULT
An address argument referred to an location that
is outside the process's accessible address space.
.TP
.BR EINVAL " (Linux 2.6 onward)"
.I param_values
is invalid, or some part of the ELF image in
.IR module_image
contains inconsistencies.
.TP
.BR EINVAL " (Linux 2.4 and earlier)"
Some
.I image
slot is filled in incorrectly,
.I image\->name
does not correspond to the original module name, some
.I image\->deps
entry does not correspond to a loaded module,
or some other similar inconsistency.
.TP
.B ENOEXEC
The ELF image in
.I module_image
is too small or has corrupted segments.
.TP
.B EPERM
The caller was not privileged
(did not have the
.B CAP_SYS_MODULE
capability),
or module loading is disabled
(see
.IR /proc/sys/kernel/modules_disabled
in
.BR proc (5)).
.SH "CONFORMING TO"
.BR init_module ()
is Linux-specific.
.SH NOTES
Glibc does not provide a wrapper for this system call; call it using
.BR syscall (2).
Information about currently loaded modules can be found in
.IR /proc/modules
and in the file trees under the per-module subdirectories under
.IR /sys/module .
See the Linux kernel source file
.I include/linux/module.h
for some useful background information.
.SS Linux 2.4 and earlier
.PP
In Linux 2.4 and earlier, this system call was rather different:
.B " #include <linux/module.h>"
.BI " int init_module(const char *" name ", struct module *" image );
This version of the system call
loads the relocated module image pointed to by
.I image
into kernel space and runs the module's
.I init
function.
The caller is responsible for providing the relocated image (since
Linux 2.6, the
.BR init_module ()
system call does the relocation).
.PP
The module image begins with a module structure and is followed by
code and data as appropriate.
The module structure is defined as follows:
.PP
.in +4n
.nf
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
};
.fi
.in
.PP
All of the pointer fields, with the exception of
.I next
and
.IR 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.
.SH "SEE ALSO"
.BR create_module (2),
.BR delete_module (2),
.BR query_module (2),
.BR modprobe (8)