Skip to content

Commit b56de53

Browse files
Zero-Tangwmmc88leon-xdleon-xd
authored
Use stack-based formatter for debug-printing. (#233)
Signed-off-by: Leon Durrenberger <[email protected]> Co-authored-by: Melvin Wang <[email protected]> Co-authored-by: leon-xd <[email protected]> Co-authored-by: Leon Durrenberger <[email protected]>
1 parent 0ae8259 commit b56de53

File tree

21 files changed

+598
-87
lines changed

21 files changed

+598
-87
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wdk-build/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn read_registry_key_string_value(
344344
return Some(
345345
CStr::from_bytes_with_nul(&buffer[..len as usize])
346346
.expect(
347-
"RegGetValueA should always return a null terminated string. The read \
347+
"RegGetValueA should always return a null-terminated string. The read \
348348
string (REG_SZ) from the registry should not contain any interior \
349349
nulls.",
350350
)

crates/wdk-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static TEST_STUBS_TEMPLATE: LazyLock<String> = LazyLock::new(|| {
118118
r"
119119
use crate::WDFFUNC;
120120
121-
/// Stubbed version of the symbol that [`WdfFunctions`] links to so that test targets will compile
121+
/// Stubbed version of the symbol that `WdfFunctions` links to so that test targets will compile
122122
#[no_mangle]
123123
pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null();
124124
",

crates/wdk-sys/src/test_stubs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING};
2828
driver_model__driver_type = "UMDF"
2929
))]
3030
#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry
31-
pub unsafe extern "system" fn driver_entry_stub(
31+
pub const unsafe extern "system" fn driver_entry_stub(
3232
_driver: &mut DRIVER_OBJECT,
3333
_registry_path: PCUNICODE_STRING,
3434
) -> NTSTATUS {

crates/wdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] }
2222
wdk-build.workspace = true
2323

2424
[dependencies]
25+
cfg-if.workspace = true
2526
wdk-sys.workspace = true
2627

2728
[dev-dependencies]

crates/wdk/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
//! built on top of the raw FFI bindings provided by [`wdk-sys`], and provides a
66
//! safe, idiomatic rust interface to the WDK.
77
8-
#![no_std]
8+
#![cfg_attr(
9+
any(driver_model__driver_type = "WDM", driver_model__driver_type = "KMDF"),
10+
no_std
11+
)]
912

1013
#[cfg(any(
1114
all(

crates/wdk/src/print.rs

Lines changed: 505 additions & 15 deletions
Large diffs are not rendered by default.

examples/sample-kmdf-driver/Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/sample-kmdf-driver/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ extern crate alloc;
1313
#[cfg(not(test))]
1414
extern crate wdk_panic;
1515

16-
use alloc::{ffi::CString, slice, string::String};
16+
use alloc::{
17+
ffi::CString,
18+
slice,
19+
string::String,
20+
};
1721

1822
use wdk::println;
1923
#[cfg(not(test))]
@@ -56,9 +60,9 @@ pub unsafe extern "system" fn driver_entry(
5660
let string = CString::new("Hello World!\n").unwrap();
5761

5862
// SAFETY: This is safe because `string` is a valid pointer to a null-terminated
59-
// string
63+
// string (`CString` guarantees null-termination)
6064
unsafe {
61-
DbgPrint(string.as_ptr());
65+
DbgPrint(c"%s".as_ptr().cast(), string.as_ptr());
6266
}
6367

6468
driver.DriverUnload = Some(driver_exit);

examples/sample-umdf-driver/Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/sample-umdf-driver/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub unsafe extern "system" fn driver_entry(
4242
let string = CString::new("Hello World!\n").unwrap();
4343

4444
// SAFETY: This is safe because `string` is a valid pointer to a null-terminated
45-
// string
45+
// string (`CString` guarantees null-termination)
4646
unsafe {
4747
OutputDebugStringA(string.as_ptr());
4848
}

examples/sample-wdm-driver/Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/sample-wdm-driver/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ pub unsafe extern "system" fn driver_entry(
3737
) -> NTSTATUS {
3838
// This is an example of directly using DbgPrint binding to print
3939
let string = CString::new("Hello World!\n").unwrap();
40+
41+
// SAFETY: This is safe because `string` is a valid pointer to a null-terminated
42+
// string (`CString` guarantees null-termination)
4043
unsafe {
41-
DbgPrint(string.as_ptr());
44+
DbgPrint(c"%s".as_ptr().cast(), string.as_ptr());
4245
}
4346

4447
driver.DriverUnload = Some(driver_exit);

tests/config-kmdf/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/config-umdf/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)