Debian Codegraph @

upstream/debian-unstable/man2/delete_module.2

raw
1 .\" Copyright 2012, Michael Kerrisk <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH delete_module 2 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 delete_module \- unload a kernel module
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ,\~ \-lc )
12 .SH SYNOPSIS
13 .nf
14 .BR "#include <fcntl.h>" " /* Definition of " O_* " constants */"
15 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
16 .B #include <unistd.h>
17 .P
18 .BI "int syscall(SYS_delete_module, const char *" name ", unsigned int " flags );
19 .fi
20 .P
21 .IR Note :
22 glibc provides no wrapper for
23 .BR delete_module (),
24 necessitating the use of
25 .BR syscall (2).
26 .SH DESCRIPTION
27 The
28 .BR delete_module ()
29 system call attempts to remove the unused loadable module entry
30 identified by
31 .IR name .
32 If the module has an
33 .I exit
34 function, then that function is executed before unloading the module.
35 The
36 .I flags
37 argument is used to modify the behavior of the system call,
38 as described below.
39 This system call requires privilege.
40 .P
41 Module removal is attempted according to the following rules:
42 .IP (1) 5
43 If there are other loaded modules that depend on
44 (i.e., refer to symbols defined in) this module,
45 then the call fails.
46 .IP (2)
47 Otherwise, if the reference count for the module
48 (i.e., the number of processes currently using the module)
49 is zero, then the module is immediately unloaded.
50 .IP (3)
51 If a module has a nonzero reference count,
52 then the behavior depends on the bits set in
53 .IR flags .
54 In normal usage (see NOTES), the
55 .B O_NONBLOCK
56 flag is always specified, and the
57 .B O_TRUNC
58 flag may additionally be specified.
59 .\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
60 .\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
61 .IP
62 The various combinations for
63 .I flags
64 have the following effect:
65 .RS
66 .TP
67 .B flags == O_NONBLOCK
68 The call returns immediately, with an error.
69 .TP
70 .B flags == (O_NONBLOCK | O_TRUNC)
71 The module is unloaded immediately,
72 regardless of whether it has a nonzero reference count.
73 .TP
74 .B (flags & O_NONBLOCK) == 0
75 If
76 .I flags
77 does not specify
78 .BR O_NONBLOCK ,
79 the following steps occur:
80 .RS
81 .IP \[bu] 3
82 The module is marked so that no new references are permitted.
83 .IP \[bu]
84 If the module's reference count is nonzero,
85 the caller is placed in an uninterruptible sleep state
86 .RB ( TASK_UNINTERRUPTIBLE )
87 until the reference count is zero, at which point the call unblocks.
88 .IP \[bu]
89 The module is unloaded in the usual way.
90 .RE
91 .RE
92 .P
93 The
94 .B O_TRUNC
95 flag has one further effect on the rules described above.
96 By default, if a module has an
97 .I init
98 function but no
99 .I exit
100 function, then an attempt to remove the module fails.
101 However, if
102 .B O_TRUNC
103 was specified, this requirement is bypassed.
104 .P
105 Using the
106 .B O_TRUNC
107 flag is dangerous!
108 If the kernel was not built with
109 .BR CONFIG_MODULE_FORCE_UNLOAD ,
110 this flag is silently ignored.
111 (Normally,
112 .B CONFIG_MODULE_FORCE_UNLOAD
113 is enabled.)
114 Using this flag taints the kernel (TAINT_FORCED_RMMOD).
115 .SH RETURN VALUE
116 On success, zero is returned.
117 On error, \-1 is returned and
118 .I errno
119 is set to indicate the error.
120 .SH ERRORS
121 .TP
122 .B EBUSY
123 The module is not "live"
124 (i.e., it is still being initialized or is already marked for removal);
125 or, the module has
126 an
127 .I init
128 function but has no
129 .I exit
130 function, and
131 .B O_TRUNC
132 was not specified in
133 .IR flags .
134 .TP
135 .B EFAULT
136 .I name
137 refers to a location outside the process's accessible address space.
138 .TP
139 .B ENOENT
140 No module by that name exists.
141 .TP
142 .B EPERM
143 The caller was not privileged
144 (did not have the
145 .B CAP_SYS_MODULE
146 capability),
147 or module unloading is disabled
148 (see
149 .I /proc/sys/kernel/modules_disabled
150 in
151 .BR proc (5)).
152 .TP
153 .B EWOULDBLOCK
154 Other modules depend on this module;
155 or,
156 .B O_NONBLOCK
157 was specified in
158 .IR flags ,
159 but the reference count of this module is nonzero and
160 .B O_TRUNC
161 was not specified in
162 .IR flags .
163 .SH STANDARDS
164 Linux.
165 .SH HISTORY
166 The
167 .BR delete_module ()
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 glibc 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
175 .BR syscall (2).
176 .SS Linux 2.4 and earlier
177 In Linux 2.4 and earlier, the system call took only one argument:
178 .P
179 .BI " int delete_module(const char *" name );
180 .P
181 If
182 .I name
183 is NULL, all unused modules marked auto-clean are removed.
184 .P
185 Some further details of differences in the behavior of
186 .BR delete_module ()
187 in Linux 2.4 and earlier are
188 .I not
189 currently explained in this manual page.
190 .SH NOTES
191 The uninterruptible sleep that may occur if
192 .B O_NONBLOCK
193 is omitted from
194 .I flags
195 is considered undesirable, because the sleeping process is left
196 in an unkillable state.
197 As at Linux 3.7, specifying
198 .B O_NONBLOCK
199 is optional, but in future kernels it is likely to become mandatory.
200 .SH SEE ALSO
201 .BR create_module (2),
202 .BR init_module (2),
203 .BR query_module (2),
204 .BR lsmod (8),
205 .BR modprobe (8),
206 .BR rmmod (8)