console_codes.4: tfix
[man-pages.git] / man2 / delete_module.2
blob3b14111c5e5da1d9b95a29893f32b39fa7d83589
1 .\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH DELETE_MODULE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 delete_module \- unload a kernel module
28 .SH SYNOPSIS
29 .nf
30 .BR "#include <fcntl.h>" "            /* Definition of " O_* " constants */"
31 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
32 .BR "#include <unistd.h>
33 .PP
34 .BI "int syscall(SYS_delete_module, const char *" name ", unsigned int " flags );
35 .fi
36 .PP
37 .IR Note :
38 glibc provides no wrapper for
39 .BR delete_module (),
40 necessitating the use of
41 .BR syscall (2).
42 .SH DESCRIPTION
43 The
44 .BR delete_module ()
45 system call attempts to remove the unused loadable module entry
46 identified by
47 .IR name .
48 If the module has an
49 .I exit
50 function, then that function is executed before unloading the module.
51 The
52 .IR flags
53 argument is used to modify the behavior of the system call,
54 as described below.
55 This system call requires privilege.
56 .PP
57 Module removal is attempted according to the following rules:
58 .IP 1. 4
59 If there are other loaded modules that depend on
60 (i.e., refer to symbols defined in) this module,
61 then the call fails.
62 .IP 2.
63 Otherwise, if the reference count for the module
64 (i.e., the number of processes currently using the module)
65 is zero, then the module is immediately unloaded.
66 .IP 3.
67 If a module has a nonzero reference count,
68 then the behavior depends on the bits set in
69 .IR flags .
70 In normal usage (see NOTES), the
71 .BR O_NONBLOCK
72 flag is always specified, and the
73 .BR O_TRUNC
74 flag may additionally be specified.
75 .\"     O_TRUNC == KMOD_REMOVE_FORCE in kmod library
76 .\"     O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
77 .IP
78 The various combinations for
79 .I flags
80 have the following effect:
81 .RS 4
82 .TP
83 .B flags == O_NONBLOCK
84 The call returns immediately, with an error.
85 .TP
86 .B flags == (O_NONBLOCK | O_TRUNC)
87 The module is unloaded immediately,
88 regardless of whether it has a nonzero reference count.
89 .TP
90 .B (flags & O_NONBLOCK) == 0
92 .I flags
93 does not specify
94 .BR O_NONBLOCK ,
95 the following steps occur:
96 .RS
97 .IP * 3
98 The module is marked so that no new references are permitted.
99 .IP *
100 If the module's reference count is nonzero,
101 the caller is placed in an uninterruptible sleep state
102 .RB ( TASK_UNINTERRUPTIBLE )
103 until the reference count is zero, at which point the call unblocks.
104 .IP *
105 The module is unloaded in the usual way.
110 .B O_TRUNC
111 flag has one further effect on the rules described above.
112 By default, if a module has an
113 .I init
114 function but no
115 .I exit
116 function, then an attempt to remove the module fails.
117 However, if
118 .BR O_TRUNC
119 was specified, this requirement is bypassed.
121 Using the
122 .B O_TRUNC
123 flag is dangerous!
124 If the kernel was not built with
125 .BR CONFIG_MODULE_FORCE_UNLOAD ,
126 this flag is silently ignored.
127 (Normally,
128 .BR CONFIG_MODULE_FORCE_UNLOAD
129 is enabled.)
130 Using this flag taints the kernel (TAINT_FORCED_RMMOD).
131 .SH RETURN VALUE
132 On success, zero is returned.
133 On error, \-1 is returned and
134 .I errno
135 is set to indicate the error.
136 .SH ERRORS
138 .B EBUSY
139 The module is not "live"
140 (i.e., it is still being initialized or is already marked for removal);
141 or, the module has
143 .I init
144 function but has no
145 .I exit
146 function, and
147 .B O_TRUNC
148 was not specified in
149 .IR flags .
151 .B EFAULT
152 .I name
153 refers to a location outside the process's accessible address space.
155 .B ENOENT
156 No module by that name exists.
158 .B EPERM
159 The caller was not privileged
160 (did not have the
161 .B CAP_SYS_MODULE
162 capability),
163 or module unloading is disabled
164 (see
165 .IR /proc/sys/kernel/modules_disabled
167 .BR proc (5)).
169 .B EWOULDBLOCK
170 Other modules depend on this module;
172 .BR O_NONBLOCK
173 was specified in
174 .IR flags ,
175 but the reference count of this module is nonzero and
176 .B O_TRUNC
177 was not specified in
178 .IR flags .
179 .SH CONFORMING TO
180 .BR delete_module ()
181 is Linux-specific.
182 .SH NOTES
184 .BR delete_module ()
185 system call is not supported by glibc.
186 No declaration is provided in glibc headers, but, through a quirk of history,
187 glibc versions before 2.23 did export an ABI for this system call.
188 Therefore, in order to employ this system call,
189 it is (before glibc 2.23) sufficient to
190 manually declare the interface in your code;
191 alternatively, you can invoke the system call using
192 .BR syscall (2).
194 The uninterruptible sleep that may occur if
195 .BR O_NONBLOCK
196 is omitted from
197 .IR flags
198 is considered undesirable, because the sleeping process is left
199 in an unkillable state.
200 As at Linux 3.7, specifying
201 .BR O_NONBLOCK
202 is optional, but in future kernels it is likely to become mandatory.
203 .SS Linux 2.4 and earlier
204 In Linux 2.4 and earlier, the system call took only one argument:
206 .BI "   int delete_module(const char *" name );
209 .I name
210 is NULL, all unused modules marked auto-clean are removed.
212 Some further details of differences in the behavior of
213 .BR delete_module ()
214 in Linux 2.4 and earlier are
215 .I not
216 currently explained in this manual page.
217 .SH SEE ALSO
218 .BR create_module (2),
219 .BR init_module (2),
220 .BR query_module (2),
221 .BR lsmod (8),
222 .BR modprobe (8),
223 .BR rmmod (8)