1 .\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH DELETE_MODULE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
27 delete_module \- unload a kernel module
30 .BI "int delete_module(const char *" name ", int " flags );
34 No declaration of this system call is provided in glibc headers; see NOTES.
38 system call attempts to remove the unused loadable module entry
43 function, then that function is executed before unloading the module.
46 argument is used to modify the behavior of the system call,
48 This system call requires privilege.
50 Module removal is attempted according to the following rules:
52 If there are other loaded modules that depend on
53 (i.e., refer to symbols defined in) this module,
56 Otherwise, if the reference count for the module
57 (i.e., the number of processes currently using the module)
58 is zero, then the module is immediately unloaded.
60 If a module has a nonzero reference count,
61 then the behavior depends on the bits set in
63 In normal usage (see NOTES), the
65 flag is always specified, and the
67 flag may additionally be specified.
68 .\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
69 .\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
71 The various combinations for
73 have the following effect:
76 .B flags == O_NONBLOCK
77 The call returns immediately, with an error.
79 .B flags == (O_NONBLOCK | O_TRUNC)
80 The module is unloaded immediately,
81 regardless of whether it has a nonzero reference count.
83 .B (flags & O_NONBLOCK) == 0
88 the following steps occur:
91 The module is marked so that no new references are permitted.
93 If the module's reference count is nonzero,
94 the caller is placed in an uninterruptible sleep state
95 .RB ( TASK_UNINTERRUPTIBLE )
96 until the reference count is zero, at which point the call unblocks.
98 The module is unloaded in the usual way.
104 flag has one further effect on the rules described above.
105 By default, if a module has an
109 function, then an attempt to remove the module fails.
112 was specified, this requirement is bypassed.
117 If the kernel was not built with
118 .BR CONFIG_MODULE_FORCE_UNLOAD ,
119 this flag is silently ignored.
121 .BR CONFIG_MODULE_FORCE_UNLOAD
123 Using this flag taints the kernel (TAINT_FORCED_RMMOD).
125 On success, zero is returned.
126 On error, \-1 is returned and
128 is set appropriately.
132 The module is not "live"
133 (i.e., it is still being initialized or is already marked for removal);
146 refers to a location outside the process's accessible address space.
149 No module by that name exists.
152 The caller was not privileged
156 or module unloading is disabled
158 .IR /proc/sys/kernel/modules_disabled
163 Other modules depend on this module;
168 but the reference count of this module is nonzero and
178 system call is not supported by glibc.
179 No declaration is provided in glibc headers, but, through a quirk of history,
180 glibc versions before 2.23 did export an ABI for this system call.
181 Therefore, in order to employ this system call,
182 it is (before glibc 2.23) sufficient to
183 manually declare the interface in your code;
184 alternatively, you can invoke the system call using
187 The uninterruptible sleep that may occur if
191 is considered undesirable, because the sleeping process is left
192 in an unkillable state.
193 As at Linux 3.7, specifying
195 is optional, but in future kernels it is likely to become mandatory.
196 .SS Linux 2.4 and earlier
197 In Linux 2.4 and earlier, the system call took only one argument:
199 .BI " int delete_module(const char *" name );
203 is NULL, all unused modules marked auto-clean are removed.
205 Some further details of differences in the behavior of
207 in Linux 2.4 and earlier are
209 currently explained in this manual page.
211 .BR create_module (2),
213 .BR query_module (2),