3 ms·
Half 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 yo
by geofft 7y ago
Half 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.