Skip to content

Commit

Permalink
remove [()] hack
Browse files Browse the repository at this point in the history
  • Loading branch information
wmmc88 committed Oct 3, 2024
1 parent 2a46e8e commit e810a00
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 55 deletions.
15 changes: 6 additions & 9 deletions general/echo/kmdf/driver/DriverSync/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {

// Register the PnP and power callbacks. Power policy related callbacks will be
// registered later in SotwareInit.
let [()] = [unsafe {
unsafe {
call_unsafe_wdf_function_binding!(
WdfDeviceInitSetPnpPowerEventCallbacks,
device_init,
&mut pnp_power_callbacks
);
}];
};

let mut attributes = WDF_OBJECT_ATTRIBUTES {
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
Expand All @@ -75,13 +75,13 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
..WDF_OBJECT_ATTRIBUTES::default()
};

let [()] = [unsafe {
unsafe {
call_unsafe_wdf_function_binding!(
WdfDeviceInitSetRequestAttributes,
device_init,
&mut attributes
);
}];
};

let mut attributes = WDF_OBJECT_ATTRIBUTES {
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
Expand Down Expand Up @@ -161,7 +161,7 @@ extern "C" fn echo_evt_device_self_managed_io_start(device: WDFDEVICE) -> NTSTAT

// Restart the queue and the periodic timer. We stopped them before going
// into low power state.
let [()] = [unsafe { call_unsafe_wdf_function_binding!(WdfIoQueueStart, queue) }];
unsafe { call_unsafe_wdf_function_binding!(WdfIoQueueStart, queue) };

let due_time: i64 = -(100) * (10000);

Expand Down Expand Up @@ -203,10 +203,7 @@ unsafe extern "C" fn echo_evt_device_self_managed_io_suspend(device: WDFDEVICE)
let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) };

unsafe {
let [()] = [call_unsafe_wdf_function_binding!(
WdfIoQueueStopSynchronously,
queue
)];
call_unsafe_wdf_function_binding!(WdfIoQueueStopSynchronously, queue);
// Stop the watchdog timer and wait for DPC to run to completion if it's already
// fired.
let _ = (*queue_context).timer.stop(true);
Expand Down
27 changes: 22 additions & 5 deletions general/echo/kmdf/driver/DriverSync/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@

use wdk::{nt_success, paged_code, println};
use wdk_sys::{
call_unsafe_wdf_function_binding, ntddk::KeGetCurrentIrql, APC_LEVEL, DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, PWDFDEVICE_INIT, STATUS_SUCCESS, ULONG, UNICODE_STRING, WDFDRIVER, WDFOBJECT, WDFSTRING, WDF_DRIVER_CONFIG, WDF_DRIVER_VERSION_AVAILABLE_PARAMS, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES
call_unsafe_wdf_function_binding,
ntddk::KeGetCurrentIrql,
APC_LEVEL,
DRIVER_OBJECT,
NTSTATUS,
PCUNICODE_STRING,
PDRIVER_OBJECT,
PWDFDEVICE_INIT,
STATUS_SUCCESS,
ULONG,
UNICODE_STRING,
WDFDRIVER,
WDFOBJECT,
WDFSTRING,
WDF_DRIVER_CONFIG,
WDF_DRIVER_VERSION_AVAILABLE_PARAMS,
WDF_NO_HANDLE,
WDF_NO_OBJECT_ATTRIBUTES,
};

use crate::device;
Expand Down Expand Up @@ -136,9 +153,9 @@ fn echo_print_driver_version() -> NTSTATUS {
return nt_status;
}

let [()] = [unsafe {
unsafe {
call_unsafe_wdf_function_binding!(WdfStringGetUnicodeString, string, &mut us);
}];
};
let driver_version = String::from_utf16_lossy(unsafe {
slice::from_raw_parts(
us.Buffer,
Expand All @@ -147,9 +164,9 @@ fn echo_print_driver_version() -> NTSTATUS {
});
println!("Echo Sample {driver_version}");

let [()] = [unsafe {
unsafe {
call_unsafe_wdf_function_binding!(WdfObjectDelete, string as WDFOBJECT);
}];
};
// string = core::ptr::null_mut();

// 2) Find out to which version of framework this driver is bound to.
Expand Down
62 changes: 21 additions & 41 deletions general/echo/kmdf/driver/DriverSync/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ extern "C" fn echo_evt_request_cancel(request: WDFREQUEST) {

// Complete the request outside of holding any locks
if complete_request {
let [()] = [unsafe {
unsafe {
call_unsafe_wdf_function_binding!(
WdfRequestCompleteWithInformation,
request,
STATUS_CANCELLED,
0
);
}];
}
}
}

Expand Down Expand Up @@ -386,12 +386,12 @@ fn echo_set_current_request(request: WDFREQUEST, queue: WDFQUEUE) {
unsafe {
// Complete the request with an error when unable to mark it cancelable.
if !nt_success(status) {
let [()] = [call_unsafe_wdf_function_binding!(
call_unsafe_wdf_function_binding!(
WdfRequestCompleteWithInformation,
request,
status,
0
)];
);
}
}
}
Expand Down Expand Up @@ -427,12 +427,12 @@ extern "C" fn echo_evt_io_read(queue: WDFQUEUE, request: WDFREQUEST, mut length:
// No data to read
unsafe {
if (*queue_context).buffer.is_null() {
let [()] = [call_unsafe_wdf_function_binding!(
call_unsafe_wdf_function_binding!(
WdfRequestCompleteWithInformation,
request,
STATUS_SUCCESS,
0,
)];
);
return;
}
}
Expand All @@ -451,12 +451,12 @@ extern "C" fn echo_evt_io_read(queue: WDFQUEUE, request: WDFREQUEST, mut length:

if !nt_success(nt_status) {
println!("echo_evt_io_read Could not get request memory buffer {nt_status:#010X}");
let [()] = [call_unsafe_wdf_function_binding!(
call_unsafe_wdf_function_binding!(
WdfRequestCompleteWithInformation,
request,
nt_status,
0
)];
);
return;
}
}
Expand All @@ -473,11 +473,7 @@ extern "C" fn echo_evt_io_read(queue: WDFQUEUE, request: WDFREQUEST, mut length:

if !nt_success(nt_status) {
println!("echo_evt_io_read: WdfMemoryCopyFromBuffer failed {nt_status:#010X}");
let [()] = [call_unsafe_wdf_function_binding!(
WdfRequestComplete,
request,
nt_status
)];
call_unsafe_wdf_function_binding!(WdfRequestComplete, request, nt_status);
return;
}
}
Expand Down Expand Up @@ -528,18 +524,18 @@ extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: us
);

if length > MAX_WRITE_LENGTH {
let [()] = [unsafe {
println!(
"echo_evt_io_write Buffer Length to big {:?}, Max is {:?}",
length, MAX_WRITE_LENGTH
);
println!(
"echo_evt_io_write Buffer Length to big {:?}, Max is {:?}",
length, MAX_WRITE_LENGTH
);
unsafe {
call_unsafe_wdf_function_binding!(
WdfRequestCompleteWithInformation,
request,
STATUS_BUFFER_OVERFLOW,
0
);
}];
}
}

// Get the memory buffer
Expand All @@ -548,11 +544,7 @@ extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: us
call_unsafe_wdf_function_binding!(WdfRequestRetrieveInputMemory, request, &mut memory);
if !nt_success(status) {
println!("echo_evt_io_write Could not get request memory buffer {status:#010X}");
let [()] = [call_unsafe_wdf_function_binding!(
WdfRequestComplete,
request,
status
)];
call_unsafe_wdf_function_binding!(WdfRequestComplete, request, status);
return;
}
}
Expand All @@ -573,11 +565,11 @@ extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: us
"echo_evt_io_write Could not allocate {:?} byte buffer",
length
);
let [()] = [call_unsafe_wdf_function_binding!(
call_unsafe_wdf_function_binding!(
WdfRequestComplete,
request,
STATUS_INSUFFICIENT_RESOURCES
)];
);
return;
}
}
Expand All @@ -597,11 +589,7 @@ extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: us
ExFreePool((*queue_context).buffer);
(*queue_context).buffer = core::ptr::null_mut();
(*queue_context).length = 0;
let [()] = [call_unsafe_wdf_function_binding!(
WdfRequestComplete,
request,
status
)];
call_unsafe_wdf_function_binding!(WdfRequestComplete, request, status);
return;
}

Expand All @@ -610,11 +598,7 @@ extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: us

// Set transfer information
unsafe {
let [()] = [call_unsafe_wdf_function_binding!(
WdfRequestSetInformation,
request,
length as u64
)];
call_unsafe_wdf_function_binding!(WdfRequestSetInformation, request, length as u64);
}

// Mark the request is cancelable. This must be the last thing we do because
Expand Down Expand Up @@ -732,11 +716,7 @@ unsafe extern "C" fn echo_evt_timer_func(timer: WDFTIMER) {
unsafe { (*queue_context).spin_lock.release() };

unsafe {
let [()] = [call_unsafe_wdf_function_binding!(
WdfRequestComplete,
request,
status
)];
call_unsafe_wdf_function_binding!(WdfRequestComplete, request, status);
}
}
}

0 comments on commit e810a00

Please sign in to comment.