From ab36865e4f9f4e0ec7f4631845d9d8be45af1dce Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Tue, 19 Nov 2024 12:33:18 -0800 Subject: [PATCH 01/12] temp commit, moving between devices --- Cargo.lock | 11 ---- Cargo.toml | 1 - crates/wdk-alloc/src/lib.rs | 4 +- crates/wdk-build/Cargo.toml | 1 - crates/wdk-build/src/cargo_make.rs | 8 +-- crates/wdk-build/src/lib.rs | 12 ++-- crates/wdk-build/src/utils.rs | 12 +--- crates/wdk-macros/src/lib.rs | 30 ++-------- crates/wdk-sys/Cargo.toml | 3 - crates/wdk-sys/build.rs | 60 +++++++++---------- crates/wdk/src/wdf/timer.rs | 6 +- examples/sample-kmdf-driver/Cargo.lock | 11 ---- examples/sample-umdf-driver/Cargo.lock | 11 ---- examples/sample-wdm-driver/Cargo.lock | 11 ---- tests/config-kmdf/Cargo.lock | 12 ---- tests/config-umdf/Cargo.lock | 12 ---- tests/mixed-package-kmdf-workspace/Cargo.lock | 11 ---- tests/umdf-driver-workspace/Cargo.lock | 11 ---- tests/wdk-macros-tests/Cargo.lock | 7 --- tests/wdk-macros-tests/Cargo.toml | 1 - tests/wdk-macros-tests/src/lib.rs | 27 ++++----- tests/wdk-sys-tests/Cargo.lock | 11 ---- 22 files changed, 55 insertions(+), 218 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d521a67..7c2804a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -293,9 +293,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -571,12 +568,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -734,7 +725,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -767,7 +757,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 8254e142..440a11d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,6 @@ cfg-if = "1.0.0" clap = "4.5.9" clap-cargo = "0.14.1" itertools = "0.13.0" -lazy_static = "1.5.0" paste = "1.0.15" pretty_assertions = "1.4.0" proc-macro2 = "1.0.86" diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 1a8b7282..3812d8fc 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -32,9 +32,7 @@ mod kernel_mode { use wdk_sys::{ ntddk::{ExAllocatePool2, ExFreePool}, - POOL_FLAG_NON_PAGED, - SIZE_T, - ULONG, + POOL_FLAG_NON_PAGED, SIZE_T, ULONG, }; /// Allocator implementation to use with `#[global_allocator]` to allow use diff --git a/crates/wdk-build/Cargo.toml b/crates/wdk-build/Cargo.toml index ad92f32f..922c3266 100644 --- a/crates/wdk-build/Cargo.toml +++ b/crates/wdk-build/Cargo.toml @@ -20,7 +20,6 @@ cargo_metadata.workspace = true cfg-if.workspace = true clap = { workspace = true, features = ["derive"] } clap-cargo.workspace = true -lazy_static.workspace = true paste.workspace = true rustversion.workspace = true serde = { workspace = true, features = ["derive"] } diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 26be9942..125ce681 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -26,13 +26,9 @@ use tracing::{instrument, trace}; use crate::{ metadata, utils::{ - detect_wdk_content_root, - get_latest_windows_sdk_version, - get_wdk_version_number, - PathExt, + detect_wdk_content_root, get_latest_windows_sdk_version, get_wdk_version_number, PathExt, }, - ConfigError, - CpuArchitecture, + ConfigError, CpuArchitecture, }; /// The filename of the main makefile for Rust Windows drivers. diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index db2e8aa8..c13318af 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -29,6 +29,8 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use utils::PathExt; +use std::sync::LazyLock; + /// Configuration parameters for a build dependent on the WDK #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Config { @@ -981,14 +983,8 @@ pub fn configure_wdk_binary_build() -> Result<(), ConfigError> { Config::from_env_auto()?.configure_binary_build() } -// This currently only exports the driver type, but may export more metadata in -// the future. `EXPORTED_CFG_SETTINGS` is a mapping of cfg key to allowed cfg -// values -lazy_static::lazy_static! { - // FIXME: replace lazy_static with std::Lazy once available: https://github.com/rust-lang/rust/issues/109736 - static ref EXPORTED_CFG_SETTINGS: Vec<(&'static str, Vec<&'static str>)> = - vec![("DRIVER_MODEL-DRIVER_TYPE", vec!["WDM", "KMDF", "UMDF"])]; -} +static EXPORTED_CFG_SETTINGS: LazyLock)>> = + LazyLock::new(|| vec![("DRIVER_MODEL-DRIVER_TYPE", vec!["WDM", "KMDF", "UMDF"])]); #[cfg(test)] mod tests { diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 4f4f6351..52a23d18 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -14,13 +14,7 @@ use thiserror::Error; use windows::{ core::{s, PCSTR}, Win32::System::Registry::{ - RegCloseKey, - RegGetValueA, - RegOpenKeyExA, - HKEY, - HKEY_LOCAL_MACHINE, - KEY_READ, - RRF_RT_REG_SZ, + RegCloseKey, RegGetValueA, RegOpenKeyExA, HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, }, }; @@ -422,9 +416,7 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ - FOLDERID_ProgramFiles, - SHGetKnownFolderPath, - KF_FLAG_DEFAULT, + FOLDERID_ProgramFiles, SHGetKnownFolderPath, KF_FLAG_DEFAULT, }; use super::*; diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index cb0b6d63..107aee33 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -12,33 +12,11 @@ use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{format_ident, quote}; use syn::{ parse::{Parse, ParseStream}, - parse2, - parse_file, - parse_quote, + parse2, parse_file, parse_quote, punctuated::Punctuated, - AngleBracketedGenericArguments, - Attribute, - BareFnArg, - Error, - Expr, - ExprCall, - File, - GenericArgument, - Ident, - Item, - ItemType, - LitStr, - Path, - PathArguments, - PathSegment, - Result, - ReturnType, - Signature, - Stmt, - Token, - Type, - TypeBareFn, - TypePath, + AngleBracketedGenericArguments, Attribute, BareFnArg, Error, Expr, ExprCall, File, + GenericArgument, Ident, Item, ItemType, LitStr, Path, PathArguments, PathSegment, Result, + ReturnType, Signature, Stmt, Token, Type, TypeBareFn, TypePath, }; /// A procedural macro that allows WDF functions to be called by name. diff --git a/crates/wdk-sys/Cargo.toml b/crates/wdk-sys/Cargo.toml index d1de5c29..28a25475 100644 --- a/crates/wdk-sys/Cargo.toml +++ b/crates/wdk-sys/Cargo.toml @@ -21,7 +21,6 @@ anyhow.workspace = true bindgen.workspace = true cargo_metadata.workspace = true cc.workspace = true -lazy_static.workspace = true serde_json.workspace = true thiserror.workspace = true tracing.workspace = true @@ -29,7 +28,6 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] } wdk-build.workspace = true [dependencies] -lazy_static = { workspace = true, features = ["spin_no_std"] } rustversion.workspace = true wdk-macros.workspace = true @@ -74,4 +72,3 @@ redundant_explicit_links = "warn" unescaped_backticks = "warn" [package.metadata.cargo-machete] -ignored = ["lazy_static"] # lazy_static is used in code generated by build.rs diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 37f350f3..59d82f66 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -10,25 +10,20 @@ use std::{ env, io::Write, path::{Path, PathBuf}, + sync::LazyLock, thread, }; use anyhow::Context; use bindgen::CodegenConfig; -use lazy_static::lazy_static; use tracing::{info, info_span, Span}; use tracing_subscriber::{ filter::{LevelFilter, ParseError}, EnvFilter, }; use wdk_build::{ - configure_wdk_library_build_and_then, - BuilderExt, - Config, - ConfigError, - DriverConfig, - KmdfConfig, - UmdfConfig, + configure_wdk_library_build_and_then, BuilderExt, Config, ConfigError, DriverConfig, + KmdfConfig, UmdfConfig, }; const NUM_WDF_FUNCTIONS_PLACEHOLDER: &str = @@ -47,18 +42,16 @@ const WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL: &str = " const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = " let wdf_function_count = crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize;"; -// FIXME: replace lazy_static with std::Lazy once available: https://github.com/rust-lang/rust/issues/109736 -lazy_static! { - static ref WDF_FUNCTION_TABLE_TEMPLATE: String = format!( +static WDF_FUNCTION_TABLE_TEMPLATE: LazyLock = LazyLock::new(|| { + format!( r#" -// FIXME: replace lazy_static with std::Lazy once available: https://github.com/rust-lang/rust/issues/109736 #[cfg(any(driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF"))] -lazy_static::lazy_static! {{ - #[allow(missing_docs)] - pub static ref WDF_FUNCTION_TABLE: &'static [crate::WDFFUNC] = {{ +#[allow(missing_docs)] +pub static WDF_FUNCTION_TABLE: core::cell::LazyCell<&'static [crate::WDFFUNC]> = core::cell::LazyCell::new(|| {{ + {{ // SAFETY: `WdfFunctions` is generated as a mutable static, but is not supposed to be ever mutated by WDF. let wdf_function_table = unsafe {{ crate::WdfFunctions }}; -{WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER} + {WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER} // SAFETY: This is safe because: // 1. `WdfFunctions` is valid for reads for `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::()` @@ -72,10 +65,13 @@ lazy_static::lazy_static! {{ debug_assert!(isize::try_from(wdf_function_count * core::mem::size_of::()).is_ok()); core::slice::from_raw_parts(wdf_function_table, wdf_function_count) }} - }}; -}}"# - ); - static ref CALL_UNSAFE_WDF_BINDING_TEMPLATE: String = format!( + }} +}});"# +) +}); + +static CALL_UNSAFE_WDF_BINDING_TEMPLATE: LazyLock = LazyLock::new(|| { + format!( r#" /// A procedural macro that allows WDF functions to be called by name. /// @@ -125,18 +121,20 @@ macro_rules! call_unsafe_wdf_function_binding {{ ) }} }}"# - ); - static ref TEST_STUBS_TEMPLATE: String = format!( - r" -use crate::WDFFUNC; - -/// Stubbed version of the symbol that [`WdfFunctions`] links to so that test targets will compile -#[no_mangle] -pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); -", - ); -} + ) +}); +static TEST_STUBS_TEMPLATE: LazyLock = LazyLock::new(|| { + format!( + r" + use crate::WDFFUNC; + + /// Stubbed version of the symbol that [`WdfFunctions`] links to so that test targets will compile + #[no_mangle] + pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); + ", + ) +}); type GenerateFn = fn(&Path, &Config) -> Result<(), ConfigError>; const BINDGEN_FILE_GENERATORS_TUPLES: &[(&str, GenerateFn)] = &[ diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 7535ca02..4e46c948 100644 --- a/crates/wdk/src/wdf/timer.rs +++ b/crates/wdk/src/wdf/timer.rs @@ -2,11 +2,7 @@ // License: MIT OR Apache-2.0 use wdk_sys::{ - call_unsafe_wdf_function_binding, - NTSTATUS, - WDFTIMER, - WDF_OBJECT_ATTRIBUTES, - WDF_TIMER_CONFIG, + call_unsafe_wdf_function_binding, NTSTATUS, WDFTIMER, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, }; use crate::nt_success; diff --git a/examples/sample-kmdf-driver/Cargo.lock b/examples/sample-kmdf-driver/Cargo.lock index 68afe172..ae91755f 100644 --- a/examples/sample-kmdf-driver/Cargo.lock +++ b/examples/sample-kmdf-driver/Cargo.lock @@ -287,9 +287,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -565,12 +562,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -728,7 +719,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -760,7 +750,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/examples/sample-umdf-driver/Cargo.lock b/examples/sample-umdf-driver/Cargo.lock index d95db0be..ade5a142 100644 --- a/examples/sample-umdf-driver/Cargo.lock +++ b/examples/sample-umdf-driver/Cargo.lock @@ -287,9 +287,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -563,12 +560,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -716,7 +707,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -744,7 +734,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/examples/sample-wdm-driver/Cargo.lock b/examples/sample-wdm-driver/Cargo.lock index a79d27fb..9d2a4eea 100644 --- a/examples/sample-wdm-driver/Cargo.lock +++ b/examples/sample-wdm-driver/Cargo.lock @@ -287,9 +287,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -565,12 +562,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -728,7 +719,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -760,7 +750,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/tests/config-kmdf/Cargo.lock b/tests/config-kmdf/Cargo.lock index af8a88c1..4a6aa31c 100644 --- a/tests/config-kmdf/Cargo.lock +++ b/tests/config-kmdf/Cargo.lock @@ -342,9 +342,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -646,12 +643,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -846,7 +837,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -871,7 +861,6 @@ name = "wdk-macros-tests" version = "0.1.0" dependencies = [ "fs4", - "lazy_static", "macrotest", "owo-colors", "paste", @@ -888,7 +877,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/tests/config-umdf/Cargo.lock b/tests/config-umdf/Cargo.lock index 99a963cd..7135bfed 100644 --- a/tests/config-umdf/Cargo.lock +++ b/tests/config-umdf/Cargo.lock @@ -342,9 +342,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -646,12 +643,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -846,7 +837,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -871,7 +861,6 @@ name = "wdk-macros-tests" version = "0.1.0" dependencies = [ "fs4", - "lazy_static", "macrotest", "owo-colors", "paste", @@ -888,7 +877,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/tests/mixed-package-kmdf-workspace/Cargo.lock b/tests/mixed-package-kmdf-workspace/Cargo.lock index 93f31b48..5e7e7cae 100644 --- a/tests/mixed-package-kmdf-workspace/Cargo.lock +++ b/tests/mixed-package-kmdf-workspace/Cargo.lock @@ -298,9 +298,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -570,12 +567,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -733,7 +724,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -765,7 +755,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/tests/umdf-driver-workspace/Cargo.lock b/tests/umdf-driver-workspace/Cargo.lock index 1dee849d..1ecb3200 100644 --- a/tests/umdf-driver-workspace/Cargo.lock +++ b/tests/umdf-driver-workspace/Cargo.lock @@ -305,9 +305,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -573,12 +570,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -726,7 +717,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -754,7 +744,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", diff --git a/tests/wdk-macros-tests/Cargo.lock b/tests/wdk-macros-tests/Cargo.lock index a963b997..8bcbab9c 100644 --- a/tests/wdk-macros-tests/Cargo.lock +++ b/tests/wdk-macros-tests/Cargo.lock @@ -77,12 +77,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.155" @@ -307,7 +301,6 @@ name = "wdk-macros-tests" version = "0.1.0" dependencies = [ "fs4", - "lazy_static", "macrotest", "owo-colors", "paste", diff --git a/tests/wdk-macros-tests/Cargo.toml b/tests/wdk-macros-tests/Cargo.toml index 7f16c6ef..2edb4df6 100644 --- a/tests/wdk-macros-tests/Cargo.toml +++ b/tests/wdk-macros-tests/Cargo.toml @@ -10,7 +10,6 @@ publish = false [dependencies] fs4 = { version = "0.8.4", features = ["sync"] } -lazy_static = "1.5.0" macrotest = "1.0.13" owo-colors = "4.0.0" paste = "1.0.15" diff --git a/tests/wdk-macros-tests/src/lib.rs b/tests/wdk-macros-tests/src/lib.rs index dc734697..fa228046 100644 --- a/tests/wdk-macros-tests/src/lib.rs +++ b/tests/wdk-macros-tests/src/lib.rs @@ -2,9 +2,8 @@ // License: MIT OR Apache-2.0 use std::path::PathBuf; - +use std::sync::LazyLock; use fs4::FileExt; -use lazy_static::lazy_static; pub use macrotest::{expand, expand_args}; pub use owo_colors::OwoColorize; pub use paste::paste; @@ -19,19 +18,17 @@ const TOOLCHAIN_CHANNEL_NAME: &str = "beta"; #[rustversion::nightly] const TOOLCHAIN_CHANNEL_NAME: &str = "nightly"; -lazy_static! { - static ref TESTS_FOLDER_PATH: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect(); - static ref INPUTS_FOLDER_PATH: PathBuf = TESTS_FOLDER_PATH.join("inputs"); - pub static ref MACROTEST_INPUT_FOLDER_PATH: PathBuf = INPUTS_FOLDER_PATH.join("macrotest"); - pub static ref TRYBUILD_INPUT_FOLDER_PATH: PathBuf = INPUTS_FOLDER_PATH.join("trybuild"); - static ref OUTPUTS_FOLDER_PATH: PathBuf = TESTS_FOLDER_PATH.join("outputs"); - static ref TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH: PathBuf = - OUTPUTS_FOLDER_PATH.join(TOOLCHAIN_CHANNEL_NAME); - pub static ref MACROTEST_OUTPUT_FOLDER_PATH: PathBuf = - TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("macrotest"); - pub static ref TRYBUILD_OUTPUT_FOLDER_PATH: PathBuf = - TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("trybuild"); -} +static TESTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {[env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect()}); +static INPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {TESTS_FOLDER_PATH.join("inputs")}); +pub static MACROTEST_INPUT_FOLDER_PATH: LazyLock = LazyLock::new(|| {INPUTS_FOLDER_PATH.join("macrotest")}); +pub static TRYBUILD_INPUT_FOLDER_PATH: LazyLock = LazyLock::new(|| {INPUTS_FOLDER_PATH.join("trybuild")}); +static OUTPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {TESTS_FOLDER_PATH.join("outputs")}); +static TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {OUTPUTS_FOLDER_PATH.join(TOOLCHAIN_CHANNEL_NAME)}); +pub static MACROTEST_OUTPUT_FOLDER_PATH: LazyLock = + LazyLock::new(|| {TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH.join("macrotest")}); +pub static TRYBUILD_OUTPUT_FOLDER_PATH: LazyLock = + 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 diff --git a/tests/wdk-sys-tests/Cargo.lock b/tests/wdk-sys-tests/Cargo.lock index 3b4cd777..dd22314f 100644 --- a/tests/wdk-sys-tests/Cargo.lock +++ b/tests/wdk-sys-tests/Cargo.lock @@ -290,9 +290,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -558,12 +555,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" version = "0.11.1" @@ -701,7 +692,6 @@ dependencies = [ "cfg-if", "clap", "clap-cargo", - "lazy_static", "paste", "rustversion", "serde", @@ -729,7 +719,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "lazy_static", "rustversion", "serde_json", "thiserror", From 76b6805bf918075f07bedad39b2d8df8c4cfd647 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 15:22:38 -0800 Subject: [PATCH 02/12] Finished implementation of FunctionTable --- Cargo.lock | 7 +- Cargo.toml | 5 +- crates/wdk-sys/Cargo.toml | 3 + crates/wdk-sys/build.rs | 69 +++++++++++++------ examples/sample-kmdf-driver/Cargo.lock | 7 +- examples/sample-umdf-driver/Cargo.lock | 7 +- examples/sample-wdm-driver/Cargo.lock | 7 +- tests/config-kmdf/Cargo.lock | 7 +- tests/config-umdf/Cargo.lock | 7 +- tests/mixed-package-kmdf-workspace/Cargo.lock | 7 +- tests/umdf-driver-workspace/Cargo.lock | 7 +- tests/wdk-sys-tests/Cargo.lock | 7 +- 12 files changed, 88 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c2804a7..1d80dd9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -371,9 +371,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -757,6 +757,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 440a11d6..06ffd73a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,12 +27,8 @@ readme = "README.md" license = "MIT OR Apache-2.0" [workspace.dependencies] -# Workspace Crates -wdk = { path = "crates/wdk", version = "0.3.0" } -wdk-alloc = { path = "crates/wdk-alloc", version = "0.3.0" } wdk-build = { path = "crates/wdk-build", version = "0.3.0" } wdk-macros = { path = "crates/wdk-macros", version = "0.3.0" } -wdk-panic = { path = "crates/wdk-panic", version = "0.3.0" } wdk-sys = { path = "crates/wdk-sys", version = "0.3.0" } # External Crates @@ -45,6 +41,7 @@ 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" diff --git a/crates/wdk-sys/Cargo.toml b/crates/wdk-sys/Cargo.toml index 28a25475..4639d597 100644 --- a/crates/wdk-sys/Cargo.toml +++ b/crates/wdk-sys/Cargo.toml @@ -21,6 +21,7 @@ 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 @@ -28,6 +29,7 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] } wdk-build.workspace = true [dependencies] +once_cell.workspace = true rustversion.workspace = true wdk-macros.workspace = true @@ -72,3 +74,4 @@ redundant_explicit_links = "warn" unescaped_backticks = "warn" [package.metadata.cargo-machete] +ignored = ["once_cell"] \ No newline at end of file diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 59d82f66..3ea8d038 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -44,29 +44,56 @@ const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = " static WDF_FUNCTION_TABLE_TEMPLATE: LazyLock = LazyLock::new(|| { format!( - r#" -#[cfg(any(driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF"))] -#[allow(missing_docs)] -pub static WDF_FUNCTION_TABLE: core::cell::LazyCell<&'static [crate::WDFFUNC]> = core::cell::LazyCell::new(|| {{ - {{ - // SAFETY: `WdfFunctions` is generated as a mutable static, but is not supposed to be ever mutated by WDF. - let wdf_function_table = unsafe {{ crate::WdfFunctions }}; - {WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER} - - // SAFETY: This is safe because: - // 1. `WdfFunctions` is valid for reads for `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::()` - // bytes, and is guaranteed to be aligned and it must be properly aligned. - // 2. `WdfFunctions` points to `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` consecutive properly initialized values of - // type `WDFFUNC`. - // 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::()`, of the slice must be no - // larger than `isize::MAX`. This is proven by the below `debug_assert!`. - unsafe {{ - debug_assert!(isize::try_from(wdf_function_count * core::mem::size_of::()).is_ok()); - core::slice::from_raw_parts(wdf_function_table, wdf_function_count) +r#"extern crate alloc; + +/// Struct to encapsulate a function table. +/// Lazily initializes on access via index operation. +pub struct FunctionTable {{ + inner: once_cell::race::OnceBox> +}} + +impl core::ops::Index for FunctionTable {{ + type Output = crate::WDFFUNC; + + fn index(&self, index: usize) -> &Self::Output {{ + &(**(self.get_function_table()))[index] + }} +}} + +impl FunctionTable {{ + /// Initializes new FunctionTable. + /// Will not contain data until accessed via index operator. + pub const fn new() -> FunctionTable {{ + FunctionTable {{ + inner: once_cell::race::OnceBox::new() }} }} -}});"# + + fn get_function_table(&self) -> &alloc::boxed::Box<[crate::WDFFUNC]> {{ + self.inner.get_or_init(|| {{ + // SAFETY: `WdfFunctions` is generated as a mutable static, but is not supposed to be ever mutated by WDF. + let wdf_function_table = unsafe {{ crate::WdfFunctions }}; + {WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER} + + // SAFETY: This is safe because: + // 1. `WdfFunctions` is valid for reads for `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::()` + // bytes, and is guaranteed to be aligned and it must be properly aligned. + // 2. `WdfFunctions` points to `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` consecutive properly initialized values of + // type `WDFFUNC`. + // 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::()`, of the slice must be no + // larger than `isize::MAX`. This is proven by the below `debug_assert!`. + unsafe {{ + debug_assert!(isize::try_from(wdf_function_count * core::mem::size_of::()).is_ok()); + alloc::boxed::Box::new(core::slice::from_raw_parts(wdf_function_table, wdf_function_count).into()) + }} + }}) + }} +}} + +/// Static instance of the function table to be used throughout generated code. +pub static WDF_FUNCTION_TABLE: FunctionTable = FunctionTable::new(); +"# ) }); diff --git a/examples/sample-kmdf-driver/Cargo.lock b/examples/sample-kmdf-driver/Cargo.lock index ae91755f..9c433e66 100644 --- a/examples/sample-kmdf-driver/Cargo.lock +++ b/examples/sample-kmdf-driver/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -750,6 +750,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/examples/sample-umdf-driver/Cargo.lock b/examples/sample-umdf-driver/Cargo.lock index ade5a142..6ec43620 100644 --- a/examples/sample-umdf-driver/Cargo.lock +++ b/examples/sample-umdf-driver/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -734,6 +734,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/examples/sample-wdm-driver/Cargo.lock b/examples/sample-wdm-driver/Cargo.lock index 9d2a4eea..b63e2dad 100644 --- a/examples/sample-wdm-driver/Cargo.lock +++ b/examples/sample-wdm-driver/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -750,6 +750,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/config-kmdf/Cargo.lock b/tests/config-kmdf/Cargo.lock index 4a6aa31c..cc31bb74 100644 --- a/tests/config-kmdf/Cargo.lock +++ b/tests/config-kmdf/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -436,9 +436,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -877,6 +877,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/config-umdf/Cargo.lock b/tests/config-umdf/Cargo.lock index 7135bfed..a9fe3815 100644 --- a/tests/config-umdf/Cargo.lock +++ b/tests/config-umdf/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -436,9 +436,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -877,6 +877,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/mixed-package-kmdf-workspace/Cargo.lock b/tests/mixed-package-kmdf-workspace/Cargo.lock index 5e7e7cae..4320a4e6 100644 --- a/tests/mixed-package-kmdf-workspace/Cargo.lock +++ b/tests/mixed-package-kmdf-workspace/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -380,9 +380,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -755,6 +755,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/umdf-driver-workspace/Cargo.lock b/tests/umdf-driver-workspace/Cargo.lock index 1ecb3200..261e8624 100644 --- a/tests/umdf-driver-workspace/Cargo.lock +++ b/tests/umdf-driver-workspace/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -383,9 +383,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -744,6 +744,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/wdk-sys-tests/Cargo.lock b/tests/wdk-sys-tests/Cargo.lock index dd22314f..bfed4173 100644 --- a/tests/wdk-sys-tests/Cargo.lock +++ b/tests/wdk-sys-tests/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -368,9 +368,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "overload" @@ -719,6 +719,7 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", + "once_cell", "rustversion", "serde_json", "thiserror", From 214e5cb4a3d40ebcf31abfcb263346d3566ffd16 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 15:46:22 -0800 Subject: [PATCH 03/12] reverted changes made by cargo fmt --- Cargo.toml | 4 ++++ crates/wdk-alloc/src/lib.rs | 6 ++++-- crates/wdk-build/src/cargo_make.rs | 8 ++++++-- crates/wdk-build/src/utils.rs | 12 ++++++++++-- crates/wdk-macros/src/lib.rs | 31 +++++++++++++++++++++++++----- crates/wdk-sys/build.rs | 21 ++++++++++++-------- crates/wdk/src/wdf/timer.rs | 6 +++++- 7 files changed, 68 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 06ffd73a..13f6040e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,12 @@ readme = "README.md" license = "MIT OR Apache-2.0" [workspace.dependencies] +# Workspace Crates +wdk = { path = "crates/wdk", version = "0.3.0" } +wdk-alloc = { path = "crates/wdk-alloc", version = "0.3.0" } wdk-build = { path = "crates/wdk-build", version = "0.3.0" } wdk-macros = { path = "crates/wdk-macros", version = "0.3.0" } +wdk-panic = { path = "crates/wdk-panic", version = "0.3.0" } wdk-sys = { path = "crates/wdk-sys", version = "0.3.0" } # External Crates diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 3812d8fc..8b6a3486 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -29,10 +29,12 @@ pub use kernel_mode::*; mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; - + use wdk_sys::{ ntddk::{ExAllocatePool2, ExFreePool}, - POOL_FLAG_NON_PAGED, SIZE_T, ULONG, + POOL_FLAG_NON_PAGED, + SIZE_T, + ULONG, }; /// Allocator implementation to use with `#[global_allocator]` to allow use diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 125ce681..26be9942 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -26,9 +26,13 @@ use tracing::{instrument, trace}; use crate::{ metadata, utils::{ - detect_wdk_content_root, get_latest_windows_sdk_version, get_wdk_version_number, PathExt, + detect_wdk_content_root, + get_latest_windows_sdk_version, + get_wdk_version_number, + PathExt, }, - ConfigError, CpuArchitecture, + ConfigError, + CpuArchitecture, }; /// The filename of the main makefile for Rust Windows drivers. diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 52a23d18..4f4f6351 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -14,7 +14,13 @@ use thiserror::Error; use windows::{ core::{s, PCSTR}, Win32::System::Registry::{ - RegCloseKey, RegGetValueA, RegOpenKeyExA, HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, + RegCloseKey, + RegGetValueA, + RegOpenKeyExA, + HKEY, + HKEY_LOCAL_MACHINE, + KEY_READ, + RRF_RT_REG_SZ, }, }; @@ -416,7 +422,9 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ - FOLDERID_ProgramFiles, SHGetKnownFolderPath, KF_FLAG_DEFAULT, + FOLDERID_ProgramFiles, + SHGetKnownFolderPath, + KF_FLAG_DEFAULT, }; use super::*; diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index 107aee33..7af668fe 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -12,13 +12,34 @@ use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{format_ident, quote}; use syn::{ parse::{Parse, ParseStream}, - parse2, parse_file, parse_quote, + parse2, + parse_file, + parse_quote, punctuated::Punctuated, - AngleBracketedGenericArguments, Attribute, BareFnArg, Error, Expr, ExprCall, File, - GenericArgument, Ident, Item, ItemType, LitStr, Path, PathArguments, PathSegment, Result, - ReturnType, Signature, Stmt, Token, Type, TypeBareFn, TypePath, + AngleBracketedGenericArguments, + Attribute, + BareFnArg, + Error, + Expr, + ExprCall, + File, + GenericArgument, + Ident, + Item, + ItemType, + LitStr, + Path, + PathArguments, + PathSegment, + Result, + ReturnType, + Signature, + Stmt, + Token, + Type, + TypeBareFn, + TypePath, }; - /// A procedural macro that allows WDF functions to be called by name. /// /// This macro is only intended to be used in the `wdk-sys` crate. Users wanting diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 3ea8d038..df24b0d2 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -22,8 +22,13 @@ use tracing_subscriber::{ EnvFilter, }; use wdk_build::{ - configure_wdk_library_build_and_then, BuilderExt, Config, ConfigError, DriverConfig, - KmdfConfig, UmdfConfig, + configure_wdk_library_build_and_then, + BuilderExt, + Config, + ConfigError, + DriverConfig, + KmdfConfig, + UmdfConfig, }; const NUM_WDF_FUNCTIONS_PLACEHOLDER: &str = @@ -94,7 +99,7 @@ impl FunctionTable {{ /// Static instance of the function table to be used throughout generated code. pub static WDF_FUNCTION_TABLE: FunctionTable = FunctionTable::new(); "# -) + ) }); static CALL_UNSAFE_WDF_BINDING_TEMPLATE: LazyLock = LazyLock::new(|| { @@ -154,12 +159,12 @@ macro_rules! call_unsafe_wdf_function_binding {{ static TEST_STUBS_TEMPLATE: LazyLock = LazyLock::new(|| { format!( r" - use crate::WDFFUNC; +use crate::WDFFUNC; - /// Stubbed version of the symbol that [`WdfFunctions`] links to so that test targets will compile - #[no_mangle] - pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); - ", +/// Stubbed version of the symbol that [`WdfFunctions`] links to so that test targets will compile +#[no_mangle] +pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); +", ) }); type GenerateFn = fn(&Path, &Config) -> Result<(), ConfigError>; diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 4e46c948..7535ca02 100644 --- a/crates/wdk/src/wdf/timer.rs +++ b/crates/wdk/src/wdf/timer.rs @@ -2,7 +2,11 @@ // License: MIT OR Apache-2.0 use wdk_sys::{ - call_unsafe_wdf_function_binding, NTSTATUS, WDFTIMER, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, + call_unsafe_wdf_function_binding, + NTSTATUS, + WDFTIMER, + WDF_OBJECT_ATTRIBUTES, + WDF_TIMER_CONFIG, }; use crate::nt_success; From fea4dfbd4654eba5450de215c1f0bec6176adb7a Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 15:53:39 -0800 Subject: [PATCH 04/12] last cleanup, consolidate imports --- crates/wdk-alloc/src/lib.rs | 2 +- crates/wdk-build/src/lib.rs | 4 +--- crates/wdk-macros/src/lib.rs | 1 + tests/wdk-macros-tests/src/lib.rs | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 8b6a3486..1a8b7282 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -29,7 +29,7 @@ pub use kernel_mode::*; mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; - + use wdk_sys::{ ntddk::{ExAllocatePool2, ExFreePool}, POOL_FLAG_NON_PAGED, diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index c13318af..ee4dfe20 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -22,15 +22,13 @@ mod utils; mod bindgen; -use std::{env, path::PathBuf}; +use std::{env, path::PathBuf, sync::LazyLock}; use cargo_metadata::MetadataCommand; use serde::{Deserialize, Serialize}; use thiserror::Error; use utils::PathExt; -use std::sync::LazyLock; - /// Configuration parameters for a build dependent on the WDK #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Config { diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index 7af668fe..cb0b6d63 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -40,6 +40,7 @@ use syn::{ TypeBareFn, TypePath, }; + /// A procedural macro that allows WDF functions to be called by name. /// /// This macro is only intended to be used in the `wdk-sys` crate. Users wanting diff --git a/tests/wdk-macros-tests/src/lib.rs b/tests/wdk-macros-tests/src/lib.rs index fa228046..1d7122bf 100644 --- a/tests/wdk-macros-tests/src/lib.rs +++ b/tests/wdk-macros-tests/src/lib.rs @@ -1,8 +1,7 @@ // Copyright (c) Microsoft Corporation // License: MIT OR Apache-2.0 -use std::path::PathBuf; -use std::sync::LazyLock; +use std::{path::PathBuf, sync::LazyLock}; use fs4::FileExt; pub use macrotest::{expand, expand_args}; pub use owo_colors::OwoColorize; From 1f035a8d83c6a4e261a7ef0c96f6b6578594e9b4 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 16:03:17 -0800 Subject: [PATCH 05/12] corrected formatting --- Cargo.toml | 4 +++- crates/wdk-sys/build.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 13f6040e..2b9db9de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,9 @@ 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"] } +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" diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index df24b0d2..bc24e193 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -48,8 +48,8 @@ const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = " let wdf_function_count = crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize;"; static WDF_FUNCTION_TABLE_TEMPLATE: LazyLock = LazyLock::new(|| { - format!( -r#"extern crate alloc; + format!(r#" +extern crate alloc; /// Struct to encapsulate a function table. /// Lazily initializes on access via index operation. From 31c883ea5a0ff168b45117ee8cdd0de467521ca6 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 16:05:04 -0800 Subject: [PATCH 06/12] adapted to cargo clippy --- crates/wdk-sys/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index bc24e193..60a46ada 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -48,7 +48,7 @@ const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = " let wdf_function_count = crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize;"; static WDF_FUNCTION_TABLE_TEMPLATE: LazyLock = LazyLock::new(|| { - format!(r#" + format!(r" extern crate alloc; /// Struct to encapsulate a function table. @@ -98,7 +98,7 @@ impl FunctionTable {{ /// Static instance of the function table to be used throughout generated code. pub static WDF_FUNCTION_TABLE: FunctionTable = FunctionTable::new(); -"# +" ) }); From 0243f685be485d7893b509bd31037bbfcd66a1dc Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 16:10:49 -0800 Subject: [PATCH 07/12] fix newline around format macro --- crates/wdk-sys/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 60a46ada..05a64960 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -48,7 +48,8 @@ const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = " let wdf_function_count = crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize;"; static WDF_FUNCTION_TABLE_TEMPLATE: LazyLock = LazyLock::new(|| { - format!(r" + format!( + r" extern crate alloc; /// Struct to encapsulate a function table. From ea050a6d0a32529a3aa93fb0b121440256611c6e Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 4 Dec 2024 18:41:31 -0800 Subject: [PATCH 08/12] Taplo passing locally --- crates/wdk-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wdk-sys/Cargo.toml b/crates/wdk-sys/Cargo.toml index 4639d597..425aed79 100644 --- a/crates/wdk-sys/Cargo.toml +++ b/crates/wdk-sys/Cargo.toml @@ -74,4 +74,4 @@ redundant_explicit_links = "warn" unescaped_backticks = "warn" [package.metadata.cargo-machete] -ignored = ["once_cell"] \ No newline at end of file +ignored = ["once_cell"] From b49a18fbcd0dd6d3c9fefaa08c27e0f8196aaed2 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 11 Dec 2024 14:25:57 -0800 Subject: [PATCH 09/12] addressed PR comments, removed function table static --- crates/wdk-macros/src/lib.rs | 16 ++- crates/wdk-sys/build.rs | 103 +++--------------- crates/wdk-sys/src/lib.rs | 3 +- .../bug_tuple_struct_shadowing.expanded.rs | 19 +++- .../macrotest/bug_unused_imports.expanded.rs | 19 +++- .../macrotest/wdf_device_create.expanded.rs | 19 +++- ...device_create_device_interface.expanded.rs | 19 +++- .../macrotest/wdf_driver_create.expanded.rs | 19 +++- ...request_retrieve_output_buffer.expanded.rs | 19 +++- .../wdf_spin_lock_acquire.expanded.rs | 19 +++- .../wdf_verifier_dbg_break_point.expanded.rs | 21 +++- .../bug_tuple_struct_shadowing.expanded.rs | 19 +++- .../macrotest/bug_unused_imports.expanded.rs | 19 +++- .../macrotest/wdf_device_create.expanded.rs | 19 +++- ...device_create_device_interface.expanded.rs | 19 +++- .../macrotest/wdf_driver_create.expanded.rs | 19 +++- ...request_retrieve_output_buffer.expanded.rs | 19 +++- .../wdf_spin_lock_acquire.expanded.rs | 19 +++- .../wdf_verifier_dbg_break_point.expanded.rs | 19 +++- .../bug_tuple_struct_shadowing.expanded.rs | 19 +++- .../macrotest/bug_unused_imports.expanded.rs | 19 +++- .../macrotest/wdf_device_create.expanded.rs | 19 +++- ...device_create_device_interface.expanded.rs | 19 +++- .../macrotest/wdf_driver_create.expanded.rs | 19 +++- ...request_retrieve_output_buffer.expanded.rs | 19 +++- .../wdf_spin_lock_acquire.expanded.rs | 19 +++- .../wdf_verifier_dbg_break_point.expanded.rs | 19 +++- 27 files changed, 465 insertions(+), 115 deletions(-) diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index cb0b6d63..96fc3e56 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -229,9 +229,23 @@ impl DerivedASTFragments { // arguments for the WDF function is safe befause WDF maintains the strict mapping between the // function table index and the correct function pointer type. unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + + // SAFETY: This is safe because: + // 1. `WdfFunctions` is valid for reads for `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::()` + // bytes, and is guaranteed to be aligned and it must be properly aligned. + // 2. `WdfFunctions` points to `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` consecutive properly initialized values of + // type `WDFFUNC`. + // 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::()`, 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::()).is_ok()); + let wdf_function_table = core::slice::from_raw_parts(wdf_function_table, wdk_sys::wdf::WDF_FUNCTION_COUNT); + core::mem::transmute( // FIXME: investigate why _WDFFUNCENUM does not have a generated type alias without the underscore prefix - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::#function_table_index as usize], + wdf_function_table[wdk_sys::_WDFFUNCENUM::#function_table_index as usize], ) } ); diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 05a64960..0ec980ab 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -31,77 +31,20 @@ use wdk_build::{ UmdfConfig, }; -const NUM_WDF_FUNCTIONS_PLACEHOLDER: &str = - ""; -const WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER: &str = - ""; const OUT_DIR_PLACEHOLDER: &str = ""; const WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER: &str = ""; 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. - let wdf_function_count = unsafe { crate::WdfFunctionCount } as usize;"; -const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = " - let wdf_function_count = crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize;"; - -static WDF_FUNCTION_TABLE_TEMPLATE: LazyLock = LazyLock::new(|| { - format!( - r" -extern crate alloc; - -/// Struct to encapsulate a function table. -/// Lazily initializes on access via index operation. -pub struct FunctionTable {{ - inner: once_cell::race::OnceBox> -}} - -impl core::ops::Index for FunctionTable {{ - type Output = crate::WDFFUNC; - - fn index(&self, index: usize) -> &Self::Output {{ - &(**(self.get_function_table()))[index] - }} -}} - -impl FunctionTable {{ - /// Initializes new FunctionTable. - /// Will not contain data until accessed via index operator. - pub const fn new() -> FunctionTable {{ - FunctionTable {{ - inner: once_cell::race::OnceBox::new() - }} - }} - - fn get_function_table(&self) -> &alloc::boxed::Box<[crate::WDFFUNC]> {{ - self.inner.get_or_init(|| {{ - // SAFETY: `WdfFunctions` is generated as a mutable static, but is not supposed to be ever mutated by WDF. - let wdf_function_table = unsafe {{ crate::WdfFunctions }}; - {WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER} - - // SAFETY: This is safe because: - // 1. `WdfFunctions` is valid for reads for `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` * `core::mem::size_of::()` - // bytes, and is guaranteed to be aligned and it must be properly aligned. - // 2. `WdfFunctions` points to `{NUM_WDF_FUNCTIONS_PLACEHOLDER}` consecutive properly initialized values of - // type `WDFFUNC`. - // 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::()`, of the slice must be no - // larger than `isize::MAX`. This is proven by the below `debug_assert!`. - unsafe {{ - debug_assert!(isize::try_from(wdf_function_count * core::mem::size_of::()).is_ok()); - alloc::boxed::Box::new(core::slice::from_raw_parts(wdf_function_table, wdf_function_count).into()) - }} - }}) - }} -}} +// 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;"; -/// Static instance of the function table to be used throughout generated code. -pub static WDF_FUNCTION_TABLE: FunctionTable = FunctionTable::new(); -" - ) -}); +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;"; static CALL_UNSAFE_WDF_BINDING_TEMPLATE: LazyLock = LazyLock::new(|| { format!( @@ -290,15 +233,14 @@ fn generate_wdf(out_path: &Path, config: &Config) -> Result<(), ConfigError> { } } -/// Generates a `wdf_function_table.rs` file in `OUT_DIR` which contains the -/// definition of `WDF_FUNCTION_TABLE`. This is required to be generated here +/// Generates a `wdf_function_count.rs` file in `OUT_DIR` which contains the +/// definition of `WDF_FUNCTION_COUNT`. This is required to be generated here /// since the size of the table is derived from either a global symbol -/// (`WDF_FUNCTION_COUNT`) that newer WDF versions expose, or an enum that older -/// versions use. +/// that newer WDF versions expose, or an enum that older versions use. fn generate_wdf_function_table(out_path: &Path, config: &Config) -> std::io::Result<()> { const MINIMUM_MINOR_VERSION_TO_GENERATE_WDF_FUNCTION_COUNT: u8 = 25; - let generated_file_path = out_path.join("wdf_function_table.rs"); + let generated_file_path = out_path.join("wdf_function_count.rs"); let mut generated_file = std::fs::File::create(generated_file_path)?; let is_wdf_function_count_generated = match *config { @@ -335,26 +277,13 @@ fn generate_wdf_function_table(out_path: &Path, config: &Config) -> std::io::Res } }; - let wdf_function_table_code_snippet = if is_wdf_function_count_generated { - WDF_FUNCTION_TABLE_TEMPLATE - .replace(NUM_WDF_FUNCTIONS_PLACEHOLDER, "crate::WdfFunctionCount") - .replace( - WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER, - WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL, - ) + let wdf_function_table_count_snippet = if is_wdf_function_count_generated { + WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL } else { - WDF_FUNCTION_TABLE_TEMPLATE - .replace( - NUM_WDF_FUNCTIONS_PLACEHOLDER, - "crate::_WDFFUNCENUM::WdfFunctionTableNumEntries", - ) - .replace( - WDF_FUNCTION_COUNT_DECLARATION_PLACEHOLDER, - WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX, - ) + WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX }; - generated_file.write_all(wdf_function_table_code_snippet.as_bytes())?; + generated_file.write_all(wdf_function_table_count_snippet.as_bytes())?; Ok(()) } @@ -458,7 +387,7 @@ fn main() -> anyhow::Result<()> { .expect("Scoped Thread should spawn successfully"), ); - info_span!("wdf_function_table.rs generation").in_scope(|| { + info_span!("wdf_function_count.rs generation").in_scope(|| { generate_wdf_function_table(&out_path, &config)?; Ok::<(), std::io::Error>(()) })?; diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index e6627c2e..bc299146 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -5,8 +5,7 @@ #![no_std] -#[cfg(any(driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF"))] -pub use wdf::WDF_FUNCTION_TABLE; + #[cfg(any( driver_model__driver_type = "WDM", driver_model__driver_type = "KMDF", diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs index bf31420b..9fb796e2 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs @@ -39,8 +39,25 @@ fn foo( pnp_power_event_callbacks__: PWDF_PNPPOWER_EVENT_CALLBACKS, ) { let wdf_function: wdk_sys::PFN_WDFDEVICEINITSETPNPPOWEREVENTCALLBACKS = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs index 62cc30dc..4879caef 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs @@ -47,8 +47,25 @@ pub extern "system" fn driver_entry( driver__: *mut WDFDRIVER, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs index ef27cf51..0acc066e 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs @@ -17,8 +17,25 @@ extern "C" fn evt_driver_device_add( device__: *mut WDFDEVICE, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDEVICECREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs index a3d848a3..c58d02b8 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs @@ -19,8 +19,25 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS reference_string__: PCUNICODE_STRING, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDEVICECREATEDEVICEINTERFACE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs index c29f50c0..e30be581 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs @@ -24,8 +24,25 @@ pub extern "system" fn driver_entry( driver__: *mut WDFDRIVER, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs index 550a1906..7183b4d5 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs @@ -16,8 +16,25 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { length__: *mut usize, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFREQUESTRETRIEVEOUTPUTBUFFER = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs index 0992a872..51e6fa3d 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs @@ -8,8 +8,25 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { #[inline(always)] pub unsafe fn wdf_spin_lock_acquire_impl(spin_lock__: WDFSPINLOCK) { let wdf_function: wdk_sys::PFN_WDFSPINLOCKACQUIRE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs index cb73dd15..76c49beb 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs @@ -8,9 +8,26 @@ fn foo() { #[inline(always)] pub unsafe fn wdf_verifier_dbg_break_point_impl() { let wdf_function: wdk_sys::PFN_WDFVERIFIERDBGBREAKPOINT = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex - as usize], + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex + as usize], ) }); if let Some(wdf_function) = wdf_function { diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs index bf31420b..9fb796e2 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs @@ -39,8 +39,25 @@ fn foo( pnp_power_event_callbacks__: PWDF_PNPPOWER_EVENT_CALLBACKS, ) { let wdf_function: wdk_sys::PFN_WDFDEVICEINITSETPNPPOWEREVENTCALLBACKS = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs index 62cc30dc..4879caef 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs @@ -47,8 +47,25 @@ pub extern "system" fn driver_entry( driver__: *mut WDFDRIVER, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs index ef27cf51..0acc066e 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs @@ -17,8 +17,25 @@ extern "C" fn evt_driver_device_add( device__: *mut WDFDEVICE, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDEVICECREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs index a3d848a3..c58d02b8 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs @@ -19,8 +19,25 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS reference_string__: PCUNICODE_STRING, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDEVICECREATEDEVICEINTERFACE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs index c29f50c0..e30be581 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs @@ -24,8 +24,25 @@ pub extern "system" fn driver_entry( driver__: *mut WDFDRIVER, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs index 550a1906..7183b4d5 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs @@ -16,8 +16,25 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { length__: *mut usize, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFREQUESTRETRIEVEOUTPUTBUFFER = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs index 0992a872..51e6fa3d 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs @@ -8,8 +8,25 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { #[inline(always)] pub unsafe fn wdf_spin_lock_acquire_impl(spin_lock__: WDFSPINLOCK) { let wdf_function: wdk_sys::PFN_WDFSPINLOCKACQUIRE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs index cb73dd15..27a03946 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs @@ -8,8 +8,25 @@ fn foo() { #[inline(always)] pub unsafe fn wdf_verifier_dbg_break_point_impl() { let wdf_function: wdk_sys::PFN_WDFVERIFIERDBGBREAKPOINT = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs index bf31420b..9fb796e2 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs @@ -39,8 +39,25 @@ fn foo( pnp_power_event_callbacks__: PWDF_PNPPOWER_EVENT_CALLBACKS, ) { let wdf_function: wdk_sys::PFN_WDFDEVICEINITSETPNPPOWEREVENTCALLBACKS = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs index 62cc30dc..4879caef 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs @@ -47,8 +47,25 @@ pub extern "system" fn driver_entry( driver__: *mut WDFDRIVER, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs index ef27cf51..0acc066e 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs @@ -17,8 +17,25 @@ extern "C" fn evt_driver_device_add( device__: *mut WDFDEVICE, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDEVICECREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs index a3d848a3..c58d02b8 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs @@ -19,8 +19,25 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS reference_string__: PCUNICODE_STRING, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDEVICECREATEDEVICEINTERFACE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs index c29f50c0..e30be581 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs @@ -24,8 +24,25 @@ pub extern "system" fn driver_entry( driver__: *mut WDFDRIVER, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs index 550a1906..7183b4d5 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs @@ -16,8 +16,25 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { length__: *mut usize, ) -> NTSTATUS { let wdf_function: wdk_sys::PFN_WDFREQUESTRETRIEVEOUTPUTBUFFER = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs index 0992a872..51e6fa3d 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs @@ -8,8 +8,25 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { #[inline(always)] pub unsafe fn wdf_spin_lock_acquire_impl(spin_lock__: WDFSPINLOCK) { let wdf_function: wdk_sys::PFN_WDFSPINLOCKACQUIRE = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex as usize], ) }); diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs index cb73dd15..951408b7 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs @@ -8,8 +8,25 @@ fn foo() { #[inline(always)] pub unsafe fn wdf_verifier_dbg_break_point_impl() { let wdf_function: wdk_sys::PFN_WDFVERIFIERDBGBREAKPOINT = Some(unsafe { + let wdf_function_table = wdk_sys::WdfFunctions; + if true { + if !isize::try_from( + wdk_sys::wdf::WDF_FUNCTION_COUNT + * core::mem::size_of::(), + ) + .is_ok() + { + ::core::panicking::panic( + "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + ) + } + } + let wdf_function_table = core::slice::from_raw_parts( + wdf_function_table, + wdk_sys::wdf::WDF_FUNCTION_COUNT, + ); core::mem::transmute( - wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex + wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex as usize], ) }); From a8280a3d99b7c10d5cf9960b212d31d05c4323f1 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 11 Dec 2024 16:42:49 -0800 Subject: [PATCH 10/12] passsed all pipeline checks --- Cargo.lock | 1 - Cargo.toml | 3 -- crates/wdk-macros/src/lib.rs | 11 +++--- crates/wdk-sys/Cargo.toml | 5 --- crates/wdk-sys/build.rs | 36 ++++++++++++------- crates/wdk-sys/src/lib.rs | 1 - crates/wdk-sys/src/wdf.rs | 2 +- examples/sample-kmdf-driver/Cargo.lock | 1 - examples/sample-umdf-driver/Cargo.lock | 1 - examples/sample-wdm-driver/Cargo.lock | 1 - tests/config-kmdf/Cargo.lock | 1 - tests/config-umdf/Cargo.lock | 1 - tests/mixed-package-kmdf-workspace/Cargo.lock | 1 - tests/umdf-driver-workspace/Cargo.lock | 1 - tests/wdk-macros-tests/src/lib.rs | 22 +++++++----- .../bug_tuple_struct_shadowing.expanded.rs | 7 ++-- .../macrotest/bug_unused_imports.expanded.rs | 7 ++-- .../macrotest/wdf_device_create.expanded.rs | 7 ++-- ...device_create_device_interface.expanded.rs | 7 ++-- .../macrotest/wdf_driver_create.expanded.rs | 7 ++-- ...request_retrieve_output_buffer.expanded.rs | 7 ++-- .../wdf_spin_lock_acquire.expanded.rs | 7 ++-- .../wdf_verifier_dbg_break_point.expanded.rs | 7 ++-- .../bug_tuple_struct_shadowing.expanded.rs | 7 ++-- .../macrotest/bug_unused_imports.expanded.rs | 7 ++-- .../macrotest/wdf_device_create.expanded.rs | 7 ++-- ...device_create_device_interface.expanded.rs | 7 ++-- .../macrotest/wdf_driver_create.expanded.rs | 7 ++-- ...request_retrieve_output_buffer.expanded.rs | 7 ++-- .../wdf_spin_lock_acquire.expanded.rs | 7 ++-- .../wdf_verifier_dbg_break_point.expanded.rs | 7 ++-- .../bug_tuple_struct_shadowing.expanded.rs | 7 ++-- .../macrotest/bug_unused_imports.expanded.rs | 7 ++-- .../macrotest/wdf_device_create.expanded.rs | 7 ++-- ...device_create_device_interface.expanded.rs | 7 ++-- .../macrotest/wdf_driver_create.expanded.rs | 7 ++-- ...request_retrieve_output_buffer.expanded.rs | 7 ++-- .../wdf_spin_lock_acquire.expanded.rs | 7 ++-- .../wdf_verifier_dbg_break_point.expanded.rs | 7 ++-- tests/wdk-sys-tests/Cargo.lock | 1 - 40 files changed, 139 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d80dd9f..74dbc07a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -757,7 +757,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 2b9db9de..440a11d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index 96fc3e56..710fc2b7 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -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::()` // bytes, and is guaranteed to be aligned and it must be properly aligned. @@ -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::()`, 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::()).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::()).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], diff --git a/crates/wdk-sys/Cargo.toml b/crates/wdk-sys/Cargo.toml index 425aed79..0a0e1d57 100644 --- a/crates/wdk-sys/Cargo.toml +++ b/crates/wdk-sys/Cargo.toml @@ -21,7 +21,6 @@ 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 @@ -29,7 +28,6 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] } wdk-build.workspace = true [dependencies] -once_cell.workspace = true rustversion.workspace = true wdk-macros.workspace = true @@ -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"] diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 0ec980ab..3047b26a 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -35,16 +35,23 @@ const OUT_DIR_PLACEHOLDER: &str = ""; const WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER: &str = ""; +const WDF_FUNCTION_COUNT_PLACEHOLDER: &str = + " = 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 = LazyLock::new(|| { format!( @@ -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(()) diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index bc299146..6820752a 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -5,7 +5,6 @@ #![no_std] - #[cfg(any( driver_model__driver_type = "WDM", driver_model__driver_type = "KMDF", diff --git a/crates/wdk-sys/src/wdf.rs b/crates/wdk-sys/src/wdf.rs index 28e75fc8..8831611d 100644 --- a/crates/wdk-sys/src/wdf.rs +++ b/crates/wdk-sys/src/wdf.rs @@ -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")); diff --git a/examples/sample-kmdf-driver/Cargo.lock b/examples/sample-kmdf-driver/Cargo.lock index 9c433e66..2733f0cd 100644 --- a/examples/sample-kmdf-driver/Cargo.lock +++ b/examples/sample-kmdf-driver/Cargo.lock @@ -750,7 +750,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/examples/sample-umdf-driver/Cargo.lock b/examples/sample-umdf-driver/Cargo.lock index 6ec43620..e8b0ffad 100644 --- a/examples/sample-umdf-driver/Cargo.lock +++ b/examples/sample-umdf-driver/Cargo.lock @@ -734,7 +734,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/examples/sample-wdm-driver/Cargo.lock b/examples/sample-wdm-driver/Cargo.lock index b63e2dad..8c15ea8f 100644 --- a/examples/sample-wdm-driver/Cargo.lock +++ b/examples/sample-wdm-driver/Cargo.lock @@ -750,7 +750,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/config-kmdf/Cargo.lock b/tests/config-kmdf/Cargo.lock index cc31bb74..fda5d141 100644 --- a/tests/config-kmdf/Cargo.lock +++ b/tests/config-kmdf/Cargo.lock @@ -877,7 +877,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/config-umdf/Cargo.lock b/tests/config-umdf/Cargo.lock index a9fe3815..8f84551e 100644 --- a/tests/config-umdf/Cargo.lock +++ b/tests/config-umdf/Cargo.lock @@ -877,7 +877,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/mixed-package-kmdf-workspace/Cargo.lock b/tests/mixed-package-kmdf-workspace/Cargo.lock index 4320a4e6..4dc9dca3 100644 --- a/tests/mixed-package-kmdf-workspace/Cargo.lock +++ b/tests/mixed-package-kmdf-workspace/Cargo.lock @@ -755,7 +755,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/umdf-driver-workspace/Cargo.lock b/tests/umdf-driver-workspace/Cargo.lock index 261e8624..40075533 100644 --- a/tests/umdf-driver-workspace/Cargo.lock +++ b/tests/umdf-driver-workspace/Cargo.lock @@ -744,7 +744,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", diff --git a/tests/wdk-macros-tests/src/lib.rs b/tests/wdk-macros-tests/src/lib.rs index 1d7122bf..1d722466 100644 --- a/tests/wdk-macros-tests/src/lib.rs +++ b/tests/wdk-macros-tests/src/lib.rs @@ -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; @@ -17,17 +18,20 @@ const TOOLCHAIN_CHANNEL_NAME: &str = "beta"; #[rustversion::nightly] const TOOLCHAIN_CHANNEL_NAME: &str = "nightly"; -static TESTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {[env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect()}); -static INPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {TESTS_FOLDER_PATH.join("inputs")}); -pub static MACROTEST_INPUT_FOLDER_PATH: LazyLock = LazyLock::new(|| {INPUTS_FOLDER_PATH.join("macrotest")}); -pub static TRYBUILD_INPUT_FOLDER_PATH: LazyLock = LazyLock::new(|| {INPUTS_FOLDER_PATH.join("trybuild")}); -static OUTPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {TESTS_FOLDER_PATH.join("outputs")}); -static TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| {OUTPUTS_FOLDER_PATH.join(TOOLCHAIN_CHANNEL_NAME)}); +static TESTS_FOLDER_PATH: LazyLock = + LazyLock::new(|| [env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect()); +static INPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| TESTS_FOLDER_PATH.join("inputs")); +pub static MACROTEST_INPUT_FOLDER_PATH: LazyLock = + LazyLock::new(|| INPUTS_FOLDER_PATH.join("macrotest")); +pub static TRYBUILD_INPUT_FOLDER_PATH: LazyLock = + LazyLock::new(|| INPUTS_FOLDER_PATH.join("trybuild")); +static OUTPUTS_FOLDER_PATH: LazyLock = LazyLock::new(|| TESTS_FOLDER_PATH.join("outputs")); +static TOOLCHAIN_SPECIFIC_OUTPUTS_FOLDER_PATH: LazyLock = + LazyLock::new(|| OUTPUTS_FOLDER_PATH.join(TOOLCHAIN_CHANNEL_NAME)); pub static MACROTEST_OUTPUT_FOLDER_PATH: LazyLock = - 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 = - 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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs index 9fb796e2..448b77e3 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs index 4879caef..e6df5925 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs index 0acc066e..285724a6 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs index c58d02b8..34000471 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs index e30be581..029e38ca 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs index 7183b4d5..807fa0e0 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs index 51e6fa3d..8cd2eea4 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs @@ -9,21 +9,22 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { pub unsafe fn wdf_spin_lock_acquire_impl(spin_lock__: WDFSPINLOCK) { let wdf_function: wdk_sys::PFN_WDFSPINLOCKACQUIRE = 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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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::WdfSpinLockAcquireTableIndex diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs index 76c49beb..5d5b999b 100644 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs @@ -9,21 +9,22 @@ fn foo() { pub unsafe fn wdf_verifier_dbg_break_point_impl() { let wdf_function: wdk_sys::PFN_WDFVERIFIERDBGBREAKPOINT = 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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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::WdfVerifierDbgBreakPointTableIndex diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs index 9fb796e2..448b77e3 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs index 4879caef..e6df5925 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs index 0acc066e..285724a6 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs index c58d02b8..34000471 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs index e30be581..029e38ca 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs index 7183b4d5..807fa0e0 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs index 51e6fa3d..8cd2eea4 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded.rs @@ -9,21 +9,22 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { pub unsafe fn wdf_spin_lock_acquire_impl(spin_lock__: WDFSPINLOCK) { let wdf_function: wdk_sys::PFN_WDFSPINLOCKACQUIRE = 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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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::WdfSpinLockAcquireTableIndex diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs index 27a03946..e06fecc4 100644 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded.rs @@ -9,21 +9,22 @@ fn foo() { pub unsafe fn wdf_verifier_dbg_break_point_impl() { let wdf_function: wdk_sys::PFN_WDFVERIFIERDBGBREAKPOINT = 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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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::WdfVerifierDbgBreakPointTableIndex diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs index 9fb796e2..448b77e3 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs index 4879caef..e6df5925 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs index 0acc066e..285724a6 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs index c58d02b8..34000471 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs index e30be581..029e38ca 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs index 7183b4d5..807fa0e0 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.expanded.rs @@ -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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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 diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs index 51e6fa3d..8cd2eea4 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs @@ -9,21 +9,22 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { pub unsafe fn wdf_spin_lock_acquire_impl(spin_lock__: WDFSPINLOCK) { let wdf_function: wdk_sys::PFN_WDFSPINLOCKACQUIRE = 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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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::WdfSpinLockAcquireTableIndex diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs index 951408b7..afac793b 100644 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs @@ -9,21 +9,22 @@ fn foo() { pub unsafe fn wdf_verifier_dbg_break_point_impl() { let wdf_function: wdk_sys::PFN_WDFVERIFIERDBGBREAKPOINT = 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::(), ) .is_ok() { ::core::panicking::panic( - "assertion failed: isize::try_from(wdk_sys::wdf::WDF_FUNCTION_COUNT *\n core::mem::size_of::()).is_ok()", + "assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::()).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::WdfVerifierDbgBreakPointTableIndex diff --git a/tests/wdk-sys-tests/Cargo.lock b/tests/wdk-sys-tests/Cargo.lock index bfed4173..47bc1fe4 100644 --- a/tests/wdk-sys-tests/Cargo.lock +++ b/tests/wdk-sys-tests/Cargo.lock @@ -719,7 +719,6 @@ dependencies = [ "bindgen", "cargo_metadata", "cc", - "once_cell", "rustversion", "serde_json", "thiserror", From dba3ef0f7f78e147df4626966341a112cac80141 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 11 Dec 2024 16:57:18 -0800 Subject: [PATCH 11/12] finished nightly clippy check --- crates/wdk-sys/build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 3047b26a..4bf45a7c 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -44,12 +44,12 @@ const WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL: &str = const WDF_FUNCTION_COUNT_DECLARATION_TABLE_INDEX: &str = "crate::_WDFFUNCENUM::WdfFunctionTableNumEntries as usize"; -const WDF_FUNCTION_COUNT_FUNCTION_TEMPLATE: LazyLock = LazyLock::new(|| { +static WDF_FUNCTION_COUNT_FUNCTION_TEMPLATE: LazyLock = LazyLock::new(|| { format!( - r#"/// function to access the value of the number of functions in the WDF function table. + 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} -}}"# +}}" ) }); From 9075140ea9f0d4327d8b69eab0e437e3f0ce643f Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 11 Dec 2024 17:18:11 -0800 Subject: [PATCH 12/12] added doc comment for EXPORTED_CFG_SETTINGS --- crates/wdk-build/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index ee4dfe20..fd91da79 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -981,6 +981,9 @@ pub fn configure_wdk_binary_build() -> Result<(), ConfigError> { Config::from_env_auto()?.configure_binary_build() } +/// This currently only exports the driver type, but may export more metadata in +/// the future. `EXPORTED_CFG_SETTINGS` is a mapping of cfg key to allowed cfg +/// values static EXPORTED_CFG_SETTINGS: LazyLock)>> = LazyLock::new(|| vec![("DRIVER_MODEL-DRIVER_TYPE", vec!["WDM", "KMDF", "UMDF"])]);