---
name: "DECLARE_MODULE"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/DECLARE_MODULE"
---

# DECLARE\_MODULE(9)

kernel module declaration macro

## NAME

**DECLARE\_MODULE** – kernel module declaration macro

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/kernel.h\>**

**#include \<sys/module.h\>**

**DECLARE\_MODULE**(*name*, *moduledata\_t data*, *sub*, *order*);

**DECLARE\_MODULE\_TIED**(*name*, *moduledata\_t data*, *sub*, *order*);

## DESCRIPTION

The **DECLARE\_MODULE**() macro declares a generic kernel module. It is used to register the module with the system, using the **SYSINIT**() macro. **DECLARE\_MODULE**() is usually used within other macros, such as [DRIVER\_MODULE(9)](/DRIVER_MODULE/9.md), [DEV\_MODULE(9)](/DEV_MODULE/9.md) and [SYSCALL\_MODULE(9)](/SYSCALL_MODULE/9.md). Of course, it can also be called directly, for example in order to implement dynamic sysctls.

A module declared with **DECLARE\_MODULE\_TIED**() will load only if the running kernel version (as specified by \_\_FreeBSD\_version) is identical to that on which it was built. This declaration should be used by modules which depend on interfaces beyond the stable kernel KBI (such as ABI emulators or hypervisors that rely on internal kernel structures). **DECLARE\_MODULE**() will behave like **DECLARE\_MODULE\_TIED**() when compiled with modules built with the kernel. This allows locks and other synchronization primitives to be inlined safely.

The arguments are:

- *name*

  The module name, which will be used in the **SYSINIT**() call to identify the module.

- *data*

  A *moduledata\_t* structure, which contains two main items, the official name of the module name, which will be used in the *module\_t* structure and a pointer to the event handler function of type *modeventhand\_t*.

- *sub*

  An argument directed to the **SYSINIT**() macro. Valid values for this are contained in the *sysinit\_sub\_id* enumeration (see ⟨sys/kernel.h⟩) and specify the type of system startup interfaces. The [DRIVER\_MODULE(9)](/DRIVER_MODULE/9.md) macro uses a value of SI\_SUB\_DRIVERS here for example, since these modules contain a driver for a device. For kernel modules that are loaded at runtime, a value of SI\_SUB\_EXEC is common.

- *order*

  An argument for **SYSINIT**(). It represents the KLDs order of initialization within the subsystem. Valid values are defined in the *sysinit\_elem\_order* enumeration (In sys/kernel.h).

## SEE ALSO

[DEV\_MODULE(9)](/DEV_MODULE/9.md), [DRIVER\_MODULE(9)](/DRIVER_MODULE/9.md), [module(9)](/module/9.md), [SYSCALL\_MODULE(9)](/SYSCALL_MODULE/9.md)

*/usr/include/sys/kernel.h*, */usr/share/examples/kld*

## AUTHORS

This manual page was written by Alexander Langer ⟨*alex@FreeBSD.org*⟩, inspired by the KLD Facility Programming Tutorial by Andrew Reiter ⟨*arr@watson.org*⟩.
