Linux kernel module example in Zig

Zig kernel module:

https://codeberg.org/usebeforefree/zig-kernel-module


Noticed nobody has shared an attempt at writing a kernel module with Zig recently. Found this old one, and took it as inspiration. I am open to hearing suggestions, as I am not at all an expert in kernel modules, and would like to learn more about this topic. I will probably use this template to actually try write something useful.

It currently uses make for calling zig build, which then omits an object, that’s then linked to module.c.

Supported Zig versions

Made it work with 0.16.0

18 Likes

Why does it need the module.c? Is it not possible to export the right interface directly from zig?

You need to include the module macros that are defined in linux/module.h. Which you can technically make a wrapper for, and use inside of Zig code.

I am looking into a better/more ergonomic way of doing this.