Skip to content

Commit

Permalink
passsed all pipeline checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Durrenberger committed Dec 12, 2024
1 parent b49a18f commit a8280a3
Show file tree
Hide file tree
Showing 40 changed files with 139 additions and 118 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ cfg-if = "1.0.0"
clap = "4.5.9"
clap-cargo = "0.14.1"
itertools = "0.13.0"
once_cell = { version = "1.20.2", default-features = false, features = [
"alloc",
] }
paste = "1.0.15"
pretty_assertions = "1.4.0"
proc-macro2 = "1.0.86"
Expand Down
11 changes: 6 additions & 5 deletions crates/wdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ impl DerivedASTFragments {
// function table index and the correct function pointer type.
unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;

let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();

// SAFETY: This is safe because:
// 1. `WdfFunctions` is valid for reads for `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::<WDFFUNC>()`
// bytes, and is guaranteed to be aligned and it must be properly aligned.
Expand All @@ -239,10 +240,10 @@ impl DerivedASTFragments {
// 3. WDF does not mutate the memory referenced by the returned slice for for its entire `'static' lifetime.
// 4. The total size, `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::<WDFFUNC>()`, of the slice must be no
// larger than `isize::MAX`. This is proven by the below `const_assert!`.
debug_assert!(isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT * core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok());
let wdf_function_table = core::slice::from_raw_parts(wdf_function_table, wdk_sys::wdf::WDF_FUNCTION_COUNT);

debug_assert!(isize::try_from(wdf_function_count * core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok());
let wdf_function_table = core::slice::from_raw_parts(wdf_function_table, wdf_function_count);

core::mem::transmute(
// FIXME: investigate why _WDFFUNCENUM does not have a generated type alias without the underscore prefix
wdf_function_table[wdk_sys::_WDFFUNCENUM::#function_table_index as usize],
Expand Down
5 changes: 0 additions & 5 deletions crates/wdk-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ anyhow.workspace = true
bindgen.workspace = true
cargo_metadata.workspace = true
cc.workspace = true
once_cell.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
wdk-build.workspace = true

[dependencies]
once_cell.workspace = true
rustversion.workspace = true
wdk-macros.workspace = true

Expand Down Expand Up @@ -72,6 +70,3 @@ missing_crate_level_docs = "warn"
private_intra_doc_links = "warn"
redundant_explicit_links = "warn"
unescaped_backticks = "warn"

[package.metadata.cargo-machete]
ignored = ["once_cell"]
36 changes: 23 additions & 13 deletions crates/wdk-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ const OUT_DIR_PLACEHOLDER: &str =
"<PLACEHOLDER FOR LITERAL VALUE CONTAINING OUT_DIR OF wdk-sys CRATE>";
const WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER: &str =
"<PLACEHOLDER FOR LITERAL VALUE CONTAINING WDFFUNCTIONS SYMBOL NAME>";
const WDF_FUNCTION_COUNT_PLACEHOLDER: &str =
"<PLACEHOLDER FOR EVALUATION CONTAINING WDF_FUNCTION_COUNT VALUE";

const WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL: &str = "
// SAFETY: `crate::WdfFunctionCount` is generated as a mutable static, but is not supposed \
to be ever mutated by WDF.
/// Number of functions in the WDF function table
pub static WDF_FUNCTION_COUNT: usize = unsafe { crate::WdfFunctionCount } as usize;";
const WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL: &str =
"(unsafe { crate::WdfFunctionCount }) as usize";

const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = "
/// Number of functions in the WDF function table
pub static WDF_FUNCTION_COUNT: usize = crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize;";
const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str =
"crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize";

const WDF_FUNCTION_COUNT_FUNCTION_TEMPLATE: LazyLock<String> = LazyLock::new(|| {
format!(
r#"/// function to access the value of the number of functions in the WDF function table.
pub fn get_wdf_function_count() -> usize {{
{WDF_FUNCTION_COUNT_PLACEHOLDER}
}}"#
)
});

static CALL_UNSAFE_WDF_BINDING_TEMPLATE: LazyLock<String> = LazyLock::new(|| {
format!(
Expand Down Expand Up @@ -277,11 +284,14 @@ fn generate_wdf_function_table(out_path: &Path, config: &Config) -> std::io::Res
}
};

let wdf_function_table_count_snippet = if is_wdf_function_count_generated {
WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL
} else {
WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX
};
let wdf_function_table_count_snippet = WDF_FUNCTION_COUNT_FUNCTION_TEMPLATE.replace(
WDF_FUNCTION_COUNT_PLACEHOLDER,
if is_wdf_function_count_generated {
WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL
} else {
WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX
},
);

generated_file.write_all(wdf_function_table_count_snippet.as_bytes())?;
Ok(())
Expand Down
1 change: 0 additions & 1 deletion crates/wdk-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![no_std]


#[cfg(any(
driver_model__driver_type = "WDM",
driver_model__driver_type = "KMDF",
Expand Down
2 changes: 1 addition & 1 deletion crates/wdk-sys/src/wdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ mod bindings {
include!(concat!(env!("OUT_DIR"), "/wdf.rs"));
}

include!(concat!(env!("OUT_DIR"), "/wdf_function_table.rs"));
include!(concat!(env!("OUT_DIR"), "/wdf_function_count.rs"));
1 change: 0 additions & 1 deletion examples/sample-kmdf-driver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/sample-umdf-driver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/sample-wdm-driver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/config-kmdf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/config-umdf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/mixed-package-kmdf-workspace/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/umdf-driver-workspace/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions tests/wdk-macros-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// License: MIT OR Apache-2.0

use std::{path::PathBuf, sync::LazyLock};

use fs4::FileExt;
pub use macrotest::{expand, expand_args};
pub use owo_colors::OwoColorize;
Expand All @@ -17,17 +18,20 @@ const TOOLCHAIN_CHANNEL_NAME: &str = "beta";
#[rustversion::nightly]
const TOOLCHAIN_CHANNEL_NAME: &str = "nightly";

static TESTS_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| {[env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect()});
static INPUTS_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| {TESTS_FOLDER_PATH.join("inputs")});
pub static MACROTEST_INPUT_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| {INPUTS_FOLDER_PATH.join("macrotest")});
pub static TRYBUILD_INPUT_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| {INPUTS_FOLDER_PATH.join("trybuild")});
static OUTPUTS_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| {TESTS_FOLDER_PATH.join("outputs")});
static TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| {OUTPUTS_FOLDER_PATH.join(TOOLCHAIN_CHANNEL_NAME)});
static TESTS_FOLDER_PATH: LazyLock<PathBuf> =
LazyLock::new(|| [env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect());
static INPUTS_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| TESTS_FOLDER_PATH.join("inputs"));
pub static MACROTEST_INPUT_FOLDER_PATH: LazyLock<PathBuf> =
LazyLock::new(|| INPUTS_FOLDER_PATH.join("macrotest"));
pub static TRYBUILD_INPUT_FOLDER_PATH: LazyLock<PathBuf> =
LazyLock::new(|| INPUTS_FOLDER_PATH.join("trybuild"));
static OUTPUTS_FOLDER_PATH: LazyLock<PathBuf> = LazyLock::new(|| TESTS_FOLDER_PATH.join("outputs"));
static TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH: LazyLock<PathBuf> =
LazyLock::new(|| OUTPUTS_FOLDER_PATH.join(TOOLCHAIN_CHANNEL_NAME));
pub static MACROTEST_OUTPUT_FOLDER_PATH: LazyLock<PathBuf> =
LazyLock::new(|| {TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("macrotest")});
LazyLock::new(|| TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("macrotest"));
pub static TRYBUILD_OUTPUT_FOLDER_PATH: LazyLock<PathBuf> =
LazyLock::new(|| {TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("trybuild")});

LazyLock::new(|| TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("trybuild"));

/// Given a filename `f` which contains code utilizing
/// [`wdk_sys::call_unsafe_wdf_function_binding`], generates a pair of tests to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ fn foo(
) {
let wdf_function: wdk_sys::PFN_WDFDEVICEINITSETPNPPOWEREVENTCALLBACKS = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
if !isize::try_from(
wdk_sys::wdf::WDF_FUNCTION_COUNT
wdf_function_count
* core::mem::size_of::<wdk_sys::WDFFUNC>(),
)
.is_ok()
{
::core::panicking::panic(
"assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
"assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
)
}
}
let wdf_function_table = core::slice::from_raw_parts(
wdf_function_table,
wdk_sys::wdf::WDF_FUNCTION_COUNT,
wdf_function_count,
);
core::mem::transmute(
wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ pub extern "system" fn driver_entry(
) -> NTSTATUS {
let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
if !isize::try_from(
wdk_sys::wdf::WDF_FUNCTION_COUNT
wdf_function_count
* core::mem::size_of::<wdk_sys::WDFFUNC>(),
)
.is_ok()
{
::core::panicking::panic(
"assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
"assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
)
}
}
let wdf_function_table = core::slice::from_raw_parts(
wdf_function_table,
wdk_sys::wdf::WDF_FUNCTION_COUNT,
wdf_function_count,
);
core::mem::transmute(
wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ extern "C" fn evt_driver_device_add(
) -> NTSTATUS {
let wdf_function: wdk_sys::PFN_WDFDEVICECREATE = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
if !isize::try_from(
wdk_sys::wdf::WDF_FUNCTION_COUNT
wdf_function_count
* core::mem::size_of::<wdk_sys::WDFFUNC>(),
)
.is_ok()
{
::core::panicking::panic(
"assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
"assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
)
}
}
let wdf_function_table = core::slice::from_raw_parts(
wdf_function_table,
wdk_sys::wdf::WDF_FUNCTION_COUNT,
wdf_function_count,
);
core::mem::transmute(
wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS
) -> NTSTATUS {
let wdf_function: wdk_sys::PFN_WDFDEVICECREATEDEVICEINTERFACE = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
if !isize::try_from(
wdk_sys::wdf::WDF_FUNCTION_COUNT
wdf_function_count
* core::mem::size_of::<wdk_sys::WDFFUNC>(),
)
.is_ok()
{
::core::panicking::panic(
"assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
"assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
)
}
}
let wdf_function_table = core::slice::from_raw_parts(
wdf_function_table,
wdk_sys::wdf::WDF_FUNCTION_COUNT,
wdf_function_count,
);
core::mem::transmute(
wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ pub extern "system" fn driver_entry(
) -> NTSTATUS {
let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
if !isize::try_from(
wdk_sys::wdf::WDF_FUNCTION_COUNT
wdf_function_count
* core::mem::size_of::<wdk_sys::WDFFUNC>(),
)
.is_ok()
{
::core::panicking::panic(
"assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
"assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
)
}
}
let wdf_function_table = core::slice::from_raw_parts(
wdf_function_table,
wdk_sys::wdf::WDF_FUNCTION_COUNT,
wdf_function_count,
);
core::mem::transmute(
wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) {
) -> NTSTATUS {
let wdf_function: wdk_sys::PFN_WDFREQUESTRETRIEVEOUTPUTBUFFER = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
if !isize::try_from(
wdk_sys::wdf::WDF_FUNCTION_COUNT
wdf_function_count
* core::mem::size_of::<wdk_sys::WDFFUNC>(),
)
.is_ok()
{
::core::panicking::panic(
"assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
"assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()",
)
}
}
let wdf_function_table = core::slice::from_raw_parts(
wdf_function_table,
wdk_sys::wdf::WDF_FUNCTION_COUNT,
wdf_function_count,
);
core::mem::transmute(
wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex
Expand Down
Loading

0 comments on commit a8280a3

Please sign in to comment.