---
name: "EVENTHANDLER_DEREGISTER"
section: "9freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "12.2-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/EVENTHANDLER/9freebsd"
---

# EVENTHANDLER\_DEREGISTER(9freebsd)

kernel event handling functions

Part of [EVENTHANDLER(9freebsd)](/EVENTHANDLER/9freebsd.md).

## NAME

**EVENTHANDLER** – 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\_DEREGISTER\_NOWAIT**(*name*, *tag*);

**EVENTHANDLER\_LIST\_DECLARE**(*name*);

**EVENTHANDLER\_LIST\_DEFINE**(*name*);

**EVENTHANDLER\_DIRECT\_INVOKE**(*name*);

*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*);

*void*\

**eventhandler\_deregister\_nowait**(*struct eventhandler\_list \*list*, *eventhandler\_tag tag*);

*struct eventhandler\_list \**\

**eventhandler\_find\_list**(*const char \*name*);

*void*\

**eventhandler\_prune\_list**(*struct eventhandler\_list \*list*);

## DESCRIPTION

The **EVENTHANDLER** mechanism provides a way for kernel subsystems to register interest in kernel 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. For events that are high frequency it is suggested that you additionally use **EVENTHANDLER\_LIST\_DEFINE**() so that the event handlers can be invoked directly using **EVENTHANDLER\_DIRECT\_INVOKE**() (see below). This saves the invoker from having to do a locked traversal of a global list of event handler lists.

- **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)](/SYSINIT/9.md) 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*. It waits until no threads are running handlers for this event before returning, making it safe to unload a module immediately upon return from this function.

- **EVENTHANDLER\_DEREGISTER\_NOWAIT**()

  This macro removes a previously registered callback associated with tag *tag* from the event handler named by argument *name*. Upon return, one or more threads could still be running the removed function(s), but no new calls will be made. To remove a handler function from within that function, use this version of deregister, to avoid a deadlock.

- **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 callback function.

- **EVENTHANDLER\_LIST\_DEFINE**()

  This macro defines a reference to an event handler list named by argument *name*. It uses [SYSINIT(9)](/SYSINIT/9.md) to initialize the reference and the eventhandler list.

- **EVENTHANDLER\_LIST\_DECLARE**()

  This macro declares an event handler list named by argument *name*. This is only needed for users of **EVENTHANDLER\_DIRECT\_INVOKE**() which are not in the same compilation unit of that list's definition.

- **EVENTHANDLER\_DIRECT\_INVOKE**()

  This macro invokes the event handlers registered for the list named by argument *name*. This macro can only be used if the list was defined with **EVENTHANDLER\_LIST\_DEFINE**(). The macro is variadic with the same semantics as **EVENTHANDLER\_INVOKE**().

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*. If *tag* is *NULL*, all callback functions for the event are removed. This function will not return until all threads have exited from the removed handler callback function(s). This function is not safe to call from inside an event handler callback.

- **eventhandler\_deregister\_nowait**()

  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 structure 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.

- *device\_attach*

  Callback invoked after a device has attached.

- *device\_detach*

  Callbacks invoked before and after a device has detached.

- *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.

- *ifaddr\_event\_ext*

  Callback invoked when an address has been added or removed from an 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 initialized.

- *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 initialized.

- *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 VALUES

The 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 corresponding to parameter *name*, or NULL if no such list was found.

## HISTORY

The **EVENTHANDLER** facility first appeared in FreeBSD 4.0.

## AUTHORS

This manual page was written by Joseph Koshy ⟨*jkoshy@FreeBSD.org*⟩ and Matt Joras ⟨*mjoras@FreeBSD.org*⟩.
