Linux kernel modules in Go, built with gokm
gokm is a project that builds Linux kernel modules from plain Go code, using TinyGo. Developers write filesystems, character devices, /proc files, network interfaces and block devices against Go packages, and gokm supplies all the kernel-side code. The project says that goroutines, channels, select, sync, timers, fmt, maps, defer/recover and floating point work inside the kernel. Kernel callbacks run Go code on whatever CPU they arrive on, concurrently, and goroutines are kernel threads.
gokm/linux generates bindings to any kernel function, struct or constant of the running kernel from its BTF[1] data. The heap grows as needed and is garbage-collected by a background collector, and kernel memory never holds Go pointers. Modules are built with kbuild[2], like any other module, and use retpolines[3], IBT, soft-float, the kernel code model and stack-depth analysis.
The project page includes a hello-world example: at insmod the module prints "hello from Go!", and at rmmod it prints "goodbye from Go!", and the build is run with gokm build. A sibling project, gopgext[4], uses the same approach to build PostgreSQL extensions from Go.
Repository gokm github.com
Open source tool that builds Linux kernel modules from plain Go code using TinyGo, with kernel bindings generated from BTF data.
Read the original jespino.github.ioDiscussion
Sources
-
jespino.github.io
Linux kernel modules in Go


