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

# module(9freebsd)

structure describing a kernel module

## NAME

**module** – structure describing a kernel module

## DESCRIPTION

Each module in the kernel is described by a *module\_t* structure. The structure contains the name of the device, a unique ID number, a pointer to an event handler function and to an argument, which is given to the event handler, as well as some kernel internal data.

The [DECLARE\_MODULE(9)](/DECLARE_MODULE/9.md) macro registers the module with the system.

When the module is loaded, the event handler function is called with the *what* argument set to MOD\_LOAD.

On unload it is first called with *what* set to MOD\_QUIESCE. If the unload was not forced, a non-zero return will prevent the unload from happening.

If the unload continues *what* is set to MOD\_UNLOAD. If the module returns non-zero to this, the unload will not happen.

The difference between MOD\_QUIESCE and MOD\_UNLOAD is that the module should fail MOD\_QUIESCE if it is currently in use, whereas MOD\_UNLOAD should only fail if it is impossible to unload the module, for instance because there are memory references to the module which cannot be revoked.

When the system is shutting down, *what* contains the value of MOD\_SHUTDOWN.

The module should return EOPNOTSUPP for unsupported and unrecognized values of *what*.

## EXAMPLES

```
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
static int foo_handler(module_t mod, int /*modeventtype_t*/ what,
                       void *arg);
static moduledata_t mod_data= {
        "foo",
        foo_handler,
	NULL
};
MODULE_VERSION(foo, 1);
MODULE_DEPEND(foo, bar, 1, 3, 4);
DECLARE_MODULE(foo, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);
```

## SEE ALSO

[DECLARE\_MODULE(9)](/DECLARE_MODULE/9.md), [DEV\_MODULE(9)](/DEV_MODULE/9.md), [DRIVER\_MODULE(9)](/DRIVER_MODULE/9.md), [MODULE\_DEPEND(9)](/MODULE_DEPEND/9.md), [MODULE\_PNP\_INFO(9)](/MODULE_PNP_INFO/9.md), [MODULE\_VERSION(9)](/MODULE_VERSION/9.md), [SYSCALL\_MODULE(9)](/SYSCALL_MODULE/9.md)

*/usr/share/examples/kld*

## AUTHORS

This manual page was written by Alexander Langer ⟨*alex@FreeBSD.org*⟩.
