-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usability improvements #119
Comments
Just checking - Is there no IoGetCurrentIrpStackLocation currently? Just checking as I'm looking for it in the docs and the repo but cant find it. If not - I may take a stab at implementing it myself as I'd love to contribute to this project! I also have a macro for CTL_CODE that I could contribute 🥳 |
I've had a stab at binding this - I couldn't get it to bind via FFI for some reason, so I went into the MSDN and had a look at the C implementation in the header file (wdm.h) and I have come up with: (note, this is also currently untested as of the time of writing) pub unsafe fn IoGetCurrentIrpStackLocation(irp: PIRP) -> PIO_STACK_LOCATION {
assert!((*irp).CurrentLocation <= (*irp).StackCount + 1); // todo maybe do error handling instead of an assert?
(*irp).Tail.Overlay.__bindgen_anon_2.__bindgen_anon_1.CurrentStackLocation
} I'm not sure if this is suitable for this project as it looks like mostly FFI bindings? If this is suitable for this project I would love to contribute it as my first addition, or to be advised on how it could be implemented using FFI; This function doesn't appear in the exports table of ntoskrnl.lib, so I assume that this project is looking (over time) to add implementations in Rust style for the wdk C header files? If this is something i could contribute, I'll fix up any safety of the above snippet (its just a POC thing), handle errors appropriately, and hopefully get my first pull request into this awesome project 🥳 |
I think this is suitable for this project, since there are already some wrappers around low-level unsafe primitives. For example: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/wdk/src/wdf/spinlock.rs. According to the |
As for asserts, to be honest, I'm not sure if As for whether to use |
@wmmc88 Hey! I'm not sure if this is something you are able to comment on? I'd love to be able to contribute something here :) |
Per https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/_kernel/,
Bindgen doesn't generate a binding to it because its an inline function. There is no symbol to link a bindgen-generated function to.
Since this should be a 1:1 port of what's in the header, this belongs in the
|
Thanks for the comment, so you dont want a contribution for IoGetCurrentIrpStackLocation as it relates to WDM? Are you only porting WDF APIs? |
But it looks like |
@wmmc88 If IoGetCurrentIrpStackLocation is for legacy drivers, it's given clearly in examples from Windows Kernel Programming 2nd Edition by Pavel Yosifovich, I'm guessing given that it is still to be used as part of IOCTL functions? If so, I would still like to contribute it ^^, as it seems relevant and from what I know, Pavel is considered a leader in terms of driver development books. Edit: Looking back, he does indicate that it is using a WDM project. |
Define the
CTL_CODE
macro and theIoGetCurrentIrpStackLocation
function.Move constants and macros (such as
FILE_DEVICE_UNKNOWN
,METHOD_BUFFERED
, and others) from this crate and windows-rs to a shared crate.Motivation: This enables the definition of IOCTL codes in a shared crate that can be linked to both the driver and application sides.
Change the types of some constants, like
IRP_MJ_*
tousize
, andIO_NO_INCREMENT
toCCHAR
. It would also be beneficial to defineTRUE
andFALSE
aspub const TRUE: BOOLEAN = 1;
andpub const FALSE: BOOLEAN = 0;
respectively, or even better, eliminate allBOOLEAN
types from the API and replace them with the plain Rust bool, although I understand that this might be nearly impossible.Motivation: To eliminate unnecessary type casting where it logically should not exist.
Do something with
__bindgen_anon_*
.Motivation: The statement
(*irp).IoStatus.__bindgen_anon_1.Status = status;
looks very awkward, and it's also challenging to locate the needed field in more complex cases like(*irp).Tail.Overlay.__bindgen_anon_2.__bindgen_anon_1.CurrentStackLocation
.In general, it would be beneficial if constants in
constants.rs
had types fromtypes.rs
.The text was updated successfully, but these errors were encountered: