Blame man2/query_module.2

Packit 7cfc04
.\" Copyright (C) 1996 Free Software Foundation, Inc.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
Packit 7cfc04
.\" This file is distributed according to the GNU General Public License.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" 2006-02-09, some reformatting by Luc Van Oostenryck; some
Packit 7cfc04
.\" reformatting and rewordings by mtk
Packit 7cfc04
.\"
Packit 7cfc04
.TH QUERY_MODULE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
query_module \- query the kernel for various bits pertaining to modules
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <linux/module.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int query_module(const char *" name ", int " which ", void *" buf ,
Packit 7cfc04
.BI "                 size_t " bufsize ", size_t *" ret );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
No declaration of this system call is provided in glibc headers; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.IR Note :
Packit 7cfc04
This system call is present only in kernels before Linux 2.6.
Packit 7cfc04
.PP
Packit 7cfc04
.BR query_module ()
Packit 7cfc04
requests information from the kernel about loadable modules.
Packit 7cfc04
The returned information is placed in the buffer pointed to by
Packit 7cfc04
.IR buf .
Packit 7cfc04
The caller must specify the size of
Packit 7cfc04
.I buf
Packit 7cfc04
in
Packit 7cfc04
.IR bufsize .
Packit 7cfc04
The precise nature and format of the returned information
Packit 7cfc04
depend on the operation specified by
Packit 7cfc04
.IR which .
Packit 7cfc04
Some operations require
Packit 7cfc04
.I name
Packit 7cfc04
to identify a currently loaded module, some allow
Packit 7cfc04
.I name
Packit 7cfc04
to be NULL, indicating the kernel proper.
Packit 7cfc04
.PP
Packit 7cfc04
The following values can be specified for
Packit 7cfc04
.IR which :
Packit 7cfc04
.TP
Packit 7cfc04
.B 0
Packit 7cfc04
Returns success, if the kernel supports
Packit 7cfc04
.BR query_module ().
Packit 7cfc04
Used to probe for availability of the system call.
Packit 7cfc04
.TP
Packit 7cfc04
.B QM_MODULES
Packit 7cfc04
Returns the names of all loaded modules.
Packit 7cfc04
The returned buffer consists of a sequence of null-terminated strings;
Packit 7cfc04
.I ret
Packit 7cfc04
is set to the number of
Packit 7cfc04
modules.
Packit 7cfc04
.\" ret is set on ENOSPC
Packit 7cfc04
.TP
Packit 7cfc04
.B QM_DEPS
Packit 7cfc04
Returns the names of all modules used by the indicated module.
Packit 7cfc04
The returned buffer consists of a sequence of null-terminated strings;
Packit 7cfc04
.I ret
Packit 7cfc04
is set to the number of modules.
Packit 7cfc04
.\" ret is set on ENOSPC
Packit 7cfc04
.TP
Packit 7cfc04
.B QM_REFS
Packit 7cfc04
Returns the names of all modules using the indicated module.
Packit 7cfc04
This is the inverse of
Packit 7cfc04
.BR QM_DEPS .
Packit 7cfc04
The returned buffer consists of a sequence of null-terminated strings;
Packit 7cfc04
.I ret
Packit 7cfc04
is set to the number of modules.
Packit 7cfc04
.\" ret is set on ENOSPC
Packit 7cfc04
.TP
Packit 7cfc04
.B QM_SYMBOLS
Packit 7cfc04
Returns the symbols and values exported by the kernel or the indicated
Packit 7cfc04
module.
Packit 7cfc04
The returned buffer is an array of structures of the following form
Packit 7cfc04
.\" ret is set on ENOSPC
Packit 7cfc04
.IP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct module_symbol {
Packit 7cfc04
    unsigned long value;
Packit 7cfc04
    unsigned long name;
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.IP
Packit 7cfc04
followed by null-terminated strings.
Packit 7cfc04
The value of
Packit 7cfc04
.I name
Packit 7cfc04
is the character offset of the string relative to the start of
Packit 7cfc04
.IR buf ;
Packit 7cfc04
.I ret
Packit 7cfc04
is set to the number of symbols.
Packit 7cfc04
.TP
Packit 7cfc04
.B QM_INFO
Packit 7cfc04
Returns miscellaneous information about the indicated module.
Packit 7cfc04
The output buffer format is:
Packit 7cfc04
.IP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct module_info {
Packit 7cfc04
    unsigned long address;
Packit 7cfc04
    unsigned long size;
Packit 7cfc04
    unsigned long flags;
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.IP
Packit 7cfc04
where
Packit 7cfc04
.I address
Packit 7cfc04
is the kernel address at which the module resides,
Packit 7cfc04
.I size
Packit 7cfc04
is the size of the module in bytes, and
Packit 7cfc04
.I flags
Packit 7cfc04
is a mask of
Packit 7cfc04
.BR MOD_RUNNING ,
Packit 7cfc04
.BR MOD_AUTOCLEAN ,
Packit 7cfc04
and so on, that indicates the current status of the module
Packit 7cfc04
(see the Linux kernel source file
Packit 7cfc04
.IR include/linux/module.h ).
Packit 7cfc04
.I ret
Packit 7cfc04
is set to the size of the
Packit 7cfc04
.I module_info
Packit 7cfc04
structure.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, zero is returned.
Packit 7cfc04
On error, \-1 is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
At least one of
Packit 7cfc04
.IR name ,
Packit 7cfc04
.IR buf ,
Packit 7cfc04
or
Packit 7cfc04
.I ret
Packit 7cfc04
was outside the program's accessible address space.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
Invalid
Packit 7cfc04
.IR which ;
Packit 7cfc04
or
Packit 7cfc04
.I name
Packit 7cfc04
is NULL (indicating "the kernel"),
Packit 7cfc04
but this is not permitted with the specified value of
Packit 7cfc04
.IR which .
Packit 7cfc04
.\" Not permitted with QM_DEPS, QM_REFS, or QM_INFO.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOENT
Packit 7cfc04
No module by that
Packit 7cfc04
.I name
Packit 7cfc04
exists.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOSPC
Packit 7cfc04
The buffer size provided was too small.
Packit 7cfc04
.I ret
Packit 7cfc04
is set to the minimum size needed.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOSYS
Packit 7cfc04
.BR query_module ()
Packit 7cfc04
is not supported in this version of the kernel
Packit 7cfc04
(e.g., the kernel is version 2.6 or later).
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
This system call is present on Linux only up until kernel 2.4;
Packit 7cfc04
it was removed in Linux 2.6.
Packit 7cfc04
.\" Removed in Linux 2.5.48
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR query_module ()
Packit 7cfc04
is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Some of the information that was formerly available via
Packit 7cfc04
.BR query_module ()
Packit 7cfc04
can be obtained from
Packit 7cfc04
.IR /proc/modules ,
Packit 7cfc04
.IR /proc/kallsyms ,
Packit 7cfc04
and the files under the directory
Packit 7cfc04
.IR /sys/module .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR query_module ()
Packit 7cfc04
system call is not supported by glibc.
Packit 7cfc04
No declaration is provided in glibc headers, but,
Packit 7cfc04
through a quirk of history, glibc does export an ABI for this system call.
Packit 7cfc04
Therefore, in order to employ this system call,
Packit 7cfc04
it is sufficient to manually declare the interface in your code;
Packit 7cfc04
alternatively, you can invoke the system call using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR create_module (2),
Packit 7cfc04
.BR delete_module (2),
Packit 7cfc04
.BR get_kernel_syms (2),
Packit 7cfc04
.BR init_module (2),
Packit 7cfc04
.BR lsmod (8),
Packit 7cfc04
.BR modinfo (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.