microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.13k stars 473 forks source link

Incorrect definition for PDRIVER_UNLOAD routine #3087

Closed AndreiMuntea closed 1 month ago

AndreiMuntea commented 1 month ago

Summary

Hi! I noticed that in windows_sys::Wdk::Foundation crate

PDRIVER_UNLOAD is defined as

pub type PDRIVER_UNLOAD = ::core::option::Option<unsafe extern "system" fn() -> ()>;

but the correct C definition would be:

void DriverUnload(
  [in] _DRIVER_OBJECT *DriverObject
)

Note the missing DriverObject parameter. See docs at: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nc-wdm-driver_unload

Currently I'm working around the issue like:


    unsafe { driver_object.DriverUnload = Some( ::core::mem::transmute::<unsafe extern "system" fn(*mut DRIVER_OBJECT),
                                                                         unsafe extern "system" fn()>(DriverUnload)); }

Crate manifest

No response

Crate code

No response

kennykerr commented 1 month ago

Looks like this has since been fixed:

pub type DRIVER_UNLOAD = Option<unsafe extern "system" fn(driverobject: *const DRIVER_OBJECT)>;

Which version of the windows-sys crate are you using? The fix may not yet have been included in a release on crates.io but you can test it directly against the repo as follows:

https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories