microsoft / Windows-rust-driver-samples

Rust port of the official Windows Driver Samples on Github. Leverages windows-drivers-rs
https://github.com/microsoft/windows-drivers-rs
Apache License 2.0
209 stars 19 forks source link

SAFETY comments should document preconditions #20

Open jdm opened 2 weeks ago

jdm commented 2 weeks ago

Reading through https://github.com/microsoft/Windows-rust-driver-samples/blob/d9cc3091625f2d3eb0d528b3e6e9ab2c0551c372/general/echo/kmdf/exe/src/main.rs#L4, I see unsafe blocks labeled with SAFETY comments, which is great! However, the comments focus on why the unsafe block is required (eg. a specific FFI call or unsafe API method), rather than what preconditions ensure the unsafe code is actually safe in practice.

wmmc88 commented 1 week ago

Hi @jdm. Yes, I agree with your assessment of the safety comments currently present in the sample driver. We have much stricter enforcement for this on the windows-drivers-rs repo, and I wish to make improvements here in the samples.

That said, we are currently working on safer abstractions for the majority of the API surface covered in the current samples, so we will no longer need these unsafe blocks. Until then though, contributions are welcome 😊