EVENTHANDLER(9FREEBSD) - Linux man page online | System kernel interfaces
Kernel event handling functions.
March 27, 2017
EVENTHANDLER(9) BSD Kernel Developer's Manual EVENTHANDLER(9)
BSD March 27, 2017 BSD
NAMEEVENTHANDLER — kernel event handling functions
SYNOPSIS#include <sys/eventhandler.h> EVENTHANDLER_DECLARE(name, type); EVENTHANDLER_DEFINE(name, func, arg, priority); EVENTHANDLER_INVOKE(name, ...); eventhandler_tag EVENTHANDLER_REGISTER(name, func, arg, priority); EVENTHANDLER_DEREGISTER(name, tag); eventhandler_tag eventhandler_register(struct eventhandler_list *list, const char *name, void *func, void *arg, int priority); void eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag); struct eventhandler_list * eventhandler_find_list(const char *name); void eventhandler_prune_list(struct eventhandler_list *list);
DESCRIPTIONThe EVENTHANDLER mechanism provides a way for kernel subsystems to register interest in ker‐ nel events and have their callback functions invoked when these events occur. Callback functions are invoked in order of priority. The relative priority of each callback among other callbacks associated with an event is given by argument priority, which is an integer ranging from EVENTHANDLER_PRI_FIRST (highest priority), to EVENTHANDLER_PRI_LAST (lowest priority). The symbol EVENTHANDLER_PRI_ANY may be used if the handler does not have a specific priority associated with it. The normal way to use this subsystem is via the macro interface. The macros that can be used for working with event handlers and callback function lists are: EVENTHANDLER_DECLARE() This macro declares an event handler named by argument name with callback functions of type type. EVENTHANDLER_DEFINE() This macro uses SYSINIT(9) to register a callback function func with event handler name. When invoked, function func will be invoked with argument arg as its first parameter along with any additional parameters passed in via macro EVENTHANDLER_INVOKE() (see below). EVENTHANDLER_REGISTER() This macro registers a callback function func with event handler name. When invoked, function func will be invoked with argument arg as its first parameter along with any additional parameters passed in via macro EVENTHANDLER_INVOKE() (see below). If registration is successful, EVENTHANDLER_REGISTER() returns a cookie of type eventhandler_tag. EVENTHANDLER_DEREGISTER() This macro removes a previously registered callback associated with tag tag from the event handler named by argument name. EVENTHANDLER_INVOKE() This macro is used to invoke all the callbacks associated with event handler name. This macro is a variadic one. Additional arguments to the macro after the name parameter are passed as the second and subsequent arguments to each registered call‐ back function. The macros are implemented using the following functions: eventhandler_register() The eventhandler_register() function is used to register a callback with a given event. The arguments expected by this function are: list A pointer to an existing event handler list, or NULL. If list is NULL, the event handler list corresponding to argument name is used. name The name of the event handler list. func A pointer to a callback function. Argument arg is passed to the callback function func as its first argument when it is invoked. priority The relative priority of this callback among all the callbacks registered for this event. Valid values are those in the range EVENTHANDLER_PRI_FIRST to EVENTHANDLER_PRI_LAST. The eventhandler_register() function returns a tag that can later be used with eventhandler_deregister() to remove the particular callback function. eventhandler_deregister() The eventhandler_deregister() function removes the callback associated with tag tag from the event handler list pointed to by list. This function is safe to call from inside an event handler callback. eventhandler_find_list() The eventhandler_find_list() function returns a pointer to event handler list struc‐ ture corresponding to event name. eventhandler_prune_list() The eventhandler_prune_list() function removes all deregistered callbacks from the event list list. Kernel Event Handlers The following event handlers are present in the kernel: acpi_sleep_event Callbacks invoked when the system is being sent to sleep. acpi_wakeup_event Callbacks invoked when the system is being woken up. app_coredump_start Callbacks invoked at start of application core dump. app_coredump_progress Callbacks invoked during progress of application core dump. app_coredump_finish Callbacks invoked at finish of application core dump. app_coredump_error Callbacks invoked on error of application core dump. bpf_track Callbacks invoked when a BPF listener attaches to/detaches from network interface. cpufreq_levels_changed Callback invoked when cpu frequency levels have changed. cpufreq_post_change Callback invoked after cpu frequency has changed. cpufreq_pre_change Callback invoked before cpu frequency has changed. dcons_poll Callback invoked to poll for dcons changes. dev_clone Callbacks invoked when a new entry is created under /dev. group_attach_event Callback invoked when an interfance has been added to an interface group. group_change_event Callback invoked when an change has been made to an interface group. group_detach_event Callback invoked when an interfance has been removed from an interface group. ifaddr_event Callbacks invoked when an address is set up on a network interface. if_clone_event Callbacks invoked when an interface is cloned. iflladdr_event Callback invoked when an if link layer address event has happened. ifnet_arrival_event Callbacks invoked when a new network interface appears. ifnet_departure_event Callbacks invoked when a network interface is taken down. ifnet_link_event Callback invoked when an interfance link event has happened. kld_load Callbacks invoked after a linker file has been loaded. kld_unload Callbacks invoked after a linker file has been successfully unloaded. kld_unload_try Callbacks invoked before a linker file is about to be unloaded. These callbacks may be used to return an error and prevent the unload from proceeding. lle_event Callback invoked when an link layer event has happened. nmbclusters_change Callback invoked when the number of mbuf clusters has changed. nmbufs_change Callback invoked when the number of mbufs has changed. maxsockets_change Callback invoked when the maximum number of sockets has changed. mountroot Callback invoked when root has been mounted. power_profile_change Callbacks invoked when the power profile of the system changes. power_resume Callback invoked when the system has resumed. power_suspend Callback invoked just before the system is suspended. process_ctor Callback invoked when a process is created. process_dtor Callback invoked when a process is destroyed. process_exec Callbacks invoked when a process performs an exec() operation. process_exit Callbacks invoked when a process exits. process_fini Callback invoked when a process memory is destroyed. This is never called. process_fork Callbacks invoked when a process forks a child. process_init Callback invoked when a process is initalized. random_adaptor_attach Callback invoked when a new random module has been loaded. register_framebuffer Callback invoked when a new frame buffer is registered. route_redirect_event Callback invoked when a route gets redirected to a new location. shutdown_pre_sync Callbacks invoked at shutdown time, before file systems are synchronized. shutdown_post_sync Callbacks invoked at shutdown time, after all file systems are synchronized. shutdown_final Callbacks invoked just before halting the system. tcp_offload_listen_start Callback invoked for TCP Offload to start listening for new connections. tcp_offload_listen_stop Callback invoked ror TCP Offload to stop listening for new connections. thread_ctor Callback invoked when a thread object is created. thread_dtor Callback invoked when a thread object is destroyed. thread_init Callback invoked when a thread object is initalized. thread_fini Callback invoked when a thread object is deinitalized. usb_dev_configured Callback invoked when a USB device is configured unregister_framebuffer Callback invoked when a frame buffer is deregistered. vfs_mounted Callback invoked when a file system is mounted. vfs_unmounted Callback invoked when a file system is unmounted. vlan_config Callback invoked when the vlan configuration has changed. vlan_unconfig Callback invoked when a vlan is destroyed. vm_lowmem Callbacks invoked when virtual memory is low. watchdog_list Callbacks invoked when the system watchdog timer is reinitialized.
RETURN VALUESThe macro EVENTHANDLER_REGISTER() and function eventhandler_register() return a cookie of type eventhandler_tag, which may be used in a subsequent call to EVENTHANDLER_DEREGISTER() or eventhandler_deregister(). The eventhandler_find_list() function returns a pointer to an event handler list correspond‐ ing to parameter name, or NULL if no such list was found.
HISTORYThe EVENTHANDLER facility first appeared in FreeBSD 4.0.
AUTHORSThis manual page was written by Joseph Koshy <@FreeBSD.org>.
|This manual||Reference||Other manuals|
bpf(9freebsd) | bpf_filter(9freebsd) | bpf_mtap(9freebsd) | bpf_mtap2(9freebsd) | bpf_tap(9freebsd) | bpf_validate(9freebsd) | bpfattach(9freebsd) | bpfattach2(9freebsd) | bpfdetach(9freebsd) | EVENTHANDLER_DECLARE(9freebsd) | EVENTHANDLER_DEFINE(9freebsd) | eventhandler_deregister(9freebsd) | EVENTHANDLER_DEREGISTER(9freebsd) | eventhandler_find_list(9freebsd) | EVENTHANDLER_INVOKE(9freebsd) | eventhandler_prune_list(9freebsd) | EVENTHANDLER_REGISTER(9freebsd) | eventhandler_register(9freebsd) | pci(9freebsd) | pci_alloc_msi(9freebsd)