Writing Linux Kernel Modules in Rust
Writing a Linux kernel module in Rust means implementing kernel-defined traits (analogous to C's function-pointer operation tables) for a Rust type, so the kernel can invoke that type's methods as ca…
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.
Writing a Linux kernel module in Rust means implementing kernel-defined traits (analogous to C's function-pointer operation tables) for a Rust type, so the kernel can invoke that type's methods as ca…