Conceptual
Login

The module Macro and the Module Trait

A loadable kernel module needs an entry point that runs when it is inserted, a cleanup path that runs when it is removed, and a block of metadata recording its name, author, description and licence. In Rust all of that is one macro invocation plus one type that implements a trait with an init function, and the type's Drop implementation is the cleanup, so you cannot forget to write an exit that undoes what init did. A related trait exists for modules whose state must be built in place because it cannot be moved after creation. Module parameters, values a user can set at load time, are declared inside the same macro.

Questions this Concept answers

  • Why does a Rust kernel module not need a separately written exit function to undo what its initialisation did?