1 .\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH DELETE_MODULE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
7 delete_module \- unload a kernel module
10 .RI ( libc ", " \-lc )
13 .BR "#include <fcntl.h>" " /* Definition of " O_* " constants */"
14 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
15 .B #include <unistd.h>
17 .BI "int syscall(SYS_delete_module, const char *" name ", unsigned int " flags );
21 glibc provides no wrapper for
23 necessitating the use of
28 system call attempts to remove the unused loadable module entry
33 function, then that function is executed before unloading the module.
36 argument is used to modify the behavior of the system call,
38 This system call requires privilege.
40 Module removal is attempted according to the following rules:
42 If there are other loaded modules that depend on
43 (i.e., refer to symbols defined in) this module,
46 Otherwise, if the reference count for the module
47 (i.e., the number of processes currently using the module)
48 is zero, then the module is immediately unloaded.
50 If a module has a nonzero reference count,
51 then the behavior depends on the bits set in
53 In normal usage (see NOTES), the
55 flag is always specified, and the
57 flag may additionally be specified.
58 .\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
59 .\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
61 The various combinations for
63 have the following effect:
66 .B flags == O_NONBLOCK
67 The call returns immediately, with an error.
69 .B flags == (O_NONBLOCK | O_TRUNC)
70 The module is unloaded immediately,
71 regardless of whether it has a nonzero reference count.
73 .B (flags & O_NONBLOCK) == 0
78 the following steps occur:
81 The module is marked so that no new references are permitted.
83 If the module's reference count is nonzero,
84 the caller is placed in an uninterruptible sleep state
85 .RB ( TASK_UNINTERRUPTIBLE )
86 until the reference count is zero, at which point the call unblocks.
88 The module is unloaded in the usual way.
94 flag has one further effect on the rules described above.
95 By default, if a module has an
99 function, then an attempt to remove the module fails.
102 was specified, this requirement is bypassed.
107 If the kernel was not built with
108 .BR CONFIG_MODULE_FORCE_UNLOAD ,
109 this flag is silently ignored.
111 .B CONFIG_MODULE_FORCE_UNLOAD
113 Using this flag taints the kernel (TAINT_FORCED_RMMOD).
115 On success, zero is returned.
116 On error, \-1 is returned and
118 is set to indicate the error.
122 The module is not "live"
123 (i.e., it is still being initialized or is already marked for removal);
136 refers to a location outside the process's accessible address space.
139 No module by that name exists.
142 The caller was not privileged
146 or module unloading is disabled
148 .I /proc/sys/kernel/modules_disabled
153 Other modules depend on this module;
158 but the reference count of this module is nonzero and
168 system call is not supported by glibc.
169 No declaration is provided in glibc headers, but, through a quirk of history,
170 glibc versions before 2.23 did export an ABI for this system call.
171 Therefore, in order to employ this system call,
172 it is (before glibc 2.23) sufficient to
173 manually declare the interface in your code;
174 alternatively, you can invoke the system call using
177 The uninterruptible sleep that may occur if
181 is considered undesirable, because the sleeping process is left
182 in an unkillable state.
183 As at Linux 3.7, specifying
185 is optional, but in future kernels it is likely to become mandatory.
186 .SS Linux 2.4 and earlier
187 In Linux 2.4 and earlier, the system call took only one argument:
189 .BI " int delete_module(const char *" name );
193 is NULL, all unused modules marked auto-clean are removed.
195 Some further details of differences in the behavior of
197 in Linux 2.4 and earlier are
199 currently explained in this manual page.
201 .BR create_module (2),
203 .BR query_module (2),