microsoft / wdkmetadata

Tooling to generate metadata for Win32 APIs in the Windows Driver Kit (WDK).
Other
96 stars 10 forks source link

Invalid "optioning" of driver callbacks. #67

Closed HoShiMin closed 5 months ago

HoShiMin commented 6 months ago

Summary

All driver callback types looks like Option<unsafe extern "system"fn (...)>, but it is wrong as it makes impossible to use them properly.
Let's look on the DRIVER_OBJECT::MajorFunction:

pub struct DRIVER_OBJECT {
    ...
    pub MajorFunction: [*mut DRIVER_DISPATCH; 28],
}

It means that MajorFunction is array of pointers to Option that holds a pointer to the handler - so, it's a pointer to pointer! It should be something like that in such cases:

// Without `Option`:
type DRIVER_DISPATCH = extern "system" fn (...);

pub struct DRIVER_OBJECT {
    ...
    pub DriverUnload: Option<DRIVER_UNLOAD>,
    pub MajorFunction: [Option<DRIVER_DISPATCH>; 28]
}

Crate manifest

No response

Crate code

No response

kennykerr commented 6 months ago

I'm not familiar with this struct but it looks like a Win32 metadata issue. Will transfer for their consideration.