[windows_kext] Update windows-rs

This commit is contained in:
Vladimir Stoilov 2024-06-28 16:06:30 +03:00
parent 2d9d433945
commit 81bee82b8f
12 changed files with 92 additions and 83 deletions

View file

@ -340,19 +340,20 @@ checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
@ -361,38 +362,43 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "zerocopy"

View file

@ -22,5 +22,5 @@ hashbrown = { version = "0.14.3", default-features = false, features = ["ahash"]
# WARNING: Do not update. The version was choosen for a reason. See wdk/README.md for more detiels.
[dependencies.windows-sys]
git = "https://github.com/microsoft/windows-rs"
rev = "41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
rev = "dffa8b03dc4987c278d82e88015ffe96aa8ac317"
features = ["Wdk_Foundation", "Wdk_Storage_FileSystem", "Wdk_System_SystemServices", "Win32_Foundation", "Win32_Security", "Win32_System_IO", "Win32_System_Kernel", "Win32_System_Power", "Win32_System_WindowsProgramming", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock", "Win32_NetworkManagement_WindowsFilteringPlatform"]

View file

@ -38,10 +38,10 @@ pub extern "system" fn driver_entry(
};
// Set driver functions.
driver.set_driver_unload(driver_unload);
driver.set_read_fn(driver_read);
driver.set_write_fn(driver_write);
driver.set_device_control_fn(device_control);
driver.set_driver_unload(Some(driver_unload));
driver.set_read_fn(Some(driver_read));
driver.set_write_fn(Some(driver_write));
driver.set_device_control_fn(Some(device_control));
// Initialize device.
unsafe {
@ -70,10 +70,10 @@ unsafe extern "system" fn driver_unload(_object: *const DRIVER_OBJECT) {
// driver_read event triggered from user-space on file.Read.
unsafe extern "system" fn driver_read(
_device_object: &mut DEVICE_OBJECT,
irp: &mut IRP,
_device_object: *const DEVICE_OBJECT,
irp: *mut IRP,
) -> NTSTATUS {
let mut read_request = ReadRequest::new(irp);
let mut read_request = ReadRequest::new(irp.as_mut().unwrap());
let Some(device) = get_device() else {
read_request.complete();
@ -86,10 +86,10 @@ unsafe extern "system" fn driver_read(
/// driver_write event triggered from user-space on file.Write.
unsafe extern "system" fn driver_write(
_device_object: &mut DEVICE_OBJECT,
irp: &mut IRP,
_device_object: *const DEVICE_OBJECT,
irp: *mut IRP,
) -> NTSTATUS {
let mut write_request = WriteRequest::new(irp);
let mut write_request = WriteRequest::new(irp.as_mut().unwrap());
let Some(device) = get_device() else {
write_request.complete();
return write_request.get_status();
@ -104,10 +104,10 @@ unsafe extern "system" fn driver_write(
/// device_control event triggered from user-space on file.deviceIOControl.
unsafe extern "system" fn device_control(
_device_object: &mut DEVICE_OBJECT,
irp: &mut IRP,
_device_object: *const DEVICE_OBJECT,
irp: *mut IRP,
) -> NTSTATUS {
let mut control_request = DeviceControlRequest::new(irp);
let mut control_request = DeviceControlRequest::new(irp.as_mut().unwrap());
let Some(device) = get_device() else {
control_request.complete();
return control_request.get_status();

View file

@ -84,19 +84,20 @@ checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
@ -105,35 +106,40 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "git+https://github.com/microsoft/windows-rs?rev=41ad38d8c42c92fd23fe25ba4dca76c2d861ca06#41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
version = "0.52.5"
source = "git+https://github.com/microsoft/windows-rs?rev=dffa8b03dc4987c278d82e88015ffe96aa8ac317#dffa8b03dc4987c278d82e88015ffe96aa8ac317"

View file

@ -16,5 +16,5 @@ features = ["alloc"]
# WARNING: Do not update. The version was choosen for a reason. See wdk/README.md for more detiels.
[dependencies.windows-sys]
git = "https://github.com/microsoft/windows-rs"
rev = "41ad38d8c42c92fd23fe25ba4dca76c2d861ca06"
rev = "dffa8b03dc4987c278d82e88015ffe96aa8ac317"
features = ["Wdk_Foundation", "Wdk_Storage_FileSystem", "Wdk_System_SystemServices", "Win32_Foundation", "Win32_Security", "Win32_System_IO", "Win32_System_Kernel", "Win32_System_Power", "Win32_System_WindowsProgramming", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock", "Win32_NetworkManagement_WindowsFilteringPlatform", "Win32_System_Rpc"]

View file

@ -10,5 +10,7 @@ see: `wdk/src/driver.rs`
see: `wdk/src/irp_helper.rs`
Open issues need to be resolved:
https://github.com/microsoft/wdkmetadata/issues/59
https://github.com/microsoft/windows-rs/issues/2805
Resolved:
https://github.com/microsoft/wdkmetadata/issues/59

View file

@ -1,6 +1,6 @@
use windows_sys::{
Wdk::Foundation::{DEVICE_OBJECT, DRIVER_OBJECT, IRP},
Win32::Foundation::{HANDLE, NTSTATUS},
Wdk::Foundation::{DEVICE_OBJECT, DRIVER_DISPATCH, DRIVER_OBJECT, DRIVER_UNLOAD},
Win32::Foundation::HANDLE,
};
use crate::{
@ -23,11 +23,6 @@ pub struct Driver {
}
unsafe impl Sync for Driver {}
// This is a workaround for current state of wdk bindings.
// TODO: replace with official version when they are correct: https://github.com/microsoft/wdkmetadata/issues/59
pub type UnloadFnType = unsafe extern "system" fn(driver_object: *const DRIVER_OBJECT);
pub type MjFnType = unsafe extern "system" fn(&mut DEVICE_OBJECT, &mut IRP) -> NTSTATUS;
impl Driver {
pub(crate) fn new(
driver_object: *mut DRIVER_OBJECT,
@ -50,54 +45,54 @@ impl Driver {
return unsafe { self.device_object.as_mut() };
}
pub fn set_driver_unload(&mut self, driver_unload: UnloadFnType) {
pub fn set_driver_unload(&mut self, driver_unload: DRIVER_UNLOAD) {
if let Some(driver) = unsafe { self.driver_object.as_mut() } {
driver.DriverUnload = Some(unsafe { core::mem::transmute(driver_unload) })
driver.DriverUnload = driver_unload
}
}
pub fn set_read_fn(&mut self, mj_fn: MjFnType) {
pub fn set_read_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(windows_sys::Wdk::System::SystemServices::IRP_MJ_READ, mj_fn);
}
pub fn set_write_fn(&mut self, mj_fn: MjFnType) {
pub fn set_write_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_WRITE,
mj_fn,
);
}
pub fn set_create_fn(&mut self, mj_fn: MjFnType) {
pub fn set_create_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_CREATE,
mj_fn,
);
}
pub fn set_device_control_fn(&mut self, mj_fn: MjFnType) {
pub fn set_device_control_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_DEVICE_CONTROL,
mj_fn,
);
}
pub fn set_close_fn(&mut self, mj_fn: MjFnType) {
pub fn set_close_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_CLOSE,
mj_fn,
);
}
pub fn set_cleanup_fn(&mut self, mj_fn: MjFnType) {
pub fn set_cleanup_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_CLEANUP,
mj_fn,
);
}
fn set_major_fn(&mut self, fn_index: u32, mj_fn: MjFnType) {
fn set_major_fn(&mut self, fn_index: u32, mj_fn: DRIVER_DISPATCH) {
if let Some(driver) = unsafe { self.driver_object.as_mut() } {
driver.MajorFunction[fn_index as usize] = Some(unsafe { core::mem::transmute(mj_fn) })
driver.MajorFunction[fn_index as usize] = mj_fn
}
}
}

View file

@ -270,7 +270,7 @@ impl WdfObjectAttributes {
evt_destroy_callback: None,
execution_level: WdfExecutionLevel::InheritFromParent,
synchronization_scope: WdfSynchronizationScope::InheritFromParent,
parent_object: 0,
parent_object: core::ptr::null_mut(),
context_size_override: 0,
context_type_info: core::ptr::null(),
}

View file

@ -1,7 +1,7 @@
use super::{callout_data::CalloutData, ffi, layer::Layer};
use crate::ffi::FwpsCalloutClassifyFn;
use alloc::{borrow::ToOwned, format, string::String};
use windows_sys::Wdk::Foundation::DEVICE_OBJECT;
use windows_sys::{Wdk::Foundation::DEVICE_OBJECT, Win32::Foundation::HANDLE};
pub enum FilterType {
Resettable,
@ -49,13 +49,13 @@ impl Callout {
pub fn register_filter(
&mut self,
filter_engine_handle: isize,
filter_engine_handle: HANDLE,
sublayer_guid: u128,
) -> Result<(), String> {
match ffi::register_filter(
filter_engine_handle,
sublayer_guid,
&format!("{}-filter", self.name),
&self.name,
&self.description,
self.guid,
self.layer,
@ -75,14 +75,14 @@ impl Callout {
pub(crate) fn register_callout(
&mut self,
filter_engine_handle: isize,
filter_engine_handle: HANDLE,
device_object: *mut DEVICE_OBJECT,
callout_fn: FwpsCalloutClassifyFn,
) -> Result<(), String> {
match ffi::register_callout(
device_object,
filter_engine_handle,
&format!("{}-callout", self.name),
&self.name,
&self.description,
self.guid,
self.layer,

View file

@ -140,7 +140,7 @@ impl<'a> CalloutData<'a> {
packet_list: Option<TransportPacketList>,
) -> Result<ClassifyDefer, String> {
unsafe {
let mut completion_context = 0;
let mut completion_context: HANDLE = core::ptr::null_mut();
if let Some(completion_handle) = (*self.metadata).get_completion_handle() {
let status = FwpsPendOperation0(completion_handle, &mut completion_context);
check_ntstatus(status)?;

View file

@ -192,7 +192,7 @@ impl Drop for FilterEngine {
}
}
if self.handle != 0 && self.handle != INVALID_HANDLE_VALUE {
if !self.handle.is_null() && self.handle != INVALID_HANDLE_VALUE {
_ = ffi::filter_engine_close(self.handle);
}
}

View file

@ -163,7 +163,7 @@ impl Injector {
let status = if packet_list.inbound {
FwpsInjectTransportReceiveAsync0(
self.transport_inject_handle,
0,
core::ptr::null_mut(),
core::ptr::null_mut(),
0,
address_family,
@ -177,7 +177,7 @@ impl Injector {
} else {
FwpsInjectTransportSendAsync1(
self.transport_inject_handle,
0,
core::ptr::null_mut(),
packet_list.endpoint_handle,
0,
&mut send_params,
@ -222,7 +222,7 @@ impl Injector {
unsafe {
FwpsInjectNetworkReceiveAsync0(
inject_handle,
0,
core::ptr::null_mut(),
0,
UNSPECIFIED_COMPARTMENT_ID,
inject_info.interface_index,
@ -237,7 +237,7 @@ impl Injector {
unsafe {
FwpsInjectNetworkSendAsync0(
inject_handle,
0,
core::ptr::null_mut(),
0,
UNSPECIFIED_COMPARTMENT_ID,
nbl,
@ -269,7 +269,7 @@ impl Injector {
} else {
self.packet_inject_handle_v4
};
if inject_handle == INVALID_HANDLE_VALUE || inject_handle == 0 {
if inject_handle == INVALID_HANDLE_VALUE || inject_handle.is_null() {
return false;
}
@ -309,19 +309,19 @@ impl Drop for Injector {
fn drop(&mut self) {
unsafe {
if self.transport_inject_handle != INVALID_HANDLE_VALUE
&& self.transport_inject_handle != 0
&& !self.transport_inject_handle.is_null()
{
FwpsInjectionHandleDestroy0(self.transport_inject_handle);
self.transport_inject_handle = INVALID_HANDLE_VALUE;
}
if self.packet_inject_handle_v4 != INVALID_HANDLE_VALUE
&& self.packet_inject_handle_v4 != 0
&& !self.packet_inject_handle_v4.is_null()
{
FwpsInjectionHandleDestroy0(self.packet_inject_handle_v4);
self.packet_inject_handle_v4 = INVALID_HANDLE_VALUE;
}
if self.packet_inject_handle_v6 != INVALID_HANDLE_VALUE
&& self.packet_inject_handle_v6 != 0
&& !self.packet_inject_handle_v6.is_null()
{
FwpsInjectionHandleDestroy0(self.packet_inject_handle_v6);
self.packet_inject_handle_v6 = INVALID_HANDLE_VALUE;