Rust for embedded Linux kernels
Rust for embedded Linux kernels
Posted Apr 23, 2024 18:47 UTC (Tue) by mb (subscriber, #50428)In reply to: Rust for embedded Linux kernels by AClwn
Parent article: Rust for embedded Linux kernels
Yes. But that is only true for Rust code outside of unsafe {} blocks. (All C code essentially is inside of an unsafe block)
Inside of unsafe blocks the unsafe code has to ensure that the requirements of Rust's safe code are upheld.
Therefore, the Rust<->C bindings have to ensure that the requirements on both sides are upheld.
If the C side struct cannot be moved, because for example it contains list_head, the Rust-C-binding needs to pin that structure so the safe Rust code can't move it. If it tries to, it will *then* get a compile error.
But if the C code didn't have list_head before, it was movable and there was no need to pin it. Adding a list_head can therefore break safe Rust code, if the wrapper was not prepared due to the missing pinning.
