Skip to content
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

Implement IoGetCurrentIrpStackLocation function in ntddk.rs #251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/wdk-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ macro_rules! PAGED_CODE {
debug_assert!(unsafe { KeGetCurrentIrql() <= APC_LEVEL as u8 });
};
}

#[cfg(any(driver_model__driver_type = "WDM", driver_model__driver_type = "KMDF"))]
pub use ntddk::IoGetCurrentIrpStackLocation;
31 changes: 31 additions & 0 deletions crates/wdk-sys/src/ntddk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! module, but are available in the top-level `wdk_sys` module.

pub use bindings::*;
use crate::{PIRP, PIO_STACK_LOCATION};

#[allow(missing_docs)]
mod bindings {
Expand All @@ -18,3 +19,33 @@ mod bindings {

include!(concat!(env!("OUT_DIR"), "/ntddk.rs"));
}

/// The IoGetCurrentIrpStackLocation routine returns a pointer to the caller's I/O stack location in
/// the specified IRP.
///
/// # Parameters
/// - irp: PIRP - A pointer to the IRP.
///
/// # Returns
/// IoGetCurrentIrpStackLocation returns a pointer to an IO_STACK_LOCATION structure that contains
/// the I/O stack location for the driver.
///
/// # Safety
/// This function directly accesses raw pointers and must only be used
/// when it is guaranteed that the provided `irp` is valid and properly
/// initialised. Using an invalid or uninitialised `irp` will result
/// in undefined behavior.
#[allow(non_snake_case)]
pub unsafe fn IoGetCurrentIrpStackLocation(irp: PIRP) -> PIO_STACK_LOCATION {
unsafe {
assert!((*irp).CurrentLocation <= (*irp).StackCount + 1);

// Access the union fields inside the IRP
(*irp)
.Tail
.Overlay
.__bindgen_anon_2
.__bindgen_anon_1
.CurrentStackLocation
}
}