3 ms·
For those like I was, wondering why a framework is required to write out of tree Linux modules in rust It’s to auto create rust bindings. Link between rust cra
by zaphirplane 7y ago
For those like I was, wondering why a framework is required to write out of tree Linux modules in rust
It’s to auto create rust bindings. Link between rust crates and kernel build system
- geofft 7y agoHalf that, and half to create safe interfaces that feel like native Rust ("ergonomic") and not like you're writing C in Rust. For instance, the kernel wants you to define a character device by passing a struct with a bunch of C function pointers for how to read, write, seek, ioctl, etc. on the device. Rust has a trait / interface system that's a good match for this use case, so in src/chrdev.rs we define a Rust trait with all these methods, and we have a helper function to create the C struct with FFI-safe function pointers that call the various methods on the Rust trait. The broad goal is that you don't need to use the "unsafe" keyword to write kernel modules that don't access memory directly themselves (filesystems, network protocols, etc.: device drivers might still need unsafe code where actually talking to the device, but it should be as little as possible). That means the interface used by kernel modules can't involve any unwrapped C functions or raw C pointers.