delete_module(2) | System Calls Manual | delete_module(2) |
delete_module - unload a kernel module
Standard C library (libc, -lc)
#include <fcntl.h> /* Definition of O_* constants */ #include <sys/syscall.h> /* Definition of SYS_* constants */ #include <unistd.h>
int syscall(SYS_delete_module, const char *name, unsigned int flags);
Note: glibc provides no wrapper for delete_module(), necessitating the use of syscall(2).
The delete_module() system call attempts to remove the unused loadable module entry identified by name. If the module has an exit function, then that function is executed before unloading the module. The flags argument is used to modify the behavior of the system call, as described below. This system call requires privilege.
Module removal is attempted according to the following rules:
The O_TRUNC flag has one further effect on the rules described above. By default, if a module has an init function but no exit function, then an attempt to remove the module fails. However, if O_TRUNC was specified, this requirement is bypassed.
Using the O_TRUNC flag is dangerous! If the kernel was not built with CONFIG_MODULE_FORCE_UNLOAD, this flag is silently ignored. (Normally, CONFIG_MODULE_FORCE_UNLOAD is enabled.) Using this flag taints the kernel (TAINT_FORCED_RMMOD).
On success, zero is returned. On error, -1 is returned and errno is set to indicate the error.
Linux.
The delete_module() system call is not supported by glibc. No declaration is provided in glibc headers, but, through a quirk of history, glibc versions before glibc 2.23 did export an ABI for this system call. Therefore, in order to employ this system call, it is (before glibc 2.23) sufficient to manually declare the interface in your code; alternatively, you can invoke the system call using syscall(2).
In Linux 2.4 and earlier, the system call took only one argument:
int delete_module(const char *name);
If name is NULL, all unused modules marked auto-clean are removed.
Some further details of differences in the behavior of delete_module() in Linux 2.4 and earlier are not currently explained in this manual page.
The uninterruptible sleep that may occur if O_NONBLOCK is omitted from flags is considered undesirable, because the sleeping process is left in an unkillable state. As at Linux 3.7, specifying O_NONBLOCK is optional, but in future kernels it is likely to become mandatory.
create_module(2), init_module(2), query_module(2), lsmod(8), modprobe(8), rmmod(8)
2023-10-31 | Linux man-pages 6.7 |