
Rust in the Kernel vs Rust in User Space: What Changes
What changes when you write Rust for the Linux 6.18 kernel: no std, fallible allocation, errno Results, panics that act like BUG, and no main function.
Tag
445 posts

What changes when you write Rust for the Linux 6.18 kernel: no std, fallible allocation, errno Results, panics that act like BUG, and no main function.

Match on io::ErrorKind to handle NotFound, PermissionDenied and read-only filesystems from Rust std::fs, and use File::try_lock to detect a locked file.

What Rust for Linux is, what the 6.18 kernel actually contains, why the project adopted it as an experiment, and how abstractions keep unsafe code in one place.

The SysRq commands that matter for kernel debugging, each with what it does and when not to use it, plus how to enable them and the REISUB sequence.

Rust's standard library does not talk to the kernel directly on Linux. It calls libc, which issues the syscall. See the layers from File::open down to openat.

Decode a real x86-64 NULL pointer oops from a module, one line at a time: fault address, error code, RIP, registers, call trace and taint flags.

Send kernel messages as UDP packets to another host with netconsole, set it up at boot or run time, and receive crash logs that never reach disk.

Read lines of any length in C with getline, reuse one growing buffer, strip the newline, spot read errors and handle files without a final newline.

Tell a kernel warning from an oops, a BUG and a panic by what the kernel does next, which taint flag it sets and which sysctls turn one into another.

Read the kernel ring buffer with dmesg and the journal with journalctl -k, filter by level and time, follow new messages and avoid clock and permission traps.

Report failures from a C tool the Unix way: perror, strerror and the err and warn family, with errno saved correctly and messages sent to stderr.

Learn the eight printk log levels, the pr_info and pr_err helpers, pr_fmt prefixes, rate limiting and the console loglevel that decides what reaches the screen.