1235b396aSJoseph Koshy.\" Copyright (c) 2004 Joseph Koshy 2235b396aSJoseph Koshy.\" All rights reserved. 3235b396aSJoseph Koshy.\" 4235b396aSJoseph Koshy.\" Redistribution and use in source and binary forms, with or without 5235b396aSJoseph Koshy.\" modification, are permitted provided that the following conditions 6235b396aSJoseph Koshy.\" are met: 7235b396aSJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright 8235b396aSJoseph Koshy.\" notice, this list of conditions and the following disclaimer. 9235b396aSJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright 10235b396aSJoseph Koshy.\" notice, this list of conditions and the following disclaimer in the 11235b396aSJoseph Koshy.\" documentation and/or other materials provided with the distribution. 12235b396aSJoseph Koshy.\" 13235b396aSJoseph Koshy.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14235b396aSJoseph Koshy.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15235b396aSJoseph Koshy.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16235b396aSJoseph Koshy.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17235b396aSJoseph Koshy.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18235b396aSJoseph Koshy.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19235b396aSJoseph Koshy.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20235b396aSJoseph Koshy.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21235b396aSJoseph Koshy.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22235b396aSJoseph Koshy.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23235b396aSJoseph Koshy.\" SUCH DAMAGE. 24235b396aSJoseph Koshy.\" $FreeBSD$ 25235b396aSJoseph Koshy.\" 26*ad6c0150SJohn-Mark Gurney.Dd April 19, 2014 27235b396aSJoseph Koshy.Dt EVENTHANDLER 9 28235b396aSJoseph Koshy.Os 29235b396aSJoseph Koshy.Sh NAME 30235b396aSJoseph Koshy.Nm EVENTHANDLER 31235b396aSJoseph Koshy.Nd kernel event handling functions 32235b396aSJoseph Koshy.Sh SYNOPSIS 33235b396aSJoseph Koshy.In sys/eventhandler.h 34235b396aSJoseph Koshy.Fn EVENTHANDLER_DECLARE name type 35235b396aSJoseph Koshy.Fn EVENTHANDLER_INVOKE name ... 36235b396aSJoseph Koshy.Ft eventhandler_tag 37235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER name func arg priority 38235b396aSJoseph Koshy.Fn EVENTHANDLER_DEREGISTER name tag 39235b396aSJoseph Koshy.Ft eventhandler_tag 40235b396aSJoseph Koshy.Fo eventhandler_register 41235b396aSJoseph Koshy.Fa "struct eventhandler_list *list" 429df1bed3SJoseph Koshy.Fa "const char *name" 43235b396aSJoseph Koshy.Fa "void *func" 44235b396aSJoseph Koshy.Fa "void *arg" 45235b396aSJoseph Koshy.Fa "int priority" 46235b396aSJoseph Koshy.Fc 47235b396aSJoseph Koshy.Ft void 48235b396aSJoseph Koshy.Fo eventhandler_deregister 49235b396aSJoseph Koshy.Fa "struct eventhandler_list *list" 50235b396aSJoseph Koshy.Fa "eventhandler_tag tag" 51235b396aSJoseph Koshy.Fc 52235b396aSJoseph Koshy.Ft "struct eventhandler_list *" 539df1bed3SJoseph Koshy.Fn eventhandler_find_list "const char *name" 54235b396aSJoseph Koshy.Ft void 55235b396aSJoseph Koshy.Fn eventhandler_prune_list "struct eventhandler_list *list" 56235b396aSJoseph Koshy.Sh DESCRIPTION 57235b396aSJoseph KoshyThe 58235b396aSJoseph Koshy.Nm 59235b396aSJoseph Koshymechanism provides a way for kernel subsystems to register interest in 60235b396aSJoseph Koshykernel events and have their callback functions invoked when these 61235b396aSJoseph Koshyevents occur. 62235b396aSJoseph Koshy.Pp 63235b396aSJoseph KoshyThe normal way to use this subsystem is via the macro interface. 6448ef2433SGiorgos KeramidasThe macros that can be used for working with event handlers and callback 6548ef2433SGiorgos Keramidasfunction lists are: 6648ef2433SGiorgos Keramidas.Bl -tag -width indent 6748ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_DECLARE 6848ef2433SGiorgos KeramidasThis macro declares an event handler named by argument 69235b396aSJoseph Koshy.Fa name 70235b396aSJoseph Koshywith callback functions of type 71235b396aSJoseph Koshy.Fa type . 7248ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_REGISTER 7348ef2433SGiorgos KeramidasThis macro registers a callback function 74235b396aSJoseph Koshy.Fa func 75235b396aSJoseph Koshywith event handler 76235b396aSJoseph Koshy.Fa name . 77235b396aSJoseph KoshyWhen invoked, function 78235b396aSJoseph Koshy.Fa func 79235b396aSJoseph Koshywill be invoked with argument 80235b396aSJoseph Koshy.Fa arg 81235b396aSJoseph Koshyas its first parameter along with any additional parameters passed in 82235b396aSJoseph Koshyvia macro 83235b396aSJoseph Koshy.Fn EVENTHANDLER_INVOKE 84235b396aSJoseph Koshy(see below). 85235b396aSJoseph KoshyCallback functions are invoked in order of priority. 8648ef2433SGiorgos KeramidasThe relative priority of each callback among other callbacks 8748ef2433SGiorgos Keramidasassociated with an event is given by argument 88235b396aSJoseph Koshy.Fa priority , 89235b396aSJoseph Koshywhich is an integer ranging from 90235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_FIRST 91235b396aSJoseph Koshy(highest priority), to 92235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_LAST 93235b396aSJoseph Koshy(lowest priority). 94235b396aSJoseph KoshyThe symbol 95235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_ANY 96235b396aSJoseph Koshymay be used if the handler does not have a specific priority 97235b396aSJoseph Koshyassociated with it. 98235b396aSJoseph KoshyIf registration is successful, 99235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER 100235b396aSJoseph Koshyreturns a cookie of type 101235b396aSJoseph Koshy.Vt eventhandler_tag . 10248ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_DEREGISTER 10348ef2433SGiorgos KeramidasThis macro removes a previously registered callback associated with tag 104235b396aSJoseph Koshy.Fa tag 105235b396aSJoseph Koshyfrom the event handler named by argument 106235b396aSJoseph Koshy.Fa name . 10748ef2433SGiorgos Keramidas.It Fn EVENTHANDLER_INVOKE 10848ef2433SGiorgos KeramidasThis macro is used to invoke all the callbacks associated with event 10948ef2433SGiorgos Keramidashandler 110235b396aSJoseph Koshy.Fa name . 111235b396aSJoseph KoshyThis macro is a variadic one. 112235b396aSJoseph KoshyAdditional arguments to the macro after the 113235b396aSJoseph Koshy.Fa name 114235b396aSJoseph Koshyparameter are passed as the second and subsequent arguments to each 115235b396aSJoseph Koshyregistered callback function. 11648ef2433SGiorgos Keramidas.El 117235b396aSJoseph Koshy.Pp 118235b396aSJoseph KoshyThe macros are implemented using the following functions: 11948ef2433SGiorgos Keramidas.Bl -tag -width indent 12048ef2433SGiorgos Keramidas.It Fn eventhandler_register 12148ef2433SGiorgos KeramidasThe 122235b396aSJoseph Koshy.Fn eventhandler_register 12348ef2433SGiorgos Keramidasfunction is used to register a callback with a given event. 12448ef2433SGiorgos KeramidasThe arguments expected by this function are: 12548ef2433SGiorgos Keramidas.Bl -tag -width ".Fa priority" 12648ef2433SGiorgos Keramidas.It Fa list 12748ef2433SGiorgos KeramidasA pointer to an existing event handler list, or 128235b396aSJoseph Koshy.Dv NULL . 12948ef2433SGiorgos KeramidasIf 130235b396aSJoseph Koshy.Fa list 131235b396aSJoseph Koshyis 132235b396aSJoseph Koshy.Dv NULL , 133235b396aSJoseph Koshythe event handler list corresponding to argument 134235b396aSJoseph Koshy.Fa name 135235b396aSJoseph Koshyis used. 13648ef2433SGiorgos Keramidas.It Fa name 13748ef2433SGiorgos KeramidasThe name of the event handler list. 13848ef2433SGiorgos Keramidas.It Fa func 13948ef2433SGiorgos KeramidasA pointer to a callback function. 140235b396aSJoseph KoshyArgument 141235b396aSJoseph Koshy.Fa arg 142d3d90204SGiorgos Keramidasis passed to the callback function 143235b396aSJoseph Koshy.Fa func 144235b396aSJoseph Koshyas its first argument when it is invoked. 14548ef2433SGiorgos Keramidas.It Fa priority 14648ef2433SGiorgos KeramidasThe relative priority of this callback among all the callbacks 14748ef2433SGiorgos Keramidasregistered for this event. 14848ef2433SGiorgos KeramidasValid values are those in the range 149235b396aSJoseph Koshy.Dv EVENTHANDLER_PRI_FIRST 150235b396aSJoseph Koshyto 15148ef2433SGiorgos Keramidas.Dv EVENTHANDLER_PRI_LAST . 15248ef2433SGiorgos Keramidas.El 153235b396aSJoseph Koshy.Pp 15448ef2433SGiorgos KeramidasThe 15548ef2433SGiorgos Keramidas.Fn eventhandler_register 15648ef2433SGiorgos Keramidasfunction returns a 15748ef2433SGiorgos Keramidas.Fa tag 15848ef2433SGiorgos Keramidasthat can later be used with 159235b396aSJoseph Koshy.Fn eventhandler_deregister 16048ef2433SGiorgos Keramidasto remove the particular callback function. 16148ef2433SGiorgos Keramidas.It Fn eventhandler_deregister 16248ef2433SGiorgos KeramidasThe 16348ef2433SGiorgos Keramidas.Fn eventhandler_deregister 16448ef2433SGiorgos Keramidasfunction removes the callback associated with tag 165235b396aSJoseph Koshy.Fa tag 166235b396aSJoseph Koshyfrom the event handler list pointed to by 167235b396aSJoseph Koshy.Fa list . 168235b396aSJoseph KoshyThis function is safe to call from inside an event handler 169235b396aSJoseph Koshycallback. 17048ef2433SGiorgos Keramidas.It Fn eventhandler_find_list 17148ef2433SGiorgos KeramidasThe 172235b396aSJoseph Koshy.Fn eventhandler_find_list 17348ef2433SGiorgos Keramidasfunction returns a pointer to event handler list structure corresponding 17448ef2433SGiorgos Keramidasto event 175235b396aSJoseph Koshy.Fa name . 17648ef2433SGiorgos Keramidas.It Fn eventhandler_prune_list 17748ef2433SGiorgos KeramidasThe 178235b396aSJoseph Koshy.Fn eventhandler_prune_list 17948ef2433SGiorgos Keramidasfunction removes all deregistered callbacks from the event list 180235b396aSJoseph Koshy.Fa list . 18148ef2433SGiorgos Keramidas.El 182235b396aSJoseph Koshy.Ss Kernel Event Handlers 183235b396aSJoseph KoshyThe following event handlers are present in the kernel: 184235b396aSJoseph Koshy.Bl -tag -width indent 185235b396aSJoseph Koshy.It Vt acpi_sleep_event 186235b396aSJoseph KoshyCallbacks invoked when the system is being sent to sleep. 187235b396aSJoseph Koshy.It Vt acpi_wakeup_event 188235b396aSJoseph KoshyCallbacks invoked when the system is being woken up. 189*ad6c0150SJohn-Mark Gurney.It Vt app_coredump_start 190*ad6c0150SJohn-Mark GurneyCallbacks invoked at start of application core dump. 191*ad6c0150SJohn-Mark Gurney.It Vt app_coredump_progress 192*ad6c0150SJohn-Mark GurneyCallbacks invoked during progress of application core dump. 193*ad6c0150SJohn-Mark Gurney.It Vt app_coredump_finish 194*ad6c0150SJohn-Mark GurneyCallbacks invoked at finish of application core dump. 195*ad6c0150SJohn-Mark Gurney.It Vt app_coredump_error 196*ad6c0150SJohn-Mark GurneyCallbacks invoked on error of application core dump. 197*ad6c0150SJohn-Mark Gurney.It Vt bpf_track 198*ad6c0150SJohn-Mark GurneyCallbacks invoked when a BPF listener attaches to/detaches from network interface. 199*ad6c0150SJohn-Mark Gurney.It Vt cpufreq_levels_changed 200*ad6c0150SJohn-Mark GurneyCallback invoked when cpu frequence levels have changed. 201*ad6c0150SJohn-Mark Gurney.It Vt cpufreq_post_change 202*ad6c0150SJohn-Mark GurneyCallback invoked after cpu frequence has changed. 203*ad6c0150SJohn-Mark Gurney.It Vt cpufreq_pre_change 204*ad6c0150SJohn-Mark GurneyCallback invoked before cpu frequence has changed 205*ad6c0150SJohn-Mark Gurney.It Vt dcons_poll 206*ad6c0150SJohn-Mark GurneyCallback invoked to poll for dcons changes. 207235b396aSJoseph Koshy.It Vt dev_clone 208235b396aSJoseph KoshyCallbacks invoked when a new entry is created under 209235b396aSJoseph Koshy.Pa /dev . 210*ad6c0150SJohn-Mark Gurney.It Vt group_attach_event 211*ad6c0150SJohn-Mark GurneyCallback invoked when an interfance has been added to an interface group. 212*ad6c0150SJohn-Mark Gurney.It Vt group_change_event 213*ad6c0150SJohn-Mark GurneyCallback invoked when an change has been made to an interface group. 214*ad6c0150SJohn-Mark Gurney.It Vt group_detach_event 215*ad6c0150SJohn-Mark GurneyCallback invoked when an interfance has been removed from an interface group. 216235b396aSJoseph Koshy.It Vt ifaddr_event 217235b396aSJoseph KoshyCallbacks invoked when an address is set up on a network interface. 218235b396aSJoseph Koshy.It Vt if_clone_event 219235b396aSJoseph KoshyCallbacks invoked when an interface is cloned. 220*ad6c0150SJohn-Mark Gurney.It Vt iflladdr_event 221*ad6c0150SJohn-Mark GurneyCallback invoked when an if link layer address event has happened. 222235b396aSJoseph Koshy.It Vt ifnet_arrival_event 223235b396aSJoseph KoshyCallbacks invoked when a new network interface appears. 224235b396aSJoseph Koshy.It Vt ifnet_departure_event 225235b396aSJoseph KoshyCallbacks invoked when a network interface is taken down. 226*ad6c0150SJohn-Mark Gurney.It Vt ifnet_link_event 227*ad6c0150SJohn-Mark GurneyCallback invoked when an interfance link event has happened. 22812ede07aSMark Johnston.It Vt kld_load 22912ede07aSMark JohnstonCallbacks invoked after a linker file has been loaded. 23012ede07aSMark Johnston.It Vt kld_unload 23129f4e216SMark JohnstonCallbacks invoked after a linker file has been successfully unloaded. 23229f4e216SMark Johnston.It Vt kld_unload_try 23312ede07aSMark JohnstonCallbacks invoked before a linker file is about to be unloaded. 234c9b645b5SMark JohnstonThese callbacks may be used to return an error and prevent the unload from 235c9b645b5SMark Johnstonproceeding. 236*ad6c0150SJohn-Mark Gurney.It Vt lle_event 237*ad6c0150SJohn-Mark GurneyCallback invoked when an link layer event has happened. 238*ad6c0150SJohn-Mark Gurney.It Vt nmbclusters_change 239*ad6c0150SJohn-Mark GurneyCallback invoked when the number of mbuf clusters has changed. 240*ad6c0150SJohn-Mark Gurney.It Vt nmbufs_change 241*ad6c0150SJohn-Mark GurneyCallback invoked when the number of mbufs has changed. 242*ad6c0150SJohn-Mark Gurney.It Vt maxsockets_change 243*ad6c0150SJohn-Mark GurneyCallback invoked when the maximum number of sockets has changed. 244*ad6c0150SJohn-Mark Gurney.It Vt mountroot 245*ad6c0150SJohn-Mark GurneyCallback invoked when root has been mounted. 246235b396aSJoseph Koshy.It Vt power_profile_change 247235b396aSJoseph KoshyCallbacks invoked when the power profile of the system changes. 248*ad6c0150SJohn-Mark Gurney.It Vt power_resume 249*ad6c0150SJohn-Mark GurneyCallback invoked when the system has resumed. 250*ad6c0150SJohn-Mark Gurney.It Vt power_suspend 251*ad6c0150SJohn-Mark GurneyCallback invoked just before the system is suspended. 252*ad6c0150SJohn-Mark Gurney.It Vt process_ctor 253*ad6c0150SJohn-Mark GurneyCallback invoked when a process is created. 254*ad6c0150SJohn-Mark Gurney.It Vt process_dtor 255*ad6c0150SJohn-Mark GurneyCallback invoked when a process is destroyed. 256235b396aSJoseph Koshy.It Vt process_exec 257235b396aSJoseph KoshyCallbacks invoked when a process performs an 258235b396aSJoseph Koshy.Fn exec 259235b396aSJoseph Koshyoperation. 260235b396aSJoseph Koshy.It Vt process_exit 261235b396aSJoseph KoshyCallbacks invoked when a process exits. 262*ad6c0150SJohn-Mark Gurney.It Vt process_fini 263*ad6c0150SJohn-Mark GurneyCallback invoked when a process memory is destroyed. 264*ad6c0150SJohn-Mark GurneyThis is never called. 265235b396aSJoseph Koshy.It Vt process_fork 266235b396aSJoseph KoshyCallbacks invoked when a process forks a child. 267*ad6c0150SJohn-Mark Gurney.It Vt process_init 268*ad6c0150SJohn-Mark GurneyCallback invoked when a process is initalized. 269*ad6c0150SJohn-Mark Gurney.It Vt random_adaptor_attach 270*ad6c0150SJohn-Mark GurneyCallback invoked when a new random module has been loaded. 271*ad6c0150SJohn-Mark Gurney.It Vt register_framebuffer 272*ad6c0150SJohn-Mark GurneyCallback invoked when a new frame buffer is registered. 273*ad6c0150SJohn-Mark Gurney.It Vt route_redirect_event 274*ad6c0150SJohn-Mark GurneyCallback invoked when a route gets redirected to a new location. 275235b396aSJoseph Koshy.It Vt shutdown_pre_sync 276235b396aSJoseph KoshyCallbacks invoked at shutdown time, before file systems are synchronized. 277235b396aSJoseph Koshy.It Vt shutdown_post_sync 278235b396aSJoseph KoshyCallbacks invoked at shutdown time, after all file systems are synchronized. 279235b396aSJoseph Koshy.It Vt shutdown_final 280235b396aSJoseph KoshyCallbacks invoked just before halting the system. 281*ad6c0150SJohn-Mark Gurney.It Vt tcp_offload_listen_start 282*ad6c0150SJohn-Mark GurneyCallback invoked for TCP Offload to start listening for new connections. 283*ad6c0150SJohn-Mark Gurney.It Vt tcp_offload_listen_stop 284*ad6c0150SJohn-Mark GurneyCallback invoked ror TCP Offload to stop listening for new connections. 285*ad6c0150SJohn-Mark Gurney.It Vt thread_ctor 286*ad6c0150SJohn-Mark GurneyCallback invoked when a thread object is created. 287*ad6c0150SJohn-Mark Gurney.It Vt thread_dtor 288*ad6c0150SJohn-Mark GurneyCallback invoked when a thread object is destroyed. 289*ad6c0150SJohn-Mark Gurney.It Vt thread_init 290*ad6c0150SJohn-Mark GurneyCallback invoked when a thread object is initalized. 291*ad6c0150SJohn-Mark Gurney.It Vt thread_fini 292*ad6c0150SJohn-Mark GurneyCallback invoked when a thread object is deinitalized. 293*ad6c0150SJohn-Mark Gurney.It Vt usb_dev_configured 294*ad6c0150SJohn-Mark GurneyCallback invoked when a USB device is configured 295*ad6c0150SJohn-Mark Gurney.It Vt unregister_framebuffer 296*ad6c0150SJohn-Mark GurneyCallback invoked when a frame buffer is deregistered. 297*ad6c0150SJohn-Mark Gurney.It Vt vfs_mounted 298*ad6c0150SJohn-Mark GurneyCallback invoked when a file system is mounted. 299*ad6c0150SJohn-Mark Gurney.It Vt vfs_unmounted 300*ad6c0150SJohn-Mark GurneyCallback invoked when a file system is unmounted. 301*ad6c0150SJohn-Mark Gurney.It Vt vlan_config 302*ad6c0150SJohn-Mark GurneyCallback invoked when the vlan configuration has changed. 303*ad6c0150SJohn-Mark Gurney.It Vt vlan_unconfig 304*ad6c0150SJohn-Mark GurneyCallback invoked when a vlan is destroyed. 305235b396aSJoseph Koshy.It Vt vm_lowmem 306235b396aSJoseph KoshyCallbacks invoked when virtual memory is low. 307235b396aSJoseph Koshy.It Vt watchdog_list 308235b396aSJoseph KoshyCallbacks invoked when the system watchdog timer is reinitialized. 309235b396aSJoseph Koshy.El 310235b396aSJoseph Koshy.Sh RETURN VALUES 311235b396aSJoseph KoshyThe macro 312235b396aSJoseph Koshy.Fn EVENTHANDLER_REGISTER 313235b396aSJoseph Koshyand function 314235b396aSJoseph Koshy.Fn eventhandler_register 315235b396aSJoseph Koshyreturn a cookie of type 316235b396aSJoseph Koshy.Vt eventhandler_tag , 317235b396aSJoseph Koshywhich may be used in a subsequent call to 318235b396aSJoseph Koshy.Fn EVENTHANDLER_DEREGISTER 319235b396aSJoseph Koshyor 320235b396aSJoseph Koshy.Fn eventhandler_deregister . 321235b396aSJoseph Koshy.Pp 32248ef2433SGiorgos KeramidasThe 323235b396aSJoseph Koshy.Fn eventhandler_find_list 32448ef2433SGiorgos Keramidasfunction 325235b396aSJoseph Koshyreturns a pointer to an event handler list corresponding to parameter 326235b396aSJoseph Koshy.Fa name , 327235b396aSJoseph Koshyor 328235b396aSJoseph Koshy.Dv NULL 329235b396aSJoseph Koshyif no such list was found. 330235b396aSJoseph Koshy.Sh HISTORY 331235b396aSJoseph KoshyThe 332235b396aSJoseph Koshy.Nm 333235b396aSJoseph Koshyfacility first appeared in 334235b396aSJoseph Koshy.Fx 4.0 . 335235b396aSJoseph Koshy.Sh AUTHORS 336235b396aSJoseph KoshyThis manual page was written by 337235b396aSJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org . 338