1 .\" Copyright (c) 2004 Joseph Koshy
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nd kernel event handling functions
33 .In sys/eventhandler.h
34 .Fn EVENTHANDLER_DECLARE name type
35 .Fn EVENTHANDLER_DEFINE name func arg priority
36 .Fn EVENTHANDLER_INVOKE name ...
38 .Fn EVENTHANDLER_REGISTER name func arg priority
39 .Fn EVENTHANDLER_DEREGISTER name tag
40 .Fn EVENTHANDLER_DEREGISTER_NOWAIT name tag
42 .Fo eventhandler_register
43 .Fa "struct eventhandler_list *list"
44 .Fa "const char *name"
50 .Fo eventhandler_deregister
51 .Fa "struct eventhandler_list *list"
52 .Fa "eventhandler_tag tag"
55 .Fo eventhandler_deregister_nowait
56 .Fa "struct eventhandler_list *list"
57 .Fa "eventhandler_tag tag"
59 .Ft "struct eventhandler_list *"
60 .Fn eventhandler_find_list "const char *name"
62 .Fn eventhandler_prune_list "struct eventhandler_list *list"
66 mechanism provides a way for kernel subsystems to register interest in
67 kernel events and have their callback functions invoked when these
70 Callback functions are invoked in order of priority.
71 The relative priority of each callback among other callbacks
72 associated with an event is given by argument
74 which is an integer ranging from
75 .Dv EVENTHANDLER_PRI_FIRST
76 (highest priority), to
77 .Dv EVENTHANDLER_PRI_LAST
80 .Dv EVENTHANDLER_PRI_ANY
81 may be used if the handler does not have a specific priority
84 The normal way to use this subsystem is via the macro interface.
85 The macros that can be used for working with event handlers and callback
87 .Bl -tag -width indent
88 .It Fn EVENTHANDLER_DECLARE
89 This macro declares an event handler named by argument
91 with callback functions of type
93 .It Fn EVENTHANDLER_DEFINE
96 to register a callback function
100 When invoked, function
102 will be invoked with argument
104 as its first parameter along with any additional parameters passed in
106 .Fn EVENTHANDLER_INVOKE
108 .It Fn EVENTHANDLER_REGISTER
109 This macro registers a callback function
113 When invoked, function
115 will be invoked with argument
117 as its first parameter along with any additional parameters passed in
119 .Fn EVENTHANDLER_INVOKE
121 If registration is successful,
122 .Fn EVENTHANDLER_REGISTER
123 returns a cookie of type
124 .Vt eventhandler_tag .
125 .It Fn EVENTHANDLER_DEREGISTER
126 This macro removes a previously registered callback associated with tag
128 from the event handler named by argument
130 It waits until no threads are running handlers for this event before
131 returning, making it safe to unload a module immediately upon return
133 .It Fn EVENTHANDLER_DEREGISTER_NOWAIT
134 This macro removes a previously registered callback associated with tag
136 from the event handler named by argument
138 Upon return, one or more threads could still be running the removed
139 function(s), but no new calls will be made.
140 To remove a handler function from within that function, use this
141 version of deregister, to avoid a deadlock.
142 .It Fn EVENTHANDLER_INVOKE
143 This macro is used to invoke all the callbacks associated with event
146 This macro is a variadic one.
147 Additional arguments to the macro after the
149 parameter are passed as the second and subsequent arguments to each
150 registered callback function.
153 The macros are implemented using the following functions:
154 .Bl -tag -width indent
155 .It Fn eventhandler_register
157 .Fn eventhandler_register
158 function is used to register a callback with a given event.
159 The arguments expected by this function are:
160 .Bl -tag -width ".Fa priority"
162 A pointer to an existing event handler list, or
168 the event handler list corresponding to argument
172 The name of the event handler list.
174 A pointer to a callback function.
177 is passed to the callback function
179 as its first argument when it is invoked.
181 The relative priority of this callback among all the callbacks
182 registered for this event.
183 Valid values are those in the range
184 .Dv EVENTHANDLER_PRI_FIRST
186 .Dv EVENTHANDLER_PRI_LAST .
190 .Fn eventhandler_register
193 that can later be used with
194 .Fn eventhandler_deregister
195 to remove the particular callback function.
196 .It Fn eventhandler_deregister
198 .Fn eventhandler_deregister
199 function removes the callback associated with tag
201 from the event handler list pointed to by
207 all callback functions for the event are removed.
208 This function will not return until all threads have exited from the
209 removed handler callback function(s).
210 This function is not safe to call from inside an event handler callback.
211 .It Fn eventhandler_deregister_nowait
213 .Fn eventhandler_deregister
214 function removes the callback associated with tag
216 from the event handler list pointed to by
218 This function is safe to call from inside an event handler
220 .It Fn eventhandler_find_list
222 .Fn eventhandler_find_list
223 function returns a pointer to event handler list structure corresponding
226 .It Fn eventhandler_prune_list
228 .Fn eventhandler_prune_list
229 function removes all deregistered callbacks from the event list
232 .Ss Kernel Event Handlers
233 The following event handlers are present in the kernel:
234 .Bl -tag -width indent
235 .It Vt acpi_sleep_event
236 Callbacks invoked when the system is being sent to sleep.
237 .It Vt acpi_wakeup_event
238 Callbacks invoked when the system is being woken up.
239 .It Vt app_coredump_start
240 Callbacks invoked at start of application core dump.
241 .It Vt app_coredump_progress
242 Callbacks invoked during progress of application core dump.
243 .It Vt app_coredump_finish
244 Callbacks invoked at finish of application core dump.
245 .It Vt app_coredump_error
246 Callbacks invoked on error of application core dump.
248 Callbacks invoked when a BPF listener attaches to/detaches from network interface.
249 .It Vt cpufreq_levels_changed
250 Callback invoked when cpu frequency levels have changed.
251 .It Vt cpufreq_post_change
252 Callback invoked after cpu frequency has changed.
253 .It Vt cpufreq_pre_change
254 Callback invoked before cpu frequency has changed.
256 Callback invoked to poll for dcons changes.
258 Callbacks invoked when a new entry is created under
260 .It Vt group_attach_event
261 Callback invoked when an interfance has been added to an interface group.
262 .It Vt group_change_event
263 Callback invoked when an change has been made to an interface group.
264 .It Vt group_detach_event
265 Callback invoked when an interfance has been removed from an interface group.
267 Callbacks invoked when an address is set up on a network interface.
268 .It Vt if_clone_event
269 Callbacks invoked when an interface is cloned.
270 .It Vt iflladdr_event
271 Callback invoked when an if link layer address event has happened.
272 .It Vt ifnet_arrival_event
273 Callbacks invoked when a new network interface appears.
274 .It Vt ifnet_departure_event
275 Callbacks invoked when a network interface is taken down.
276 .It Vt ifnet_link_event
277 Callback invoked when an interfance link event has happened.
279 Callbacks invoked after a linker file has been loaded.
281 Callbacks invoked after a linker file has been successfully unloaded.
282 .It Vt kld_unload_try
283 Callbacks invoked before a linker file is about to be unloaded.
284 These callbacks may be used to return an error and prevent the unload from
287 Callback invoked when an link layer event has happened.
288 .It Vt nmbclusters_change
289 Callback invoked when the number of mbuf clusters has changed.
291 Callback invoked when the number of mbufs has changed.
292 .It Vt maxsockets_change
293 Callback invoked when the maximum number of sockets has changed.
295 Callback invoked when root has been mounted.
296 .It Vt power_profile_change
297 Callbacks invoked when the power profile of the system changes.
299 Callback invoked when the system has resumed.
301 Callback invoked just before the system is suspended.
303 Callback invoked when a process is created.
305 Callback invoked when a process is destroyed.
307 Callbacks invoked when a process performs an
311 Callbacks invoked when a process exits.
313 Callback invoked when a process memory is destroyed.
314 This is never called.
316 Callbacks invoked when a process forks a child.
318 Callback invoked when a process is initalized.
319 .It Vt random_adaptor_attach
320 Callback invoked when a new random module has been loaded.
321 .It Vt register_framebuffer
322 Callback invoked when a new frame buffer is registered.
323 .It Vt route_redirect_event
324 Callback invoked when a route gets redirected to a new location.
325 .It Vt shutdown_pre_sync
326 Callbacks invoked at shutdown time, before file systems are synchronized.
327 .It Vt shutdown_post_sync
328 Callbacks invoked at shutdown time, after all file systems are synchronized.
329 .It Vt shutdown_final
330 Callbacks invoked just before halting the system.
331 .It Vt tcp_offload_listen_start
332 Callback invoked for TCP Offload to start listening for new connections.
333 .It Vt tcp_offload_listen_stop
334 Callback invoked ror TCP Offload to stop listening for new connections.
336 Callback invoked when a thread object is created.
338 Callback invoked when a thread object is destroyed.
340 Callback invoked when a thread object is initalized.
342 Callback invoked when a thread object is deinitalized.
343 .It Vt usb_dev_configured
344 Callback invoked when a USB device is configured
345 .It Vt unregister_framebuffer
346 Callback invoked when a frame buffer is deregistered.
348 Callback invoked when a file system is mounted.
350 Callback invoked when a file system is unmounted.
352 Callback invoked when the vlan configuration has changed.
354 Callback invoked when a vlan is destroyed.
356 Callbacks invoked when virtual memory is low.
358 Callbacks invoked when the system watchdog timer is reinitialized.
362 .Fn EVENTHANDLER_REGISTER
364 .Fn eventhandler_register
365 return a cookie of type
366 .Vt eventhandler_tag ,
367 which may be used in a subsequent call to
368 .Fn EVENTHANDLER_DEREGISTER
370 .Fn eventhandler_deregister .
373 .Fn eventhandler_find_list
375 returns a pointer to an event handler list corresponding to parameter
379 if no such list was found.
383 facility first appeared in
386 This manual page was written by
387 .An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .