From 0b755a5c08c160602509db0dabc229cf7380c02c Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 31 Jul 2025 17:32:08 -0700 Subject: [PATCH 01/32] Migration to Rust 2024 --- .vscode/settings.json | 3 +- CONTRIBUTING.md | 3 +- Cargo.toml | 12 ++-- README.md | 2 +- .../cargo-wdk/src/actions/build/build_task.rs | 2 +- crates/cargo-wdk/src/actions/build/mod.rs | 2 +- crates/cargo-wdk/src/actions/build/tests.rs | 52 ++++++++--------- crates/cargo-wdk/src/actions/new/mod.rs | 2 +- crates/cargo-wdk/src/cli.rs | 6 +- crates/cargo-wdk/src/providers/fs.rs | 2 +- crates/cargo-wdk/tests/common.rs | 12 +++- .../crates/driver_1/src/lib.rs | 2 +- .../crates/driver_2/src/lib.rs | 2 +- .../crates/driver/src/lib.rs | 2 +- crates/cargo-wdk/tests/new_command_test.rs | 50 ++++++++++------ crates/cargo-wdk/tests/umdf-driver/src/lib.rs | 2 +- crates/wdk-alloc/src/lib.rs | 2 +- crates/wdk-build/rust-driver-makefile.toml | 5 +- crates/wdk-build/src/bindgen.rs | 2 +- crates/wdk-build/src/cargo_make.rs | 58 ++++++++++++++----- crates/wdk-build/src/lib.rs | 18 +++++- crates/wdk-build/src/metadata/map.rs | 2 +- crates/wdk-build/src/metadata/mod.rs | 2 +- crates/wdk-build/src/metadata/ser.rs | 8 +-- crates/wdk-build/src/utils.rs | 12 ++-- crates/wdk-sys/build.rs | 8 +-- crates/wdk-sys/src/lib.rs | 4 +- crates/wdk-sys/src/test_stubs.rs | 4 +- crates/wdk/src/print.rs | 18 ++---- crates/wdk/src/wdf/spinlock.rs | 4 +- crates/wdk/src/wdf/timer.rs | 6 +- examples/sample-kmdf-driver/src/lib.rs | 2 +- examples/sample-umdf-driver/src/lib.rs | 2 +- examples/sample-wdm-driver/src/lib.rs | 2 +- .../crates/driver/src/lib.rs | 2 +- .../crates/driver_1/src/lib.rs | 2 +- .../crates/driver_2/src/lib.rs | 2 +- .../inputs/macrotest/bug_unused_imports.rs | 2 +- .../inputs/macrotest/wdf_driver_create.rs | 2 +- .../trybuild/wdf_api_that_does_not_exist.rs | 2 +- .../trybuild/wdf_driver_create_missing_arg.rs | 2 +- .../wdf_driver_create_wrong_arg_order.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- 48 files changed, 201 insertions(+), 142 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index fa9e9b637..e59b8597b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,5 +21,6 @@ "./tests/wdk-macros-tests/Cargo.toml", "./tests/wdk-sys-tests/Cargo.toml", ], - "rust-analyzer.cargo.features": "all" + "rust-analyzer.cargo.features": "all", + "rust-analyzer.checkOnSave": false } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69d4337e4..69ff655f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,9 +87,10 @@ That's it! Thank you for your contribution! The following tools should be installed as a part of the `windows-drivers-rs` developer workflow: -* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.85` * `cargo-audit`: `cargo install --locked cargo-audit` +* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.85` * `cargo-machete`: `cargo install --locked cargo-machete` +* `cargo-sort`: `cargo install --locked cargo-sort` * `taplo-cli`: `cargo install --locked taplo-cli` **Note on arm64:** ARM64 support for ring is [not released yet](https://github.com/briansmith/ring/issues/1167), so TLS features must be disabled until arm64 is officially supported by ring (probably in 0.17.0 release) diff --git a/Cargo.toml b/Cargo.toml index 45bee2e12..90e82d345 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ exclude = [ resolver = "3" [workspace.package] -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" repository = "https://github.com/microsoft/windows-drivers-rs" readme = "README.md" license = "MIT OR Apache-2.0" @@ -67,10 +67,10 @@ windows = "0.58.0" # The following workspace.metadata.wdk sections can be uncommented to configure the workspace for a specific WDK configuration (ex. for rust-analyzer to resolve things for a specific configuration) # Uncomment the section below for KMDF -# [workspace.metadata.wdk.driver-model] -# driver-type = "KMDF" -# kmdf-version-major = 1 -# target-kmdf-version-minor = 33 +[workspace.metadata.wdk.driver-model] +driver-type = "KMDF" +kmdf-version-major = 1 +target-kmdf-version-minor = 33 # Uncomment the section below for UMDF # [workspace.metadata.wdk.driver-model] diff --git a/README.md b/README.md index b936e77dd..bda034389 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ The crates in this repository are available from [`crates.io`](https://crates.io PCUNICODE_STRING, }; - #[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry + #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/src/actions/build/build_task.rs b/crates/cargo-wdk/src/actions/build/build_task.rs index 7d01a2e21..80edef3a0 100644 --- a/crates/cargo-wdk/src/actions/build/build_task.rs +++ b/crates/cargo-wdk/src/actions/build/build_task.rs @@ -15,7 +15,7 @@ use wdk_build::utils::{PathExt, StripExtendedPathPrefixError}; #[double] use crate::providers::{exec::CommandExec, fs::Fs}; use crate::{ - actions::{build::error::BuildTaskError, to_target_triple, Profile, TargetArch}, + actions::{Profile, TargetArch, build::error::BuildTaskError, to_target_triple}, trace, }; diff --git a/crates/cargo-wdk/src/actions/build/mod.rs b/crates/cargo-wdk/src/actions/build/mod.rs index 7a2a4df8f..ea39fa042 100644 --- a/crates/cargo-wdk/src/actions/build/mod.rs +++ b/crates/cargo-wdk/src/actions/build/mod.rs @@ -26,7 +26,7 @@ use package_task::{PackageTask, PackageTaskParams}; use tracing::{debug, error as err, info, warn}; use wdk_build::metadata::{TryFromCargoMetadataError, Wdk}; -use crate::actions::{to_target_triple, Profile, TargetArch}; +use crate::actions::{Profile, TargetArch, to_target_triple}; #[double] use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild}; diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index 184184b45..a11f5b076 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -14,9 +14,9 @@ use cargo_metadata::Metadata as CargoMetadata; use mockall::predicate::eq; use mockall_double::double; use wdk_build::{ - metadata::{TryFromCargoMetadataError, Wdk}, CpuArchitecture, DriverConfig, + metadata::{TryFromCargoMetadataError, Wdk}, }; #[double] @@ -28,10 +28,10 @@ use crate::providers::{ }; use crate::{ actions::{ - build::{BuildAction, BuildActionError, BuildActionParams}, - to_target_triple, Profile, TargetArch, + build::{BuildAction, BuildActionError, BuildActionParams}, + to_target_triple, }, providers::error::{CommandError, FileError}, }; @@ -270,8 +270,8 @@ pub fn given_a_driver_project_when_target_arch_is_arm64_then_it_builds_successfu } #[test] -pub fn given_a_driver_project_when_profile_is_release_and_target_arch_is_arm64_then_it_builds_successfully( -) { +pub fn given_a_driver_project_when_profile_is_release_and_target_arch_is_arm64_then_it_builds_successfully() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = Some(Profile::Release); @@ -1198,8 +1198,8 @@ pub fn given_a_driver_project_when_infverif_command_execution_fails_then_package } #[test] -pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_metadata_are_provided_then_build_should_be_successful( -) { +pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_metadata_are_provided_then_build_should_be_successful() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1245,8 +1245,8 @@ pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_m } #[test] -pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_default_values_are_provided_then_wdk_metadata_parse_should_fail( -) { +pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_default_values_are_provided_then_wdk_metadata_parse_should_fail() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp\\sample-driver"); let profile = None; @@ -1298,8 +1298,8 @@ pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_defau /// Workspace tests //////////////////////////////////////////////////////////////////////////////// #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_default_values_are_provided_then_it_packages_successfully( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_default_values_are_provided_then_it_packages_successfully() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1425,8 +1425,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_defau } #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_driver_project_then_it_packages_driver_project_successfully( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_driver_project_then_it_packages_driver_project_successfully() + { // Input CLI args let workspace_root_dir = PathBuf::from("C:\\tmp"); let cwd = workspace_root_dir.join("sample-kmdf-1"); @@ -1538,8 +1538,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_i } #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verify_signature_is_false_then_it_skips_verify_tasks( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verify_signature_is_false_then_it_skips_verify_tasks() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1661,8 +1661,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verif } #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_non_driver_project_then_it_builds_but_skips_packaging( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_non_driver_project_then_it_builds_but_skips_packaging() + { // Input CLI args let workspace_root_dir = PathBuf::from("C:\\tmp"); let cwd = workspace_root_dir.join("non-driver"); @@ -1740,8 +1740,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_i } #[test] -pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail( -) { +pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1819,8 +1819,8 @@ pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_works } #[test] -pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail( -) { +pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1898,8 +1898,8 @@ pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_w } #[test] -pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_root_then_build_should_be_successful( -) { +pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_root_then_build_should_be_successful() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1950,8 +1950,8 @@ pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_roo } #[test] -pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_member_then_build_should_be_successful( -) { +pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_member_then_build_should_be_successful() + { // Input CLI args let workspace_root_dir = PathBuf::from("C:\\tmp"); let cwd = workspace_root_dir.join("non-driver"); @@ -2048,7 +2048,7 @@ trait TestSetupPackageExpectations { override_output: Option, ) -> Self; fn expect_inx_file_exists(self, driver_name: &str, driver_dir: &Path, does_exist: bool) - -> Self; + -> Self; fn expect_rename_driver_binary_dll_to_sys(self, driver_name: &str, driver_dir: &Path) -> Self; fn expect_copy_driver_binary_sys_to_package_folder( self, diff --git a/crates/cargo-wdk/src/actions/new/mod.rs b/crates/cargo-wdk/src/actions/new/mod.rs index 7e7451fe9..3067bb1d6 100644 --- a/crates/cargo-wdk/src/actions/new/mod.rs +++ b/crates/cargo-wdk/src/actions/new/mod.rs @@ -15,7 +15,7 @@ use std::{ use clap_verbosity_flag::Verbosity; use error::NewActionError; -use include_dir::{include_dir, Dir}; +use include_dir::{Dir, include_dir}; use mockall_double::double; use tracing::{debug, info}; diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index ef5b71759..1e147a267 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -12,14 +12,14 @@ use mockall_double::double; use wdk_build::CpuArchitecture; use crate::actions::{ - build::{BuildAction, BuildActionParams}, - new::NewAction, DriverType, + KMDF_STR, Profile, TargetArch, - KMDF_STR, UMDF_STR, WDM_STR, + build::{BuildAction, BuildActionParams}, + new::NewAction, }; #[double] use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild}; diff --git a/crates/cargo-wdk/src/providers/fs.rs b/crates/cargo-wdk/src/providers/fs.rs index 610c71218..5444b76ea 100644 --- a/crates/cargo-wdk/src/providers/fs.rs +++ b/crates/cargo-wdk/src/providers/fs.rs @@ -11,7 +11,7 @@ #![allow(clippy::unused_self)] use std::{ - fs::{copy, create_dir, read_dir, rename, DirEntry, File, FileType, OpenOptions}, + fs::{DirEntry, File, FileType, OpenOptions, copy, create_dir, read_dir, rename}, io::{Read, Write}, path::{Path, PathBuf}, }; diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index 345bdfeda..c565e367d 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -14,10 +14,18 @@ use fs4::fs_std::FileExt; pub fn set_crt_static_flag() { if let Ok(rustflags) = std::env::var("RUSTFLAGS") { let updated_rust_flags = format!("{rustflags} -C target-feature=+crt-static"); - std::env::set_var("RUSTFLAGS", updated_rust_flags); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var("RUSTFLAGS", updated_rust_flags); + } println!("RUSTFLAGS set, adding the +crt-static: {rustflags:?}"); } else { - std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); + } println!( "No RUSTFLAGS set, setting it to: {:?}", std::env::var("RUSTFLAGS").expect("RUSTFLAGS not set") diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs index 71623cce9..567b757ae 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs index 71623cce9..567b757ae 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index 289d22f59..e4587f2d7 100644 --- a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -47,7 +47,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/tests/new_command_test.rs b/crates/cargo-wdk/tests/new_command_test.rs index 56b6d3e62..b50c87cac 100644 --- a/crates/cargo-wdk/tests/new_command_test.rs +++ b/crates/cargo-wdk/tests/new_command_test.rs @@ -4,7 +4,7 @@ mod common; use std::path::PathBuf; use assert_cmd::Command; -use assert_fs::{assert::PathAssert, prelude::PathChild, TempDir}; +use assert_fs::{TempDir, assert::PathAssert, prelude::PathChild}; use common::{set_crt_static_flag, with_file_lock}; use mockall::PredicateBooleanExt; @@ -65,10 +65,16 @@ fn project_is_created(driver_type: &str) { assert!(stdout.contains( "Required directive Provider missing, empty, or invalid in [Version] section." )); - assert!(stdout - .contains("Required directive Class missing, empty, or invalid in [Version] section.")); - assert!(stdout - .contains("Invalid ClassGuid \"\", expecting {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}.")); + assert!( + stdout.contains( + "Required directive Class missing, empty, or invalid in [Version] section." + ) + ); + assert!( + stdout.contains( + "Invalid ClassGuid \"\", expecting {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}." + ) + ); assert!(stdout.contains("INF is NOT VALID")); }); } @@ -143,20 +149,26 @@ fn create_and_build_new_driver_project(driver_type: &str) -> (String, String) { assert!(tmp_dir.join(&driver_name).is_dir()); assert!(tmp_dir.join(&driver_name).join("build.rs").is_file()); assert!(tmp_dir.join(&driver_name).join("Cargo.toml").is_file()); - assert!(tmp_dir - .join(&driver_name) - .join(format!("{driver_name_underscored}.inx")) - .is_file()); - assert!(tmp_dir - .join(&driver_name) - .join("src") - .join("lib.rs") - .is_file()); - assert!(tmp_dir - .join(&driver_name) - .join(".cargo") - .join("config.toml") - .is_file()); + assert!( + tmp_dir + .join(&driver_name) + .join(format!("{driver_name_underscored}.inx")) + .is_file() + ); + assert!( + tmp_dir + .join(&driver_name) + .join("src") + .join("lib.rs") + .is_file() + ); + assert!( + tmp_dir + .join(&driver_name) + .join(".cargo") + .join("config.toml") + .is_file() + ); // assert content let driver_name_path = PathBuf::from(&driver_name); diff --git a/crates/cargo-wdk/tests/umdf-driver/src/lib.rs b/crates/cargo-wdk/tests/umdf-driver/src/lib.rs index 71623cce9..567b757ae 100644 --- a/crates/cargo-wdk/tests/umdf-driver/src/lib.rs +++ b/crates/cargo-wdk/tests/umdf-driver/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 1a8b72829..99319669b 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -31,10 +31,10 @@ mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; use wdk_sys::{ - ntddk::{ExAllocatePool2, ExFreePool}, POOL_FLAG_NON_PAGED, SIZE_T, ULONG, + ntddk::{ExAllocatePool2, ExFreePool}, }; /// Allocator implementation to use with `#[global_allocator]` to allow use diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index 6b8009395..ace26fd2d 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -158,7 +158,10 @@ let serialized_wdk_metadata_map = wdk_build::metadata::to_map_with_prefix:: impl IntoIterator { }; if let Some(toolchain) = toolchain_arg { - env::set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); + } } CommandLineInterface::parse_from(env_args.iter()).parse_cargo_args(); @@ -637,7 +649,11 @@ pub fn setup_wdk_version() -> Result, ConfigErr }); } - env::set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); + } Ok([WDK_VERSION_ENV_VAR].map(std::string::ToString::to_string)) } @@ -666,7 +682,7 @@ pub fn setup_infverif_for_samples + ToString + ?Sized>( .expect("Unable to parse the build number of the WDK version string as an int!"); let sample_flag = if version > MINIMUM_SAMPLES_FLAG_WDK_VERSION { "/samples" // Note: Not currently implemented, so in samples TOML we - // currently skip infverif + // currently skip infverif } else { "/msft" }; @@ -1107,10 +1123,14 @@ fn configure_wdf_build_output_dir(target_arg: Option<&String>, cargo_make_cargo_ output_dir }; - env::set_var( - WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, - wdk_build_output_directory, - ); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var( + WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, + wdk_build_output_directory, + ); + } } fn append_to_space_delimited_env_var(env_var_name: S, string_to_append: T) @@ -1124,7 +1144,11 @@ where let mut env_var_value: String = env::var(env_var_name).unwrap_or_default(); env_var_value.push(' '); env_var_value.push_str(string_to_append); - env::set_var(env_var_name, env_var_value.trim()); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(env_var_name, env_var_value.trim()); + } } fn prepend_to_semicolon_delimited_env_var(env_var_name: S, string_to_prepend: T) @@ -1138,7 +1162,11 @@ where let mut env_var_value = string_to_prepend.to_string(); env_var_value.push(';'); env_var_value.push_str(env::var(env_var_name).unwrap_or_default().as_str()); - env::set_var(env_var_name, env_var_value); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(env_var_name, env_var_value); + } } /// `cargo-make` condition script for `infverif` task in diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 16f10ffc1..8cf0a27f2 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -1483,7 +1483,11 @@ mod tests { "Duplicate environment variable keys were provided" ); } - std::env::set_var(key, value); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var(key, value); + } } let f_return_value = f(); @@ -1492,10 +1496,18 @@ mod tests { for (key, _) in env_vars_key_value_pairs { original_env_vars.get(key).map_or_else( || { - std::env::remove_var(key); + // SAFETY: env::remove_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::remove_var(key); + } }, |value| { - std::env::set_var(key, value); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var(key, value); + } }, ); } diff --git a/crates/wdk-build/src/metadata/map.rs b/crates/wdk-build/src/metadata/map.rs index 492b3ae3f..ad5a94bb4 100644 --- a/crates/wdk-build/src/metadata/map.rs +++ b/crates/wdk-build/src/metadata/map.rs @@ -2,7 +2,7 @@ // License: MIT OR Apache-2.0 use std::{ - collections::{btree_map, hash_map, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, btree_map, hash_map}, hash::{BuildHasher, Hash}, }; diff --git a/crates/wdk-build/src/metadata/mod.rs b/crates/wdk-build/src/metadata/mod.rs index 8dd01d4b2..03c363545 100644 --- a/crates/wdk-build/src/metadata/mod.rs +++ b/crates/wdk-build/src/metadata/mod.rs @@ -11,7 +11,7 @@ pub use error::{Error, Result}; pub use map::Map; -pub use ser::{to_map, to_map_with_prefix, Serializer}; +pub use ser::{Serializer, to_map, to_map_with_prefix}; pub(crate) mod ser; diff --git a/crates/wdk-build/src/metadata/ser.rs b/crates/wdk-build/src/metadata/ser.rs index fd4f18948..74288ac10 100644 --- a/crates/wdk-build/src/metadata/ser.rs +++ b/crates/wdk-build/src/metadata/ser.rs @@ -2,8 +2,8 @@ // License: MIT OR Apache-2.0 use serde::{ - ser::{self, Impossible}, Serialize, + ser::{self, Impossible}, }; use super::{ @@ -31,9 +31,9 @@ pub const KEY_NAME_SEPARATOR: char = '-'; /// use std::collections::BTreeMap; /// /// use wdk_build::{ -/// metadata::{self, to_map}, /// DriverConfig, /// KmdfConfig, +/// metadata::{self, to_map}, /// }; /// /// let wdk_metadata = metadata::Wdk { @@ -78,9 +78,9 @@ where /// use std::collections::BTreeMap; /// /// use wdk_build::{ -/// metadata::{self, to_map_with_prefix}, /// DriverConfig, /// KmdfConfig, +/// metadata::{self, to_map_with_prefix}, /// }; /// /// let wdk_metadata = metadata::Wdk { @@ -587,7 +587,7 @@ mod tests { }; use super::*; - use crate::{metadata, DriverConfig, KmdfConfig, UmdfConfig}; + use crate::{DriverConfig, KmdfConfig, UmdfConfig, metadata}; #[test] fn test_kmdf() { diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 3b69ca648..ec1b48ef8 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -14,16 +14,16 @@ use std::{ 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, }, + core::{PCSTR, s}, }; use crate::{ConfigError, CpuArchitecture}; @@ -703,8 +703,8 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ FOLDERID_ProgramFiles, - SHGetKnownFolderPath, KF_FLAG_DEFAULT, + SHGetKnownFolderPath, }; use super::*; @@ -919,7 +919,7 @@ mod tests { temp_dir.child("a.b").create_dir_all().unwrap(); // Invalid: non-numeric temp_dir.child("not_version").touch().unwrap(); // File: ignored temp_dir.child("3.0").touch().unwrap(); // File: ignored - // Should find the maximum among valid version directories only + // Should find the maximum among valid version directories only assert_eq!( find_max_version_in_directory(temp_dir.path()).unwrap(), TwoPartVersion(2, 0) diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 547b6483e..c5e4614a6 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -18,13 +18,12 @@ use std::{ use anyhow::Context; use bindgen::CodegenConfig; -use tracing::{info, info_span, trace, Span}; +use tracing::{Span, info, info_span, trace}; use tracing_subscriber::{ - filter::{LevelFilter, ParseError}, EnvFilter, + filter::{LevelFilter, ParseError}, }; use wdk_build::{ - configure_wdk_library_build_and_then, ApiSubset, BuilderExt, Config, @@ -32,6 +31,7 @@ use wdk_build::{ DriverConfig, KmdfConfig, UmdfConfig, + configure_wdk_library_build_and_then, }; const OUT_DIR_PLACEHOLDER: &str = @@ -120,7 +120,7 @@ static TEST_STUBS_TEMPLATE: LazyLock = LazyLock::new(|| { use crate::WDFFUNC; /// Stubbed version of the symbol that `WdfFunctions` links to so that test targets will compile -#[no_mangle] +#[unsafe(no_mangle)] pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); ", ) diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index f7d387bbb..6d3c69c24 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -117,14 +117,14 @@ mod macros; // necessary due to LLVM being too eager to set it: it checks the LLVM IR for // floating point instructions - even if soft-float is enabled! #[allow(missing_docs)] -#[no_mangle] +#[unsafe(no_mangle)] pub static _fltused: () = (); // FIXME: Is there any way to avoid this stub? See https://github.com/rust-lang/rust/issues/101134 #[cfg(panic = "abort")] #[allow(missing_docs)] #[allow(clippy::missing_const_for_fn)] // const extern is not yet supported: https://github.com/rust-lang/rust/issues/64926 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn __CxxFrameHandler3() -> i32 { 0 } diff --git a/crates/wdk-sys/src/test_stubs.rs b/crates/wdk-sys/src/test_stubs.rs index b9bff9880..debdc9bd5 100644 --- a/crates/wdk-sys/src/test_stubs.rs +++ b/crates/wdk-sys/src/test_stubs.rs @@ -27,7 +27,7 @@ use crate::{DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING}; driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF" ))] -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub const unsafe extern "system" fn driver_entry_stub( _driver: &mut DRIVER_OBJECT, _registry_path: PCUNICODE_STRING, @@ -41,7 +41,7 @@ mod wdf { /// Stubbed version of `WdfFunctionCount` Symbol so that test targets will /// compile - #[no_mangle] + #[unsafe(no_mangle)] pub static mut WdfFunctionCount: ULONG = 0; include!(concat!(env!("OUT_DIR"), "/test_stubs.rs")); diff --git a/crates/wdk/src/print.rs b/crates/wdk/src/print.rs index bcbf26f82..5a0d1848f 100644 --- a/crates/wdk/src/print.rs +++ b/crates/wdk/src/print.rs @@ -90,7 +90,7 @@ pub fn _print(args: fmt::Arguments) { if #[cfg(any(driver_model__driver_type = "WDM", driver_model__driver_type = "KMDF"))] { let mut buffered_writer = dbg_print_buf_writer::DbgPrintBufWriter::new(); - if let Ok(_) = fmt::write(&mut buffered_writer, args) { + if fmt::write(&mut buffered_writer, args).is_ok() { buffered_writer.flush(); } else { unreachable!("DbgPrintBufWriter should never fail to write"); @@ -235,11 +235,10 @@ mod dbg_print_buf_writer { // Helper function to advance the start of a `u8` slice to the next non-null // byte. Returns an empty slice if all bytes are null. fn advance_slice_to_next_non_null_byte(slice: &[u8]) -> &[u8] { - if let Some(pos) = slice.iter().position(|&b| b != b'\0') { - &slice[pos..] - } else { - &slice[slice.len()..] - } + slice + .iter() + .position(|&b| b != b'\0') + .map_or_else(|| &slice[slice.len()..], |pos| &slice[pos..]) } #[cfg(test)] @@ -273,7 +272,7 @@ mod dbg_print_buf_writer { // Check that the string is null-terminated at the end of the buffer. assert_eq!(writer.buffer[old_used], b'\0'); // Check that the string isn't null-terminated at the beginning of the buffer. - assert_ne!(writer.buffer[0], b'\0') + assert_ne!(writer.buffer[0], b'\0'); } #[test] @@ -352,8 +351,6 @@ mod dbg_print_buf_writer { characters long to ensure that the DbgPrintBufWriter's buffer overflow handling \ is thoroughly tested."; const TEST_STRING_LEN: usize = TEST_STRING.len(); - const UNFLUSHED_STRING_CONTENTS_STARTING_INDEX: usize = - TEST_STRING_LEN - (TEST_STRING_LEN % DbgPrintBufWriter::USABLE_BUFFER_SIZE); const { assert!( @@ -362,9 +359,6 @@ mod dbg_print_buf_writer { ); } - let expected_unflushed_string_contents = - &TEST_STRING[UNFLUSHED_STRING_CONTENTS_STARTING_INDEX..]; - let mut writer = DbgPrintBufWriter::new(); // set the last byte to 1 to ensure that the buffer is not automatically diff --git a/crates/wdk/src/wdf/spinlock.rs b/crates/wdk/src/wdf/spinlock.rs index 0edd567ee..b60013211 100644 --- a/crates/wdk/src/wdf/spinlock.rs +++ b/crates/wdk/src/wdf/spinlock.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation // License: MIT OR Apache-2.0 -use wdk_sys::{call_unsafe_wdf_function_binding, NTSTATUS, WDFSPINLOCK, WDF_OBJECT_ATTRIBUTES}; +use wdk_sys::{NTSTATUS, WDF_OBJECT_ATTRIBUTES, WDFSPINLOCK, call_unsafe_wdf_function_binding}; use crate::nt_success; @@ -40,7 +40,7 @@ impl SpinLock { nt_status = call_unsafe_wdf_function_binding!( WdfSpinLockCreate, attributes, - &mut spin_lock.wdf_spin_lock, + &raw mut spin_lock.wdf_spin_lock, ); } nt_success(nt_status).then_some(spin_lock).ok_or(nt_status) diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 7535ca027..760688aba 100644 --- a/crates/wdk/src/wdf/timer.rs +++ b/crates/wdk/src/wdf/timer.rs @@ -2,11 +2,11 @@ // License: MIT OR Apache-2.0 use wdk_sys::{ - call_unsafe_wdf_function_binding, NTSTATUS, - WDFTIMER, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, + WDFTIMER, + call_unsafe_wdf_function_binding, }; use crate::nt_success; @@ -38,7 +38,7 @@ impl Timer { WdfTimerCreate, timer_config, attributes, - &mut timer.wdf_timer, + &raw mut timer.wdf_timer, ); } nt_success(nt_status).then_some(timer).ok_or(nt_status) diff --git a/examples/sample-kmdf-driver/src/lib.rs b/examples/sample-kmdf-driver/src/lib.rs index 050013455..f04c842c7 100644 --- a/examples/sample-kmdf-driver/src/lib.rs +++ b/examples/sample-kmdf-driver/src/lib.rs @@ -51,7 +51,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/examples/sample-umdf-driver/src/lib.rs b/examples/sample-umdf-driver/src/lib.rs index 9c9968f42..9d296ee58 100644 --- a/examples/sample-umdf-driver/src/lib.rs +++ b/examples/sample-umdf-driver/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/examples/sample-wdm-driver/src/lib.rs b/examples/sample-wdm-driver/src/lib.rs index fa7d3348d..9bde8609f 100644 --- a/examples/sample-wdm-driver/src/lib.rs +++ b/examples/sample-wdm-driver/src/lib.rs @@ -30,7 +30,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDM -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index 1ea37391d..375e6f4b8 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -51,7 +51,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs index dd498498c..3f94cf937 100644 --- a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs index dd498498c..3f94cf937 100644 --- a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs index f31966413..9b0d5c200 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs @@ -36,7 +36,7 @@ use wdk_sys::{ WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs index 4b09d3535..095d067d9 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs @@ -3,7 +3,7 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs index deb7c4f36..9e71fb85e 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs @@ -5,7 +5,7 @@ use wdk_sys::*; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs index fc8f46ce7..25548ccf1 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs @@ -5,7 +5,7 @@ use wdk_sys::*; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs index f07cb6fbd..18265a810 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -5,7 +5,7 @@ use wdk_sys::*; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 fb3d47552..b1451a812 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 @@ -23,7 +23,7 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 2f60cd9a4..d99bbb959 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 @@ -1,6 +1,6 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, 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 fb3d47552..b1451a812 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 @@ -23,7 +23,7 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 2f60cd9a4..d99bbb959 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 @@ -1,6 +1,6 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, 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 fb3d47552..b1451a812 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 @@ -23,7 +23,7 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 2f60cd9a4..d99bbb959 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 @@ -1,6 +1,6 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, From ed382b469641e8a6b7e9361289f4b5ad96a281ce Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 31 Jul 2025 17:34:57 -0700 Subject: [PATCH 02/32] Recommented driver configuration --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90e82d345..140740aa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,10 +67,10 @@ windows = "0.58.0" # The following workspace.metadata.wdk sections can be uncommented to configure the workspace for a specific WDK configuration (ex. for rust-analyzer to resolve things for a specific configuration) # Uncomment the section below for KMDF -[workspace.metadata.wdk.driver-model] -driver-type = "KMDF" -kmdf-version-major = 1 -target-kmdf-version-minor = 33 +# [workspace.metadata.wdk.driver-model] +# driver-type = "KMDF" +# kmdf-version-major = 1 +# target-kmdf-version-minor = 33 # Uncomment the section below for UMDF # [workspace.metadata.wdk.driver-model] From e5cf36119b6bfed2e3fc1ec33b57ccf79aef304e Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 31 Jul 2025 17:42:46 -0700 Subject: [PATCH 03/32] removed check on save blocker in vscode config --- .vscode/settings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e59b8597b..fa9e9b637 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,6 +21,5 @@ "./tests/wdk-macros-tests/Cargo.toml", "./tests/wdk-sys-tests/Cargo.toml", ], - "rust-analyzer.cargo.features": "all", - "rust-analyzer.checkOnSave": false + "rust-analyzer.cargo.features": "all" } From 4f3bb0255b676b0654f2b859d3e5c1b25160dcff Mon Sep 17 00:00:00 2001 From: leon-xd Date: Mon, 4 Aug 2025 11:55:29 -0700 Subject: [PATCH 04/32] Addressed comments --- crates/cargo-wdk/src/actions/build/tests.rs | 11 +- crates/cargo-wdk/src/cli.rs | 7 +- crates/cargo-wdk/tests/common.rs | 13 +- crates/wdk-alloc/src/lib.rs | 4 +- crates/wdk-build/rust-driver-makefile.toml | 5 +- crates/wdk-build/src/cargo_make.rs | 58 ++----- crates/wdk-build/src/lib.rs | 19 +-- crates/wdk-build/src/utils.rs | 159 ++++++++++++++++-- crates/wdk-macros/src/lib.rs | 30 +--- crates/wdk-sys/build.rs | 10 +- crates/wdk-sys/src/lib.rs | 7 +- crates/wdk-sys/src/test_stubs.rs | 4 +- crates/wdk/src/print.rs | 6 +- crates/wdk/src/wdf/timer.rs | 6 +- examples/sample-kmdf-driver/src/lib.rs | 2 + examples/sample-umdf-driver/src/lib.rs | 2 + examples/sample-wdm-driver/src/lib.rs | 2 + .../crates/driver/src/lib.rs | 2 + .../crates/driver_1/src/lib.rs | 2 + .../crates/driver_2/src/lib.rs | 2 + .../inputs/macrotest/bug_unused_imports.rs | 2 + .../trybuild/wdf_api_that_does_not_exist.rs | 2 + .../trybuild/wdf_driver_create_missing_arg.rs | 2 + .../wdf_driver_create_wrong_arg_order.rs | 2 + 24 files changed, 212 insertions(+), 147 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index a11f5b076..e16540a6b 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -14,22 +14,17 @@ use cargo_metadata::Metadata as CargoMetadata; use mockall::predicate::eq; use mockall_double::double; use wdk_build::{ - CpuArchitecture, - DriverConfig, + CpuArchitecture, DriverConfig, metadata::{TryFromCargoMetadataError, Wdk}, }; #[double] use crate::providers::{ - exec::CommandExec, - fs::Fs, - metadata::Metadata as MetadataProvider, - wdk_build::WdkBuild, + exec::CommandExec, fs::Fs, metadata::Metadata as MetadataProvider, wdk_build::WdkBuild, }; use crate::{ actions::{ - Profile, - TargetArch, + Profile, TargetArch, build::{BuildAction, BuildActionError, BuildActionParams}, to_target_triple, }, diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index 1e147a267..e085a2e3c 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -12,12 +12,7 @@ use mockall_double::double; use wdk_build::CpuArchitecture; use crate::actions::{ - DriverType, - KMDF_STR, - Profile, - TargetArch, - UMDF_STR, - WDM_STR, + DriverType, KMDF_STR, Profile, TargetArch, UMDF_STR, WDM_STR, build::{BuildAction, BuildActionParams}, new::NewAction, }; diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index c565e367d..3ee7d9321 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -3,6 +3,7 @@ #![allow(clippy::literal_string_with_formatting_args)] use fs4::fs_std::FileExt; +use wdk_build::utils::set_var; /// Sets the `RUSTFLAGS` environment variable to include `+crt-static`. /// @@ -14,18 +15,10 @@ use fs4::fs_std::FileExt; pub fn set_crt_static_flag() { if let Ok(rustflags) = std::env::var("RUSTFLAGS") { let updated_rust_flags = format!("{rustflags} -C target-feature=+crt-static"); - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var("RUSTFLAGS", updated_rust_flags); - } + set_var("RUSTFLAGS", updated_rust_flags); println!("RUSTFLAGS set, adding the +crt-static: {rustflags:?}"); } else { - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); - } + set_var("RUSTFLAGS", "-C target-feature=+crt-static"); println!( "No RUSTFLAGS set, setting it to: {:?}", std::env::var("RUSTFLAGS").expect("RUSTFLAGS not set") diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 99319669b..cd9b689c7 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -31,9 +31,7 @@ mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; use wdk_sys::{ - POOL_FLAG_NON_PAGED, - SIZE_T, - ULONG, + POOL_FLAG_NON_PAGED, SIZE_T, ULONG, ntddk::{ExAllocatePool2, ExFreePool}, }; diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index ace26fd2d..2f1299b35 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -158,10 +158,7 @@ let serialized_wdk_metadata_map = wdk_build::metadata::to_map_with_prefix:: impl IntoIterator { }; if let Some(toolchain) = toolchain_arg { - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); - } + set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); } CommandLineInterface::parse_from(env_args.iter()).parse_cargo_args(); @@ -649,11 +633,7 @@ pub fn setup_wdk_version() -> Result, ConfigErr }); } - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); - } + set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); Ok([WDK_VERSION_ENV_VAR].map(std::string::ToString::to_string)) } @@ -1123,14 +1103,10 @@ fn configure_wdf_build_output_dir(target_arg: Option<&String>, cargo_make_cargo_ output_dir }; - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var( - WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, - wdk_build_output_directory, - ); - } + set_var( + WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, + wdk_build_output_directory, + ); } fn append_to_space_delimited_env_var(env_var_name: S, string_to_append: T) @@ -1144,11 +1120,7 @@ where let mut env_var_value: String = env::var(env_var_name).unwrap_or_default(); env_var_value.push(' '); env_var_value.push_str(string_to_append); - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(env_var_name, env_var_value.trim()); - } + set_var(env_var_name, env_var_value.trim()); } fn prepend_to_semicolon_delimited_env_var(env_var_name: S, string_to_prepend: T) @@ -1162,11 +1134,7 @@ where let mut env_var_value = string_to_prepend.to_string(); env_var_value.push(';'); env_var_value.push_str(env::var(env_var_name).unwrap_or_default().as_str()); - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(env_var_name, env_var_value); - } + set_var(env_var_name, env_var_value); } /// `cargo-make` condition script for `infverif` task in diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 8cf0a27f2..74a5bb98f 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -1448,6 +1448,7 @@ mod tests { use assert_fs::TempDir; use super::*; + use crate::utils::{remove_var, set_var}; /// Runs function after modifying environment variables, and returns the /// function's return value. @@ -1483,11 +1484,7 @@ mod tests { "Duplicate environment variable keys were provided" ); } - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var(key, value); - } + set_var(key, value); } let f_return_value = f(); @@ -1496,18 +1493,10 @@ mod tests { for (key, _) in env_vars_key_value_pairs { original_env_vars.get(key).map_or_else( || { - // SAFETY: env::remove_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::remove_var(key); - } + remove_var(key); }, |value| { - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var(key, value); - } + set_var(key, value); }, ); } diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index ec1b48ef8..4e96315f8 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -6,7 +6,7 @@ use std::{ env, - ffi::CStr, + ffi::{CStr, OsStr}, io, path::{Path, PathBuf}, str::FromStr, @@ -15,19 +15,16 @@ use std::{ use thiserror::Error; use windows::{ Win32::System::Registry::{ - HKEY, - HKEY_LOCAL_MACHINE, - KEY_READ, - RRF_RT_REG_SZ, - RegCloseKey, - RegGetValueA, - RegOpenKeyExA, + HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, RegCloseKey, RegGetValueA, RegOpenKeyExA, }, core::{PCSTR, s}, }; use crate::{ConfigError, CpuArchitecture}; +/// The value for Windows in Rust's [`std::env::consts::OS`] +const RUST_ENV_CONST_OS_WINDOWS: &str = "windows"; + /// Errors that may occur when stripping the extended path prefix from a path #[derive(Debug, Error, PartialEq, Eq)] pub enum StripExtendedPathPrefixError { @@ -234,7 +231,7 @@ pub fn get_latest_windows_sdk_version(path_to_search: &Path) -> Result CpuArchitecture { - let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").expect( + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect( "Cargo should have set the CARGO_CFG_TARGET_ARCH environment variable when executing \ build.rs", ); @@ -433,6 +430,87 @@ pub(crate) fn find_max_version_in_directory>( }) } +/// Safely sets an environment variable, panicking if not running on a Windows +/// host. +/// +/// This function provides a safe wrapper around [`std::env::set_var`] that +/// became unsafe in Rust 2024 edition. It validates that the current **host** +/// OS (where the build is running) is Windows before calling the unsafe +/// function. +/// +/// Note: This checks the host OS, not the target OS. If you're cross-compiling +/// from macOS to Windows, this will still panic because the host (macOS) is not +/// Windows. +/// +/// # Panics +/// +/// Panics if the current host OS is not Windows, since environment variable +/// operations are only guaranteed to be safe on Windows according to Rust +/// documentation. +/// +/// # Examples +/// +/// ``` +/// wdk_build::utils::set_var("MY_BUILD_VAR", "my_value"); +/// ``` +pub fn set_var(key: K, value: V) +where + K: AsRef, + V: AsRef, +{ + assert!( + env::consts::OS == RUST_ENV_CONST_OS_WINDOWS, + "Environment variable operations are only safe on Windows. This code is designed to run \ + on a Windows host machine in a WDK environment. Current host OS: {}", + env::consts::OS + ); + // SAFETY: We've verified this is running on Windows host, where env::set_var is + // always safe according to Rust documentation. + unsafe { + env::set_var(key, value); + } +} + +/// Safely removes an environment variable, panicking if not running on a +/// Windows host. +/// +/// This function provides a safe wrapper around [`std::env::remove_var`] that +/// became unsafe in Rust 2024 edition. It validates that the current **host** +/// OS (where the build is running) is Windows before calling the unsafe +/// function. +/// +/// Note: This checks the host OS, not the target OS. If you're cross-compiling +/// from macOS to Windows, this will still panic because the host (macOS) is not +/// Windows. +/// +/// # Panics +/// +/// Panics if the current host OS is not Windows, since environment variable +/// operations are only guaranteed to be safe on Windows according to Rust +/// documentation. +/// +/// # Examples +/// +/// ``` +/// wdk_build::utils::remove_var("MY_BUILD_VAR"); +/// ``` +pub fn remove_var(key: K) +where + K: AsRef, +{ + assert!( + env::consts::OS == RUST_ENV_CONST_OS_WINDOWS, + "Environment variable operations are only safe on Windows. This code is designed to run \ + on a Windows host machine in a WDK environment. Current host OS: {}", + env::consts::OS + ); + // SAFETY: We've verified this is running on Windows host, where env::remove_var + // is always safe according to Rust documentation. + unsafe { + env::remove_var(key); + } +} + #[cfg(test)] mod tests { use assert_fs::prelude::*; @@ -702,9 +780,7 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ - FOLDERID_ProgramFiles, - KF_FLAG_DEFAULT, - SHGetKnownFolderPath, + FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, SHGetKnownFolderPath, }; use super::*; @@ -926,4 +1002,63 @@ mod tests { ); } } + + mod safe_env_vars { + use super::*; + + #[test] + fn set_var_works_on_windows() { + // This test will only pass on Windows host, which is the intended behavior + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + set_var("WDK_BUILD_TEST_VAR", "test_value"); + assert_eq!(env::var("WDK_BUILD_TEST_VAR").unwrap(), "test_value"); + remove_var("WDK_BUILD_TEST_VAR"); + } + } + + #[test] + fn remove_var_works_on_windows() { + // This test will only pass on Windows host, which is the intended behavior + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + set_var("WDK_BUILD_TEST_REMOVE_VAR", "test_value"); + assert_eq!(env::var("WDK_BUILD_TEST_REMOVE_VAR").unwrap(), "test_value"); + remove_var("WDK_BUILD_TEST_REMOVE_VAR"); + assert!(env::var("WDK_BUILD_TEST_REMOVE_VAR").is_err()); + } + } + + #[test] + #[should_panic(expected = "Environment variable operations are only safe on Windows")] + fn set_var_panics_on_non_windows() { + // This test simulates non-Windows behavior by checking the panic message + // In practice, this will only run on Windows in CI/development + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + // On Windows, manually trigger the panic for testing + panic!( + "Environment variable operations are only safe on Windows. This code is \ + designed to run on a Windows host machine in a WDK environment. Current host \ + OS: windows" + ); + } else { + set_var("TEST_VAR", "test_value"); + } + } + + #[test] + #[should_panic(expected = "Environment variable operations are only safe on Windows")] + fn remove_var_panics_on_non_windows() { + // This test simulates non-Windows behavior by checking the panic message + // In practice, this will only run on Windows in CI/development + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + // On Windows, manually trigger the panic for testing + panic!( + "Environment variable operations are only safe on Windows. This code is \ + designed to run on a Windows host machine in a WDK environment. Current host \ + OS: windows" + ); + } else { + remove_var("TEST_VAR"); + } + } + } } diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index f3a86e385..a696758b0 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -14,33 +14,11 @@ use quote::{format_ident, quote, ToTokens}; use serde::{Deserialize, Serialize}; use syn::{ parse::{Parse, ParseStream, Parser}, - 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, }; /// Name of the `bindgen`-generated Rust module that contains the `TableIndex` diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index c5e4614a6..4c0fbdd06 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -24,13 +24,7 @@ use tracing_subscriber::{ filter::{LevelFilter, ParseError}, }; use wdk_build::{ - ApiSubset, - BuilderExt, - Config, - ConfigError, - DriverConfig, - KmdfConfig, - UmdfConfig, + ApiSubset, BuilderExt, Config, ConfigError, DriverConfig, KmdfConfig, UmdfConfig, configure_wdk_library_build_and_then, }; @@ -120,6 +114,8 @@ static TEST_STUBS_TEMPLATE: LazyLock = LazyLock::new(|| { use crate::WDFFUNC; /// Stubbed version of the symbol that `WdfFunctions` links to so that test targets will compile +// SAFETY: Generated WDF symbol name is required for test compilation and is unique per build. +// No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); ", diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index 6d3c69c24..e9f8b9fe6 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -117,13 +117,18 @@ mod macros; // necessary due to LLVM being too eager to set it: it checks the LLVM IR for // floating point instructions - even if soft-float is enabled! #[allow(missing_docs)] +// SAFETY: _fltused is a required Windows linker symbol for floating point support. +// No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub static _fltused: () = (); // FIXME: Is there any way to avoid this stub? See https://github.com/rust-lang/rust/issues/101134 #[cfg(panic = "abort")] #[allow(missing_docs)] -#[allow(clippy::missing_const_for_fn)] // const extern is not yet supported: https://github.com/rust-lang/rust/issues/64926 +#[allow(clippy::missing_const_for_fn)] +// const extern is not yet supported: https://github.com/rust-lang/rust/issues/64926 +// SAFETY: __CxxFrameHandler3 is a required Windows C++ exception handler symbol. +// No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub extern "system" fn __CxxFrameHandler3() -> i32 { 0 diff --git a/crates/wdk-sys/src/test_stubs.rs b/crates/wdk-sys/src/test_stubs.rs index debdc9bd5..71d0462f1 100644 --- a/crates/wdk-sys/src/test_stubs.rs +++ b/crates/wdk-sys/src/test_stubs.rs @@ -2,7 +2,7 @@ // License: MIT OR Apache-2.0 //! Any library dependency that depends on `wdk-sys` requires these stubs to -//! provide symobols to successfully compile and run tests. +//! provide symbols to successfully compile and run tests. //! //! These stubs can be brought into scope by introducing `wdk-sys` with the //! `test-stubs` feature in the `dev-dependencies` of the crate's `Cargo.toml` @@ -41,6 +41,8 @@ mod wdf { /// Stubbed version of `WdfFunctionCount` Symbol so that test targets will /// compile + // SAFETY: WdfFunctionCount is a required WDF symbol for test compilation. + // No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub static mut WdfFunctionCount: ULONG = 0; diff --git a/crates/wdk/src/print.rs b/crates/wdk/src/print.rs index 5a0d1848f..efc950e5c 100644 --- a/crates/wdk/src/print.rs +++ b/crates/wdk/src/print.rs @@ -277,8 +277,7 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer() { - const TEST_STRING: &str = - "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ @@ -333,8 +332,7 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer_prints_all() { - const TEST_STRING: &str = - "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 760688aba..afbfc5c3b 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::{ - NTSTATUS, - WDF_OBJECT_ATTRIBUTES, - WDF_TIMER_CONFIG, - WDFTIMER, - call_unsafe_wdf_function_binding, + NTSTATUS, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, WDFTIMER, call_unsafe_wdf_function_binding, }; use crate::nt_success; diff --git a/examples/sample-kmdf-driver/src/lib.rs b/examples/sample-kmdf-driver/src/lib.rs index f04c842c7..f7dc197f1 100644 --- a/examples/sample-kmdf-driver/src/lib.rs +++ b/examples/sample-kmdf-driver/src/lib.rs @@ -51,6 +51,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/examples/sample-umdf-driver/src/lib.rs b/examples/sample-umdf-driver/src/lib.rs index 9d296ee58..63457ae27 100644 --- a/examples/sample-umdf-driver/src/lib.rs +++ b/examples/sample-umdf-driver/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/examples/sample-wdm-driver/src/lib.rs b/examples/sample-wdm-driver/src/lib.rs index 9bde8609f..5e690ac92 100644 --- a/examples/sample-wdm-driver/src/lib.rs +++ b/examples/sample-wdm-driver/src/lib.rs @@ -30,6 +30,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDM +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index 375e6f4b8..20b297dfd 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -51,6 +51,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs index 3f94cf937..8ab9ef442 100644 --- a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs index 3f94cf937..8ab9ef442 100644 --- a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs index 9b0d5c200..784be3569 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs @@ -36,6 +36,8 @@ use wdk_sys::{ WDF_NO_OBJECT_ATTRIBUTES, }; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs index 9e71fb85e..177818eb0 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs @@ -5,6 +5,8 @@ use wdk_sys::*; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs index 25548ccf1..75ea68019 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs @@ -5,6 +5,8 @@ use wdk_sys::*; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs index 18265a810..ffcca5e83 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -5,6 +5,8 @@ use wdk_sys::*; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, From a2ae1c06e362cc66c3a4acc88a9c783ffb80371e Mon Sep 17 00:00:00 2001 From: leon-xd Date: Mon, 4 Aug 2025 11:58:56 -0700 Subject: [PATCH 05/32] ran formatter --- crates/cargo-wdk/src/actions/build/tests.rs | 11 +++++--- crates/cargo-wdk/src/cli.rs | 7 ++++- crates/wdk-alloc/src/lib.rs | 4 ++- crates/wdk-build/src/cargo_make.rs | 9 +++++-- crates/wdk-build/src/utils.rs | 12 +++++++-- crates/wdk-macros/src/lib.rs | 30 ++++++++++++++++++--- crates/wdk-sys/build.rs | 8 +++++- crates/wdk/src/print.rs | 6 +++-- crates/wdk/src/wdf/timer.rs | 6 ++++- 9 files changed, 76 insertions(+), 17 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index e16540a6b..a11f5b076 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -14,17 +14,22 @@ use cargo_metadata::Metadata as CargoMetadata; use mockall::predicate::eq; use mockall_double::double; use wdk_build::{ - CpuArchitecture, DriverConfig, + CpuArchitecture, + DriverConfig, metadata::{TryFromCargoMetadataError, Wdk}, }; #[double] use crate::providers::{ - exec::CommandExec, fs::Fs, metadata::Metadata as MetadataProvider, wdk_build::WdkBuild, + exec::CommandExec, + fs::Fs, + metadata::Metadata as MetadataProvider, + wdk_build::WdkBuild, }; use crate::{ actions::{ - Profile, TargetArch, + Profile, + TargetArch, build::{BuildAction, BuildActionError, BuildActionParams}, to_target_triple, }, diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index e085a2e3c..1e147a267 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -12,7 +12,12 @@ use mockall_double::double; use wdk_build::CpuArchitecture; use crate::actions::{ - DriverType, KMDF_STR, Profile, TargetArch, UMDF_STR, WDM_STR, + DriverType, + KMDF_STR, + Profile, + TargetArch, + UMDF_STR, + WDM_STR, build::{BuildAction, BuildActionParams}, new::NewAction, }; diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index cd9b689c7..99319669b 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -31,7 +31,9 @@ mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; use wdk_sys::{ - POOL_FLAG_NON_PAGED, SIZE_T, ULONG, + POOL_FLAG_NON_PAGED, + SIZE_T, + ULONG, ntddk::{ExAllocatePool2, ExFreePool}, }; diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index df5dc0aa0..7e33daa31 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -25,9 +25,14 @@ use clap::{Args, Parser}; use tracing::{instrument, trace}; use crate::{ - ConfigError, CpuArchitecture, metadata, + ConfigError, + CpuArchitecture, + metadata, utils::{ - PathExt, 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, set_var, }, }; diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 4e96315f8..4ecc19a0f 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -15,7 +15,13 @@ use std::{ use thiserror::Error; use windows::{ Win32::System::Registry::{ - HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, RegCloseKey, RegGetValueA, RegOpenKeyExA, + HKEY, + HKEY_LOCAL_MACHINE, + KEY_READ, + RRF_RT_REG_SZ, + RegCloseKey, + RegGetValueA, + RegOpenKeyExA, }, core::{PCSTR, s}, }; @@ -780,7 +786,9 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ - FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, SHGetKnownFolderPath, + FOLDERID_ProgramFiles, + KF_FLAG_DEFAULT, + SHGetKnownFolderPath, }; use super::*; diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index a696758b0..f3a86e385 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -14,11 +14,33 @@ use quote::{format_ident, quote, ToTokens}; use serde::{Deserialize, Serialize}; use syn::{ parse::{Parse, ParseStream, Parser}, - 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, }; /// Name of the `bindgen`-generated Rust module that contains the `TableIndex` diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 4c0fbdd06..5b3bf4ce0 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -24,7 +24,13 @@ use tracing_subscriber::{ filter::{LevelFilter, ParseError}, }; use wdk_build::{ - ApiSubset, BuilderExt, Config, ConfigError, DriverConfig, KmdfConfig, UmdfConfig, + ApiSubset, + BuilderExt, + Config, + ConfigError, + DriverConfig, + KmdfConfig, + UmdfConfig, configure_wdk_library_build_and_then, }; diff --git a/crates/wdk/src/print.rs b/crates/wdk/src/print.rs index efc950e5c..5a0d1848f 100644 --- a/crates/wdk/src/print.rs +++ b/crates/wdk/src/print.rs @@ -277,7 +277,8 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer() { - const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = + "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ @@ -332,7 +333,8 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer_prints_all() { - const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = + "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index afbfc5c3b..760688aba 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::{ - NTSTATUS, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, WDFTIMER, call_unsafe_wdf_function_binding, + NTSTATUS, + WDF_OBJECT_ATTRIBUTES, + WDF_TIMER_CONFIG, + WDFTIMER, + call_unsafe_wdf_function_binding, }; use crate::nt_success; From a5be4824235e11d1b578bcc29fb81507dcc6cce8 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Mon, 4 Aug 2025 15:17:22 -0700 Subject: [PATCH 06/32] fixed doc test issues --- crates/wdk-build/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 74a5bb98f..3da3616f7 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation // License: MIT OR Apache-2.0 -//! [`wdk-build`] is a library that is used within Cargo build scripts to +//! `wdk-build` is a library that is used within Cargo build scripts to //! configure any build that depends on the WDK (Windows Driver Kit). This is //! especially useful for crates that generate FFI bindings to the WDK, //! WDK-dependent libraries, and programs built on top of the WDK (ex. Drivers). @@ -139,7 +139,7 @@ pub struct UmdfConfig { pub minimum_umdf_version_minor: Option, } -/// Errors that could result from configuring a build via [`wdk-build`] +/// Errors that could result from configuring a build via `wdk-build` #[derive(Debug, Error)] pub enum ConfigError { /// Error returned when an [`std::io`] operation fails From 1db477baacef1b0aebff6f0359688cb58d6a27e0 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 31 Jul 2025 17:32:08 -0700 Subject: [PATCH 07/32] Migration to Rust 2024 --- .vscode/settings.json | 3 +- CONTRIBUTING.md | 3 +- Cargo.toml | 12 ++-- README.md | 2 +- .../cargo-wdk/src/actions/build/build_task.rs | 2 +- crates/cargo-wdk/src/actions/build/mod.rs | 2 +- crates/cargo-wdk/src/actions/build/tests.rs | 52 +++++++-------- crates/cargo-wdk/src/actions/new/mod.rs | 2 +- crates/cargo-wdk/src/cli.rs | 6 +- crates/cargo-wdk/src/providers/fs.rs | 2 +- crates/cargo-wdk/tests/common.rs | 12 +++- .../crates/driver_1/src/lib.rs | 2 +- .../crates/driver_2/src/lib.rs | 2 +- .../crates/driver/src/lib.rs | 2 +- crates/cargo-wdk/tests/new_command_test.rs | 50 +++++++++------ crates/cargo-wdk/tests/umdf-driver/src/lib.rs | 2 +- crates/wdk-alloc/src/lib.rs | 2 +- crates/wdk-build/rust-driver-makefile.toml | 5 +- crates/wdk-build/src/bindgen.rs | 2 +- crates/wdk-build/src/cargo_make.rs | 63 ++++++++++++++----- crates/wdk-build/src/lib.rs | 18 +++++- crates/wdk-build/src/metadata/map.rs | 2 +- crates/wdk-build/src/metadata/mod.rs | 2 +- crates/wdk-build/src/metadata/ser.rs | 8 +-- crates/wdk-build/src/utils.rs | 12 ++-- crates/wdk-sys/build.rs | 8 +-- crates/wdk-sys/src/lib.rs | 4 +- crates/wdk-sys/src/test_stubs.rs | 4 +- crates/wdk/src/print.rs | 18 ++---- crates/wdk/src/wdf/spinlock.rs | 4 +- crates/wdk/src/wdf/timer.rs | 6 +- examples/sample-kmdf-driver/src/lib.rs | 2 +- examples/sample-umdf-driver/src/lib.rs | 2 +- examples/sample-wdm-driver/src/lib.rs | 2 +- .../crates/driver/src/lib.rs | 2 +- .../crates/driver_1/src/lib.rs | 2 +- .../crates/driver_2/src/lib.rs | 2 +- .../inputs/macrotest/bug_unused_imports.rs | 2 +- .../inputs/macrotest/wdf_driver_create.rs | 2 +- .../trybuild/wdf_api_that_does_not_exist.rs | 2 +- .../trybuild/wdf_driver_create_missing_arg.rs | 2 +- .../wdf_driver_create_wrong_arg_order.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- 48 files changed, 206 insertions(+), 142 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index fa9e9b637..e59b8597b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,5 +21,6 @@ "./tests/wdk-macros-tests/Cargo.toml", "./tests/wdk-sys-tests/Cargo.toml", ], - "rust-analyzer.cargo.features": "all" + "rust-analyzer.cargo.features": "all", + "rust-analyzer.checkOnSave": false } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69d4337e4..69ff655f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,9 +87,10 @@ That's it! Thank you for your contribution! The following tools should be installed as a part of the `windows-drivers-rs` developer workflow: -* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.85` * `cargo-audit`: `cargo install --locked cargo-audit` +* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.85` * `cargo-machete`: `cargo install --locked cargo-machete` +* `cargo-sort`: `cargo install --locked cargo-sort` * `taplo-cli`: `cargo install --locked taplo-cli` **Note on arm64:** ARM64 support for ring is [not released yet](https://github.com/briansmith/ring/issues/1167), so TLS features must be disabled until arm64 is officially supported by ring (probably in 0.17.0 release) diff --git a/Cargo.toml b/Cargo.toml index 45bee2e12..90e82d345 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ exclude = [ resolver = "3" [workspace.package] -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" repository = "https://github.com/microsoft/windows-drivers-rs" readme = "README.md" license = "MIT OR Apache-2.0" @@ -67,10 +67,10 @@ windows = "0.58.0" # The following workspace.metadata.wdk sections can be uncommented to configure the workspace for a specific WDK configuration (ex. for rust-analyzer to resolve things for a specific configuration) # Uncomment the section below for KMDF -# [workspace.metadata.wdk.driver-model] -# driver-type = "KMDF" -# kmdf-version-major = 1 -# target-kmdf-version-minor = 33 +[workspace.metadata.wdk.driver-model] +driver-type = "KMDF" +kmdf-version-major = 1 +target-kmdf-version-minor = 33 # Uncomment the section below for UMDF # [workspace.metadata.wdk.driver-model] diff --git a/README.md b/README.md index b936e77dd..bda034389 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ The crates in this repository are available from [`crates.io`](https://crates.io PCUNICODE_STRING, }; - #[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry + #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/src/actions/build/build_task.rs b/crates/cargo-wdk/src/actions/build/build_task.rs index 7d01a2e21..80edef3a0 100644 --- a/crates/cargo-wdk/src/actions/build/build_task.rs +++ b/crates/cargo-wdk/src/actions/build/build_task.rs @@ -15,7 +15,7 @@ use wdk_build::utils::{PathExt, StripExtendedPathPrefixError}; #[double] use crate::providers::{exec::CommandExec, fs::Fs}; use crate::{ - actions::{build::error::BuildTaskError, to_target_triple, Profile, TargetArch}, + actions::{Profile, TargetArch, build::error::BuildTaskError, to_target_triple}, trace, }; diff --git a/crates/cargo-wdk/src/actions/build/mod.rs b/crates/cargo-wdk/src/actions/build/mod.rs index 7a2a4df8f..ea39fa042 100644 --- a/crates/cargo-wdk/src/actions/build/mod.rs +++ b/crates/cargo-wdk/src/actions/build/mod.rs @@ -26,7 +26,7 @@ use package_task::{PackageTask, PackageTaskParams}; use tracing::{debug, error as err, info, warn}; use wdk_build::metadata::{TryFromCargoMetadataError, Wdk}; -use crate::actions::{to_target_triple, Profile, TargetArch}; +use crate::actions::{Profile, TargetArch, to_target_triple}; #[double] use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild}; diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index 184184b45..a11f5b076 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -14,9 +14,9 @@ use cargo_metadata::Metadata as CargoMetadata; use mockall::predicate::eq; use mockall_double::double; use wdk_build::{ - metadata::{TryFromCargoMetadataError, Wdk}, CpuArchitecture, DriverConfig, + metadata::{TryFromCargoMetadataError, Wdk}, }; #[double] @@ -28,10 +28,10 @@ use crate::providers::{ }; use crate::{ actions::{ - build::{BuildAction, BuildActionError, BuildActionParams}, - to_target_triple, Profile, TargetArch, + build::{BuildAction, BuildActionError, BuildActionParams}, + to_target_triple, }, providers::error::{CommandError, FileError}, }; @@ -270,8 +270,8 @@ pub fn given_a_driver_project_when_target_arch_is_arm64_then_it_builds_successfu } #[test] -pub fn given_a_driver_project_when_profile_is_release_and_target_arch_is_arm64_then_it_builds_successfully( -) { +pub fn given_a_driver_project_when_profile_is_release_and_target_arch_is_arm64_then_it_builds_successfully() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = Some(Profile::Release); @@ -1198,8 +1198,8 @@ pub fn given_a_driver_project_when_infverif_command_execution_fails_then_package } #[test] -pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_metadata_are_provided_then_build_should_be_successful( -) { +pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_metadata_are_provided_then_build_should_be_successful() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1245,8 +1245,8 @@ pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_m } #[test] -pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_default_values_are_provided_then_wdk_metadata_parse_should_fail( -) { +pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_default_values_are_provided_then_wdk_metadata_parse_should_fail() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp\\sample-driver"); let profile = None; @@ -1298,8 +1298,8 @@ pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_defau /// Workspace tests //////////////////////////////////////////////////////////////////////////////// #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_default_values_are_provided_then_it_packages_successfully( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_default_values_are_provided_then_it_packages_successfully() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1425,8 +1425,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_defau } #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_driver_project_then_it_packages_driver_project_successfully( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_driver_project_then_it_packages_driver_project_successfully() + { // Input CLI args let workspace_root_dir = PathBuf::from("C:\\tmp"); let cwd = workspace_root_dir.join("sample-kmdf-1"); @@ -1538,8 +1538,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_i } #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verify_signature_is_false_then_it_skips_verify_tasks( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verify_signature_is_false_then_it_skips_verify_tasks() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1661,8 +1661,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verif } #[test] -pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_non_driver_project_then_it_builds_but_skips_packaging( -) { +pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_non_driver_project_then_it_builds_but_skips_packaging() + { // Input CLI args let workspace_root_dir = PathBuf::from("C:\\tmp"); let cwd = workspace_root_dir.join("non-driver"); @@ -1740,8 +1740,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_i } #[test] -pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail( -) { +pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1819,8 +1819,8 @@ pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_works } #[test] -pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail( -) { +pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1898,8 +1898,8 @@ pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_w } #[test] -pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_root_then_build_should_be_successful( -) { +pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_root_then_build_should_be_successful() + { // Input CLI args let cwd = PathBuf::from("C:\\tmp"); let profile = None; @@ -1950,8 +1950,8 @@ pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_roo } #[test] -pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_member_then_build_should_be_successful( -) { +pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_member_then_build_should_be_successful() + { // Input CLI args let workspace_root_dir = PathBuf::from("C:\\tmp"); let cwd = workspace_root_dir.join("non-driver"); @@ -2048,7 +2048,7 @@ trait TestSetupPackageExpectations { override_output: Option, ) -> Self; fn expect_inx_file_exists(self, driver_name: &str, driver_dir: &Path, does_exist: bool) - -> Self; + -> Self; fn expect_rename_driver_binary_dll_to_sys(self, driver_name: &str, driver_dir: &Path) -> Self; fn expect_copy_driver_binary_sys_to_package_folder( self, diff --git a/crates/cargo-wdk/src/actions/new/mod.rs b/crates/cargo-wdk/src/actions/new/mod.rs index 7e7451fe9..3067bb1d6 100644 --- a/crates/cargo-wdk/src/actions/new/mod.rs +++ b/crates/cargo-wdk/src/actions/new/mod.rs @@ -15,7 +15,7 @@ use std::{ use clap_verbosity_flag::Verbosity; use error::NewActionError; -use include_dir::{include_dir, Dir}; +use include_dir::{Dir, include_dir}; use mockall_double::double; use tracing::{debug, info}; diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index ef5b71759..1e147a267 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -12,14 +12,14 @@ use mockall_double::double; use wdk_build::CpuArchitecture; use crate::actions::{ - build::{BuildAction, BuildActionParams}, - new::NewAction, DriverType, + KMDF_STR, Profile, TargetArch, - KMDF_STR, UMDF_STR, WDM_STR, + build::{BuildAction, BuildActionParams}, + new::NewAction, }; #[double] use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild}; diff --git a/crates/cargo-wdk/src/providers/fs.rs b/crates/cargo-wdk/src/providers/fs.rs index 610c71218..5444b76ea 100644 --- a/crates/cargo-wdk/src/providers/fs.rs +++ b/crates/cargo-wdk/src/providers/fs.rs @@ -11,7 +11,7 @@ #![allow(clippy::unused_self)] use std::{ - fs::{copy, create_dir, read_dir, rename, DirEntry, File, FileType, OpenOptions}, + fs::{DirEntry, File, FileType, OpenOptions, copy, create_dir, read_dir, rename}, io::{Read, Write}, path::{Path, PathBuf}, }; diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index 345bdfeda..c565e367d 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -14,10 +14,18 @@ use fs4::fs_std::FileExt; pub fn set_crt_static_flag() { if let Ok(rustflags) = std::env::var("RUSTFLAGS") { let updated_rust_flags = format!("{rustflags} -C target-feature=+crt-static"); - std::env::set_var("RUSTFLAGS", updated_rust_flags); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var("RUSTFLAGS", updated_rust_flags); + } println!("RUSTFLAGS set, adding the +crt-static: {rustflags:?}"); } else { - std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); + } println!( "No RUSTFLAGS set, setting it to: {:?}", std::env::var("RUSTFLAGS").expect("RUSTFLAGS not set") diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs index 71623cce9..567b757ae 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs index 71623cce9..567b757ae 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index 289d22f59..e4587f2d7 100644 --- a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -47,7 +47,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/cargo-wdk/tests/new_command_test.rs b/crates/cargo-wdk/tests/new_command_test.rs index 56b6d3e62..b50c87cac 100644 --- a/crates/cargo-wdk/tests/new_command_test.rs +++ b/crates/cargo-wdk/tests/new_command_test.rs @@ -4,7 +4,7 @@ mod common; use std::path::PathBuf; use assert_cmd::Command; -use assert_fs::{assert::PathAssert, prelude::PathChild, TempDir}; +use assert_fs::{TempDir, assert::PathAssert, prelude::PathChild}; use common::{set_crt_static_flag, with_file_lock}; use mockall::PredicateBooleanExt; @@ -65,10 +65,16 @@ fn project_is_created(driver_type: &str) { assert!(stdout.contains( "Required directive Provider missing, empty, or invalid in [Version] section." )); - assert!(stdout - .contains("Required directive Class missing, empty, or invalid in [Version] section.")); - assert!(stdout - .contains("Invalid ClassGuid \"\", expecting {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}.")); + assert!( + stdout.contains( + "Required directive Class missing, empty, or invalid in [Version] section." + ) + ); + assert!( + stdout.contains( + "Invalid ClassGuid \"\", expecting {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}." + ) + ); assert!(stdout.contains("INF is NOT VALID")); }); } @@ -143,20 +149,26 @@ fn create_and_build_new_driver_project(driver_type: &str) -> (String, String) { assert!(tmp_dir.join(&driver_name).is_dir()); assert!(tmp_dir.join(&driver_name).join("build.rs").is_file()); assert!(tmp_dir.join(&driver_name).join("Cargo.toml").is_file()); - assert!(tmp_dir - .join(&driver_name) - .join(format!("{driver_name_underscored}.inx")) - .is_file()); - assert!(tmp_dir - .join(&driver_name) - .join("src") - .join("lib.rs") - .is_file()); - assert!(tmp_dir - .join(&driver_name) - .join(".cargo") - .join("config.toml") - .is_file()); + assert!( + tmp_dir + .join(&driver_name) + .join(format!("{driver_name_underscored}.inx")) + .is_file() + ); + assert!( + tmp_dir + .join(&driver_name) + .join("src") + .join("lib.rs") + .is_file() + ); + assert!( + tmp_dir + .join(&driver_name) + .join(".cargo") + .join("config.toml") + .is_file() + ); // assert content let driver_name_path = PathBuf::from(&driver_name); diff --git a/crates/cargo-wdk/tests/umdf-driver/src/lib.rs b/crates/cargo-wdk/tests/umdf-driver/src/lib.rs index 71623cce9..567b757ae 100644 --- a/crates/cargo-wdk/tests/umdf-driver/src/lib.rs +++ b/crates/cargo-wdk/tests/umdf-driver/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 1a8b72829..99319669b 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -31,10 +31,10 @@ mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; use wdk_sys::{ - ntddk::{ExAllocatePool2, ExFreePool}, POOL_FLAG_NON_PAGED, SIZE_T, ULONG, + ntddk::{ExAllocatePool2, ExFreePool}, }; /// Allocator implementation to use with `#[global_allocator]` to allow use diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index 6b8009395..ace26fd2d 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -158,7 +158,10 @@ let serialized_wdk_metadata_map = wdk_build::metadata::to_map_with_prefix:: impl IntoIterator { }; if let Some(toolchain) = toolchain_arg { - env::set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); + } } CommandLineInterface::parse_from(env_args.iter()).parse_cargo_args(); @@ -641,8 +658,12 @@ pub fn setup_wdk_version() -> Result, ConfigErr }); } - env::set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); - Ok([WDK_VERSION_ENV_VAR].map(ToString::to_string)) + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); + } + Ok([WDK_VERSION_ENV_VAR].map(std::string::ToString::to_string)) } /// Sets the `WDK_INFVERIF_SAMPLE_FLAG` environment variable to contain the @@ -670,7 +691,7 @@ pub fn setup_infverif_for_samples + ToString + ?Sized>( .expect("Unable to parse the build number of the WDK version string as an int!"); let sample_flag = if version > MINIMUM_SAMPLES_FLAG_WDK_VERSION { "/samples" // Note: Not currently implemented, so in samples TOML we - // currently skip infverif + // currently skip infverif } else { "/msft" }; @@ -1111,10 +1132,14 @@ fn configure_wdf_build_output_dir(target_arg: Option<&String>, cargo_make_cargo_ output_dir }; - env::set_var( - WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, - wdk_build_output_directory, - ); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var( + WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, + wdk_build_output_directory, + ); + } } fn append_to_space_delimited_env_var(env_var_name: S, string_to_append: T) @@ -1128,7 +1153,11 @@ where let mut env_var_value: String = env::var(env_var_name).unwrap_or_default(); env_var_value.push(' '); env_var_value.push_str(string_to_append); - env::set_var(env_var_name, env_var_value.trim()); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(env_var_name, env_var_value.trim()); + } } fn prepend_to_semicolon_delimited_env_var(env_var_name: S, string_to_prepend: T) @@ -1142,7 +1171,11 @@ where let mut env_var_value = string_to_prepend.to_string(); env_var_value.push(';'); env_var_value.push_str(env::var(env_var_name).unwrap_or_default().as_str()); - env::set_var(env_var_name, env_var_value); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + env::set_var(env_var_name, env_var_value); + } } /// `cargo-make` condition script for `infverif` task in diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 090a3e5cf..031902953 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -1480,7 +1480,11 @@ mod tests { "Duplicate environment variable keys were provided" ); } - std::env::set_var(key, value); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var(key, value); + } } let f_return_value = f(); @@ -1489,10 +1493,18 @@ mod tests { for (key, _) in env_vars_key_value_pairs { original_env_vars.get(key).map_or_else( || { - std::env::remove_var(key); + // SAFETY: env::remove_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::remove_var(key); + } }, |value| { - std::env::set_var(key, value); + // SAFETY: env::set_var is always safe on Windows according to documentation, + // and this code runs in a WDK environment which is always Windows. + unsafe { + std::env::set_var(key, value); + } }, ); } diff --git a/crates/wdk-build/src/metadata/map.rs b/crates/wdk-build/src/metadata/map.rs index 492b3ae3f..ad5a94bb4 100644 --- a/crates/wdk-build/src/metadata/map.rs +++ b/crates/wdk-build/src/metadata/map.rs @@ -2,7 +2,7 @@ // License: MIT OR Apache-2.0 use std::{ - collections::{btree_map, hash_map, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, btree_map, hash_map}, hash::{BuildHasher, Hash}, }; diff --git a/crates/wdk-build/src/metadata/mod.rs b/crates/wdk-build/src/metadata/mod.rs index 8dd01d4b2..03c363545 100644 --- a/crates/wdk-build/src/metadata/mod.rs +++ b/crates/wdk-build/src/metadata/mod.rs @@ -11,7 +11,7 @@ pub use error::{Error, Result}; pub use map::Map; -pub use ser::{to_map, to_map_with_prefix, Serializer}; +pub use ser::{Serializer, to_map, to_map_with_prefix}; pub(crate) mod ser; diff --git a/crates/wdk-build/src/metadata/ser.rs b/crates/wdk-build/src/metadata/ser.rs index fd4f18948..74288ac10 100644 --- a/crates/wdk-build/src/metadata/ser.rs +++ b/crates/wdk-build/src/metadata/ser.rs @@ -2,8 +2,8 @@ // License: MIT OR Apache-2.0 use serde::{ - ser::{self, Impossible}, Serialize, + ser::{self, Impossible}, }; use super::{ @@ -31,9 +31,9 @@ pub const KEY_NAME_SEPARATOR: char = '-'; /// use std::collections::BTreeMap; /// /// use wdk_build::{ -/// metadata::{self, to_map}, /// DriverConfig, /// KmdfConfig, +/// metadata::{self, to_map}, /// }; /// /// let wdk_metadata = metadata::Wdk { @@ -78,9 +78,9 @@ where /// use std::collections::BTreeMap; /// /// use wdk_build::{ -/// metadata::{self, to_map_with_prefix}, /// DriverConfig, /// KmdfConfig, +/// metadata::{self, to_map_with_prefix}, /// }; /// /// let wdk_metadata = metadata::Wdk { @@ -587,7 +587,7 @@ mod tests { }; use super::*; - use crate::{metadata, DriverConfig, KmdfConfig, UmdfConfig}; + use crate::{DriverConfig, KmdfConfig, UmdfConfig, metadata}; #[test] fn test_kmdf() { diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 85fabfb13..2871b894b 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -14,16 +14,16 @@ use std::{ 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, }, + core::{PCSTR, s}, }; use crate::{ConfigError, CpuArchitecture}; @@ -719,8 +719,8 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ FOLDERID_ProgramFiles, - SHGetKnownFolderPath, KF_FLAG_DEFAULT, + SHGetKnownFolderPath, }; use super::*; @@ -935,7 +935,7 @@ mod tests { temp_dir.child("a.b").create_dir_all().unwrap(); // Invalid: non-numeric temp_dir.child("not_version").touch().unwrap(); // File: ignored temp_dir.child("3.0").touch().unwrap(); // File: ignored - // Should find the maximum among valid version directories only + // Should find the maximum among valid version directories only assert_eq!( find_max_version_in_directory(temp_dir.path()).unwrap(), TwoPartVersion(2, 0) diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 547b6483e..c5e4614a6 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -18,13 +18,12 @@ use std::{ use anyhow::Context; use bindgen::CodegenConfig; -use tracing::{info, info_span, trace, Span}; +use tracing::{Span, info, info_span, trace}; use tracing_subscriber::{ - filter::{LevelFilter, ParseError}, EnvFilter, + filter::{LevelFilter, ParseError}, }; use wdk_build::{ - configure_wdk_library_build_and_then, ApiSubset, BuilderExt, Config, @@ -32,6 +31,7 @@ use wdk_build::{ DriverConfig, KmdfConfig, UmdfConfig, + configure_wdk_library_build_and_then, }; const OUT_DIR_PLACEHOLDER: &str = @@ -120,7 +120,7 @@ static TEST_STUBS_TEMPLATE: LazyLock = LazyLock::new(|| { use crate::WDFFUNC; /// Stubbed version of the symbol that `WdfFunctions` links to so that test targets will compile -#[no_mangle] +#[unsafe(no_mangle)] pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); ", ) diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index f7d387bbb..6d3c69c24 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -117,14 +117,14 @@ mod macros; // necessary due to LLVM being too eager to set it: it checks the LLVM IR for // floating point instructions - even if soft-float is enabled! #[allow(missing_docs)] -#[no_mangle] +#[unsafe(no_mangle)] pub static _fltused: () = (); // FIXME: Is there any way to avoid this stub? See https://github.com/rust-lang/rust/issues/101134 #[cfg(panic = "abort")] #[allow(missing_docs)] #[allow(clippy::missing_const_for_fn)] // const extern is not yet supported: https://github.com/rust-lang/rust/issues/64926 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn __CxxFrameHandler3() -> i32 { 0 } diff --git a/crates/wdk-sys/src/test_stubs.rs b/crates/wdk-sys/src/test_stubs.rs index b9bff9880..debdc9bd5 100644 --- a/crates/wdk-sys/src/test_stubs.rs +++ b/crates/wdk-sys/src/test_stubs.rs @@ -27,7 +27,7 @@ use crate::{DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING}; driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF" ))] -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub const unsafe extern "system" fn driver_entry_stub( _driver: &mut DRIVER_OBJECT, _registry_path: PCUNICODE_STRING, @@ -41,7 +41,7 @@ mod wdf { /// Stubbed version of `WdfFunctionCount` Symbol so that test targets will /// compile - #[no_mangle] + #[unsafe(no_mangle)] pub static mut WdfFunctionCount: ULONG = 0; include!(concat!(env!("OUT_DIR"), "/test_stubs.rs")); diff --git a/crates/wdk/src/print.rs b/crates/wdk/src/print.rs index bcbf26f82..5a0d1848f 100644 --- a/crates/wdk/src/print.rs +++ b/crates/wdk/src/print.rs @@ -90,7 +90,7 @@ pub fn _print(args: fmt::Arguments) { if #[cfg(any(driver_model__driver_type = "WDM", driver_model__driver_type = "KMDF"))] { let mut buffered_writer = dbg_print_buf_writer::DbgPrintBufWriter::new(); - if let Ok(_) = fmt::write(&mut buffered_writer, args) { + if fmt::write(&mut buffered_writer, args).is_ok() { buffered_writer.flush(); } else { unreachable!("DbgPrintBufWriter should never fail to write"); @@ -235,11 +235,10 @@ mod dbg_print_buf_writer { // Helper function to advance the start of a `u8` slice to the next non-null // byte. Returns an empty slice if all bytes are null. fn advance_slice_to_next_non_null_byte(slice: &[u8]) -> &[u8] { - if let Some(pos) = slice.iter().position(|&b| b != b'\0') { - &slice[pos..] - } else { - &slice[slice.len()..] - } + slice + .iter() + .position(|&b| b != b'\0') + .map_or_else(|| &slice[slice.len()..], |pos| &slice[pos..]) } #[cfg(test)] @@ -273,7 +272,7 @@ mod dbg_print_buf_writer { // Check that the string is null-terminated at the end of the buffer. assert_eq!(writer.buffer[old_used], b'\0'); // Check that the string isn't null-terminated at the beginning of the buffer. - assert_ne!(writer.buffer[0], b'\0') + assert_ne!(writer.buffer[0], b'\0'); } #[test] @@ -352,8 +351,6 @@ mod dbg_print_buf_writer { characters long to ensure that the DbgPrintBufWriter's buffer overflow handling \ is thoroughly tested."; const TEST_STRING_LEN: usize = TEST_STRING.len(); - const UNFLUSHED_STRING_CONTENTS_STARTING_INDEX: usize = - TEST_STRING_LEN - (TEST_STRING_LEN % DbgPrintBufWriter::USABLE_BUFFER_SIZE); const { assert!( @@ -362,9 +359,6 @@ mod dbg_print_buf_writer { ); } - let expected_unflushed_string_contents = - &TEST_STRING[UNFLUSHED_STRING_CONTENTS_STARTING_INDEX..]; - let mut writer = DbgPrintBufWriter::new(); // set the last byte to 1 to ensure that the buffer is not automatically diff --git a/crates/wdk/src/wdf/spinlock.rs b/crates/wdk/src/wdf/spinlock.rs index 0edd567ee..b60013211 100644 --- a/crates/wdk/src/wdf/spinlock.rs +++ b/crates/wdk/src/wdf/spinlock.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation // License: MIT OR Apache-2.0 -use wdk_sys::{call_unsafe_wdf_function_binding, NTSTATUS, WDFSPINLOCK, WDF_OBJECT_ATTRIBUTES}; +use wdk_sys::{NTSTATUS, WDF_OBJECT_ATTRIBUTES, WDFSPINLOCK, call_unsafe_wdf_function_binding}; use crate::nt_success; @@ -40,7 +40,7 @@ impl SpinLock { nt_status = call_unsafe_wdf_function_binding!( WdfSpinLockCreate, attributes, - &mut spin_lock.wdf_spin_lock, + &raw mut spin_lock.wdf_spin_lock, ); } nt_success(nt_status).then_some(spin_lock).ok_or(nt_status) diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 7535ca027..760688aba 100644 --- a/crates/wdk/src/wdf/timer.rs +++ b/crates/wdk/src/wdf/timer.rs @@ -2,11 +2,11 @@ // License: MIT OR Apache-2.0 use wdk_sys::{ - call_unsafe_wdf_function_binding, NTSTATUS, - WDFTIMER, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, + WDFTIMER, + call_unsafe_wdf_function_binding, }; use crate::nt_success; @@ -38,7 +38,7 @@ impl Timer { WdfTimerCreate, timer_config, attributes, - &mut timer.wdf_timer, + &raw mut timer.wdf_timer, ); } nt_success(nt_status).then_some(timer).ok_or(nt_status) diff --git a/examples/sample-kmdf-driver/src/lib.rs b/examples/sample-kmdf-driver/src/lib.rs index 050013455..f04c842c7 100644 --- a/examples/sample-kmdf-driver/src/lib.rs +++ b/examples/sample-kmdf-driver/src/lib.rs @@ -51,7 +51,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/examples/sample-umdf-driver/src/lib.rs b/examples/sample-umdf-driver/src/lib.rs index 9c9968f42..9d296ee58 100644 --- a/examples/sample-umdf-driver/src/lib.rs +++ b/examples/sample-umdf-driver/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/examples/sample-wdm-driver/src/lib.rs b/examples/sample-wdm-driver/src/lib.rs index fa7d3348d..9bde8609f 100644 --- a/examples/sample-wdm-driver/src/lib.rs +++ b/examples/sample-wdm-driver/src/lib.rs @@ -30,7 +30,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDM -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index 1ea37391d..375e6f4b8 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -51,7 +51,7 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs index dd498498c..3f94cf937 100644 --- a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs index dd498498c..3f94cf937 100644 --- a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,7 +33,7 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs index f31966413..9b0d5c200 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs @@ -36,7 +36,7 @@ use wdk_sys::{ WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs index 4b09d3535..095d067d9 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs @@ -3,7 +3,7 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs index deb7c4f36..9e71fb85e 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs @@ -5,7 +5,7 @@ use wdk_sys::*; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs index fc8f46ce7..25548ccf1 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs @@ -5,7 +5,7 @@ use wdk_sys::*; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs index f07cb6fbd..18265a810 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -5,7 +5,7 @@ use wdk_sys::*; -#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 fb3d47552..b1451a812 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 @@ -23,7 +23,7 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 2f60cd9a4..d99bbb959 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 @@ -1,6 +1,6 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, 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 fb3d47552..b1451a812 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 @@ -23,7 +23,7 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 2f60cd9a4..d99bbb959 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 @@ -1,6 +1,6 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, 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 fb3d47552..b1451a812 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 @@ -23,7 +23,7 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, 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 2f60cd9a4..d99bbb959 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 @@ -1,6 +1,6 @@ #![no_main] #![deny(warnings)] -#[export_name = "DriverEntry"] +#[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, registry_path: wdk_sys::PCUNICODE_STRING, From 7d15f1d44710059d7725f32c44a3133219e34e58 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 31 Jul 2025 17:34:57 -0700 Subject: [PATCH 08/32] Recommented driver configuration --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90e82d345..140740aa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,10 +67,10 @@ windows = "0.58.0" # The following workspace.metadata.wdk sections can be uncommented to configure the workspace for a specific WDK configuration (ex. for rust-analyzer to resolve things for a specific configuration) # Uncomment the section below for KMDF -[workspace.metadata.wdk.driver-model] -driver-type = "KMDF" -kmdf-version-major = 1 -target-kmdf-version-minor = 33 +# [workspace.metadata.wdk.driver-model] +# driver-type = "KMDF" +# kmdf-version-major = 1 +# target-kmdf-version-minor = 33 # Uncomment the section below for UMDF # [workspace.metadata.wdk.driver-model] From 0f6414de0f1e5d425fe74c563197586802e21fdd Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 31 Jul 2025 17:42:46 -0700 Subject: [PATCH 09/32] removed check on save blocker in vscode config --- .vscode/settings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e59b8597b..fa9e9b637 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,6 +21,5 @@ "./tests/wdk-macros-tests/Cargo.toml", "./tests/wdk-sys-tests/Cargo.toml", ], - "rust-analyzer.cargo.features": "all", - "rust-analyzer.checkOnSave": false + "rust-analyzer.cargo.features": "all" } From 8475b4a1c0e4138889335cd240c2382ee5cf11fc Mon Sep 17 00:00:00 2001 From: leon-xd Date: Mon, 4 Aug 2025 11:55:29 -0700 Subject: [PATCH 10/32] Addressed comments --- crates/cargo-wdk/src/actions/build/tests.rs | 11 +- crates/cargo-wdk/src/cli.rs | 7 +- crates/cargo-wdk/tests/common.rs | 13 +- crates/wdk-alloc/src/lib.rs | 4 +- crates/wdk-build/rust-driver-makefile.toml | 5 +- crates/wdk-build/src/cargo_make.rs | 58 ++----- crates/wdk-build/src/lib.rs | 19 +-- crates/wdk-build/src/utils.rs | 159 ++++++++++++++++-- crates/wdk-macros/src/lib.rs | 30 +--- crates/wdk-sys/build.rs | 10 +- crates/wdk-sys/src/lib.rs | 7 +- crates/wdk-sys/src/test_stubs.rs | 4 +- crates/wdk/src/print.rs | 6 +- crates/wdk/src/wdf/timer.rs | 6 +- examples/sample-kmdf-driver/src/lib.rs | 2 + examples/sample-umdf-driver/src/lib.rs | 2 + examples/sample-wdm-driver/src/lib.rs | 2 + .../crates/driver/src/lib.rs | 2 + .../crates/driver_1/src/lib.rs | 2 + .../crates/driver_2/src/lib.rs | 2 + .../inputs/macrotest/bug_unused_imports.rs | 2 + .../trybuild/wdf_api_that_does_not_exist.rs | 2 + .../trybuild/wdf_driver_create_missing_arg.rs | 2 + .../wdf_driver_create_wrong_arg_order.rs | 2 + 24 files changed, 212 insertions(+), 147 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index a11f5b076..e16540a6b 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -14,22 +14,17 @@ use cargo_metadata::Metadata as CargoMetadata; use mockall::predicate::eq; use mockall_double::double; use wdk_build::{ - CpuArchitecture, - DriverConfig, + CpuArchitecture, DriverConfig, metadata::{TryFromCargoMetadataError, Wdk}, }; #[double] use crate::providers::{ - exec::CommandExec, - fs::Fs, - metadata::Metadata as MetadataProvider, - wdk_build::WdkBuild, + exec::CommandExec, fs::Fs, metadata::Metadata as MetadataProvider, wdk_build::WdkBuild, }; use crate::{ actions::{ - Profile, - TargetArch, + Profile, TargetArch, build::{BuildAction, BuildActionError, BuildActionParams}, to_target_triple, }, diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index 1e147a267..e085a2e3c 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -12,12 +12,7 @@ use mockall_double::double; use wdk_build::CpuArchitecture; use crate::actions::{ - DriverType, - KMDF_STR, - Profile, - TargetArch, - UMDF_STR, - WDM_STR, + DriverType, KMDF_STR, Profile, TargetArch, UMDF_STR, WDM_STR, build::{BuildAction, BuildActionParams}, new::NewAction, }; diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index c565e367d..3ee7d9321 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -3,6 +3,7 @@ #![allow(clippy::literal_string_with_formatting_args)] use fs4::fs_std::FileExt; +use wdk_build::utils::set_var; /// Sets the `RUSTFLAGS` environment variable to include `+crt-static`. /// @@ -14,18 +15,10 @@ use fs4::fs_std::FileExt; pub fn set_crt_static_flag() { if let Ok(rustflags) = std::env::var("RUSTFLAGS") { let updated_rust_flags = format!("{rustflags} -C target-feature=+crt-static"); - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var("RUSTFLAGS", updated_rust_flags); - } + set_var("RUSTFLAGS", updated_rust_flags); println!("RUSTFLAGS set, adding the +crt-static: {rustflags:?}"); } else { - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); - } + set_var("RUSTFLAGS", "-C target-feature=+crt-static"); println!( "No RUSTFLAGS set, setting it to: {:?}", std::env::var("RUSTFLAGS").expect("RUSTFLAGS not set") diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index 99319669b..cd9b689c7 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -31,9 +31,7 @@ mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; use wdk_sys::{ - POOL_FLAG_NON_PAGED, - SIZE_T, - ULONG, + POOL_FLAG_NON_PAGED, SIZE_T, ULONG, ntddk::{ExAllocatePool2, ExFreePool}, }; diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index ace26fd2d..2f1299b35 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -158,10 +158,7 @@ let serialized_wdk_metadata_map = wdk_build::metadata::to_map_with_prefix:: impl IntoIterator { }; if let Some(toolchain) = toolchain_arg { - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); - } + set_var(CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN_ENV_VAR, toolchain); } CommandLineInterface::parse_from(env_args.iter()).parse_cargo_args(); @@ -658,11 +642,7 @@ pub fn setup_wdk_version() -> Result, ConfigErr }); } - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); - } + set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); Ok([WDK_VERSION_ENV_VAR].map(std::string::ToString::to_string)) } @@ -1132,14 +1112,10 @@ fn configure_wdf_build_output_dir(target_arg: Option<&String>, cargo_make_cargo_ output_dir }; - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var( - WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, - wdk_build_output_directory, - ); - } + set_var( + WDK_BUILD_OUTPUT_DIRECTORY_ENV_VAR, + wdk_build_output_directory, + ); } fn append_to_space_delimited_env_var(env_var_name: S, string_to_append: T) @@ -1153,11 +1129,7 @@ where let mut env_var_value: String = env::var(env_var_name).unwrap_or_default(); env_var_value.push(' '); env_var_value.push_str(string_to_append); - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(env_var_name, env_var_value.trim()); - } + set_var(env_var_name, env_var_value.trim()); } fn prepend_to_semicolon_delimited_env_var(env_var_name: S, string_to_prepend: T) @@ -1171,11 +1143,7 @@ where let mut env_var_value = string_to_prepend.to_string(); env_var_value.push(';'); env_var_value.push_str(env::var(env_var_name).unwrap_or_default().as_str()); - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - env::set_var(env_var_name, env_var_value); - } + set_var(env_var_name, env_var_value); } /// `cargo-make` condition script for `infverif` task in diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 031902953..da34766ef 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -1445,6 +1445,7 @@ mod tests { use std::{collections::HashMap, ffi::OsStr, sync::Mutex}; use super::*; + use crate::utils::{remove_var, set_var}; /// Runs function after modifying environment variables, and returns the /// function's return value. @@ -1480,11 +1481,7 @@ mod tests { "Duplicate environment variable keys were provided" ); } - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var(key, value); - } + set_var(key, value); } let f_return_value = f(); @@ -1493,18 +1490,10 @@ mod tests { for (key, _) in env_vars_key_value_pairs { original_env_vars.get(key).map_or_else( || { - // SAFETY: env::remove_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::remove_var(key); - } + remove_var(key); }, |value| { - // SAFETY: env::set_var is always safe on Windows according to documentation, - // and this code runs in a WDK environment which is always Windows. - unsafe { - std::env::set_var(key, value); - } + set_var(key, value); }, ); } diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 2871b894b..503d24068 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -6,7 +6,7 @@ use std::{ env, - ffi::CStr, + ffi::{CStr, OsStr}, io, path::{Path, PathBuf}, str::FromStr, @@ -15,19 +15,16 @@ use std::{ use thiserror::Error; use windows::{ Win32::System::Registry::{ - HKEY, - HKEY_LOCAL_MACHINE, - KEY_READ, - RRF_RT_REG_SZ, - RegCloseKey, - RegGetValueA, - RegOpenKeyExA, + HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, RegCloseKey, RegGetValueA, RegOpenKeyExA, }, core::{PCSTR, s}, }; use crate::{ConfigError, CpuArchitecture}; +/// The value for Windows in Rust's [`std::env::consts::OS`] +const RUST_ENV_CONST_OS_WINDOWS: &str = "windows"; + /// Errors that may occur when stripping the extended path prefix from a path #[derive(Debug, Error, PartialEq, Eq)] pub enum StripExtendedPathPrefixError { @@ -234,7 +231,7 @@ pub fn get_latest_windows_sdk_version(path_to_search: &Path) -> Result CpuArchitecture { - let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").expect( + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect( "Cargo should have set the CARGO_CFG_TARGET_ARCH environment variable when executing \ build.rs", ); @@ -449,6 +446,87 @@ pub(crate) fn find_max_version_in_directory>( }) } +/// Safely sets an environment variable, panicking if not running on a Windows +/// host. +/// +/// This function provides a safe wrapper around [`std::env::set_var`] that +/// became unsafe in Rust 2024 edition. It validates that the current **host** +/// OS (where the build is running) is Windows before calling the unsafe +/// function. +/// +/// Note: This checks the host OS, not the target OS. If you're cross-compiling +/// from macOS to Windows, this will still panic because the host (macOS) is not +/// Windows. +/// +/// # Panics +/// +/// Panics if the current host OS is not Windows, since environment variable +/// operations are only guaranteed to be safe on Windows according to Rust +/// documentation. +/// +/// # Examples +/// +/// ``` +/// wdk_build::utils::set_var("MY_BUILD_VAR", "my_value"); +/// ``` +pub fn set_var(key: K, value: V) +where + K: AsRef, + V: AsRef, +{ + assert!( + env::consts::OS == RUST_ENV_CONST_OS_WINDOWS, + "Environment variable operations are only safe on Windows. This code is designed to run \ + on a Windows host machine in a WDK environment. Current host OS: {}", + env::consts::OS + ); + // SAFETY: We've verified this is running on Windows host, where env::set_var is + // always safe according to Rust documentation. + unsafe { + env::set_var(key, value); + } +} + +/// Safely removes an environment variable, panicking if not running on a +/// Windows host. +/// +/// This function provides a safe wrapper around [`std::env::remove_var`] that +/// became unsafe in Rust 2024 edition. It validates that the current **host** +/// OS (where the build is running) is Windows before calling the unsafe +/// function. +/// +/// Note: This checks the host OS, not the target OS. If you're cross-compiling +/// from macOS to Windows, this will still panic because the host (macOS) is not +/// Windows. +/// +/// # Panics +/// +/// Panics if the current host OS is not Windows, since environment variable +/// operations are only guaranteed to be safe on Windows according to Rust +/// documentation. +/// +/// # Examples +/// +/// ``` +/// wdk_build::utils::remove_var("MY_BUILD_VAR"); +/// ``` +pub fn remove_var(key: K) +where + K: AsRef, +{ + assert!( + env::consts::OS == RUST_ENV_CONST_OS_WINDOWS, + "Environment variable operations are only safe on Windows. This code is designed to run \ + on a Windows host machine in a WDK environment. Current host OS: {}", + env::consts::OS + ); + // SAFETY: We've verified this is running on Windows host, where env::remove_var + // is always safe according to Rust documentation. + unsafe { + env::remove_var(key); + } +} + #[cfg(test)] mod tests { use assert_fs::prelude::*; @@ -718,9 +796,7 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ - FOLDERID_ProgramFiles, - KF_FLAG_DEFAULT, - SHGetKnownFolderPath, + FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, SHGetKnownFolderPath, }; use super::*; @@ -942,4 +1018,63 @@ mod tests { ); } } + + mod safe_env_vars { + use super::*; + + #[test] + fn set_var_works_on_windows() { + // This test will only pass on Windows host, which is the intended behavior + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + set_var("WDK_BUILD_TEST_VAR", "test_value"); + assert_eq!(env::var("WDK_BUILD_TEST_VAR").unwrap(), "test_value"); + remove_var("WDK_BUILD_TEST_VAR"); + } + } + + #[test] + fn remove_var_works_on_windows() { + // This test will only pass on Windows host, which is the intended behavior + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + set_var("WDK_BUILD_TEST_REMOVE_VAR", "test_value"); + assert_eq!(env::var("WDK_BUILD_TEST_REMOVE_VAR").unwrap(), "test_value"); + remove_var("WDK_BUILD_TEST_REMOVE_VAR"); + assert!(env::var("WDK_BUILD_TEST_REMOVE_VAR").is_err()); + } + } + + #[test] + #[should_panic(expected = "Environment variable operations are only safe on Windows")] + fn set_var_panics_on_non_windows() { + // This test simulates non-Windows behavior by checking the panic message + // In practice, this will only run on Windows in CI/development + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + // On Windows, manually trigger the panic for testing + panic!( + "Environment variable operations are only safe on Windows. This code is \ + designed to run on a Windows host machine in a WDK environment. Current host \ + OS: windows" + ); + } else { + set_var("TEST_VAR", "test_value"); + } + } + + #[test] + #[should_panic(expected = "Environment variable operations are only safe on Windows")] + fn remove_var_panics_on_non_windows() { + // This test simulates non-Windows behavior by checking the panic message + // In practice, this will only run on Windows in CI/development + if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { + // On Windows, manually trigger the panic for testing + panic!( + "Environment variable operations are only safe on Windows. This code is \ + designed to run on a Windows host machine in a WDK environment. Current host \ + OS: windows" + ); + } else { + remove_var("TEST_VAR"); + } + } + } } diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index 67e735602..dddb43761 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -15,33 +15,11 @@ use quote::{format_ident, quote, ToTokens}; use serde::{Deserialize, Serialize}; use syn::{ parse::{Parse, ParseStream, Parser}, - 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, }; /// Name of the `bindgen`-generated Rust module that contains the `TableIndex` diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index c5e4614a6..4c0fbdd06 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -24,13 +24,7 @@ use tracing_subscriber::{ filter::{LevelFilter, ParseError}, }; use wdk_build::{ - ApiSubset, - BuilderExt, - Config, - ConfigError, - DriverConfig, - KmdfConfig, - UmdfConfig, + ApiSubset, BuilderExt, Config, ConfigError, DriverConfig, KmdfConfig, UmdfConfig, configure_wdk_library_build_and_then, }; @@ -120,6 +114,8 @@ static TEST_STUBS_TEMPLATE: LazyLock = LazyLock::new(|| { use crate::WDFFUNC; /// Stubbed version of the symbol that `WdfFunctions` links to so that test targets will compile +// SAFETY: Generated WDF symbol name is required for test compilation and is unique per build. +// No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub static mut {WDFFUNCTIONS_SYMBOL_NAME_PLACEHOLDER}: *const WDFFUNC = core::ptr::null(); ", diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index 6d3c69c24..e9f8b9fe6 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -117,13 +117,18 @@ mod macros; // necessary due to LLVM being too eager to set it: it checks the LLVM IR for // floating point instructions - even if soft-float is enabled! #[allow(missing_docs)] +// SAFETY: _fltused is a required Windows linker symbol for floating point support. +// No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub static _fltused: () = (); // FIXME: Is there any way to avoid this stub? See https://github.com/rust-lang/rust/issues/101134 #[cfg(panic = "abort")] #[allow(missing_docs)] -#[allow(clippy::missing_const_for_fn)] // const extern is not yet supported: https://github.com/rust-lang/rust/issues/64926 +#[allow(clippy::missing_const_for_fn)] +// const extern is not yet supported: https://github.com/rust-lang/rust/issues/64926 +// SAFETY: __CxxFrameHandler3 is a required Windows C++ exception handler symbol. +// No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub extern "system" fn __CxxFrameHandler3() -> i32 { 0 diff --git a/crates/wdk-sys/src/test_stubs.rs b/crates/wdk-sys/src/test_stubs.rs index debdc9bd5..71d0462f1 100644 --- a/crates/wdk-sys/src/test_stubs.rs +++ b/crates/wdk-sys/src/test_stubs.rs @@ -2,7 +2,7 @@ // License: MIT OR Apache-2.0 //! Any library dependency that depends on `wdk-sys` requires these stubs to -//! provide symobols to successfully compile and run tests. +//! provide symbols to successfully compile and run tests. //! //! These stubs can be brought into scope by introducing `wdk-sys` with the //! `test-stubs` feature in the `dev-dependencies` of the crate's `Cargo.toml` @@ -41,6 +41,8 @@ mod wdf { /// Stubbed version of `WdfFunctionCount` Symbol so that test targets will /// compile + // SAFETY: WdfFunctionCount is a required WDF symbol for test compilation. + // No other symbols in this crate export this name, preventing linker conflicts. #[unsafe(no_mangle)] pub static mut WdfFunctionCount: ULONG = 0; diff --git a/crates/wdk/src/print.rs b/crates/wdk/src/print.rs index 5a0d1848f..efc950e5c 100644 --- a/crates/wdk/src/print.rs +++ b/crates/wdk/src/print.rs @@ -277,8 +277,7 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer() { - const TEST_STRING: &str = - "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ @@ -333,8 +332,7 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer_prints_all() { - const TEST_STRING: &str = - "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 760688aba..afbfc5c3b 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::{ - NTSTATUS, - WDF_OBJECT_ATTRIBUTES, - WDF_TIMER_CONFIG, - WDFTIMER, - call_unsafe_wdf_function_binding, + NTSTATUS, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, WDFTIMER, call_unsafe_wdf_function_binding, }; use crate::nt_success; diff --git a/examples/sample-kmdf-driver/src/lib.rs b/examples/sample-kmdf-driver/src/lib.rs index f04c842c7..f7dc197f1 100644 --- a/examples/sample-kmdf-driver/src/lib.rs +++ b/examples/sample-kmdf-driver/src/lib.rs @@ -51,6 +51,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/examples/sample-umdf-driver/src/lib.rs b/examples/sample-umdf-driver/src/lib.rs index 9d296ee58..63457ae27 100644 --- a/examples/sample-umdf-driver/src/lib.rs +++ b/examples/sample-umdf-driver/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/examples/sample-wdm-driver/src/lib.rs b/examples/sample-wdm-driver/src/lib.rs index 9bde8609f..5e690ac92 100644 --- a/examples/sample-wdm-driver/src/lib.rs +++ b/examples/sample-wdm-driver/src/lib.rs @@ -30,6 +30,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDM +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index 375e6f4b8..20b297dfd 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -51,6 +51,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs index 3f94cf937..8ab9ef442 100644 --- a/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs index 3f94cf937..8ab9ef442 100644 --- a/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/tests/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs index 9b0d5c200..784be3569 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/bug_unused_imports.rs @@ -36,6 +36,8 @@ use wdk_sys::{ WDF_NO_OBJECT_ATTRIBUTES, }; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs index 9e71fb85e..177818eb0 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_api_that_does_not_exist.rs @@ -5,6 +5,8 @@ use wdk_sys::*; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs index 25548ccf1..75ea68019 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_missing_arg.rs @@ -5,6 +5,8 @@ use wdk_sys::*; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs index 18265a810..ffcca5e83 100644 --- a/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs +++ b/tests/wdk-macros-tests/tests/inputs/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -5,6 +5,8 @@ use wdk_sys::*; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, From 0b420a4985d78cbf9fd61fd1092084930b09a814 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Mon, 4 Aug 2025 11:58:56 -0700 Subject: [PATCH 11/32] ran formatter --- crates/cargo-wdk/src/actions/build/tests.rs | 11 +++++--- crates/cargo-wdk/src/cli.rs | 7 ++++- crates/wdk-alloc/src/lib.rs | 4 ++- crates/wdk-build/src/cargo_make.rs | 9 +++++-- crates/wdk-build/src/utils.rs | 12 +++++++-- crates/wdk-macros/src/lib.rs | 30 ++++++++++++++++++--- crates/wdk-sys/build.rs | 8 +++++- crates/wdk/src/print.rs | 6 +++-- crates/wdk/src/wdf/timer.rs | 6 ++++- 9 files changed, 76 insertions(+), 17 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index e16540a6b..a11f5b076 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -14,17 +14,22 @@ use cargo_metadata::Metadata as CargoMetadata; use mockall::predicate::eq; use mockall_double::double; use wdk_build::{ - CpuArchitecture, DriverConfig, + CpuArchitecture, + DriverConfig, metadata::{TryFromCargoMetadataError, Wdk}, }; #[double] use crate::providers::{ - exec::CommandExec, fs::Fs, metadata::Metadata as MetadataProvider, wdk_build::WdkBuild, + exec::CommandExec, + fs::Fs, + metadata::Metadata as MetadataProvider, + wdk_build::WdkBuild, }; use crate::{ actions::{ - Profile, TargetArch, + Profile, + TargetArch, build::{BuildAction, BuildActionError, BuildActionParams}, to_target_triple, }, diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index e085a2e3c..1e147a267 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -12,7 +12,12 @@ use mockall_double::double; use wdk_build::CpuArchitecture; use crate::actions::{ - DriverType, KMDF_STR, Profile, TargetArch, UMDF_STR, WDM_STR, + DriverType, + KMDF_STR, + Profile, + TargetArch, + UMDF_STR, + WDM_STR, build::{BuildAction, BuildActionParams}, new::NewAction, }; diff --git a/crates/wdk-alloc/src/lib.rs b/crates/wdk-alloc/src/lib.rs index cd9b689c7..99319669b 100644 --- a/crates/wdk-alloc/src/lib.rs +++ b/crates/wdk-alloc/src/lib.rs @@ -31,7 +31,9 @@ mod kernel_mode { use core::alloc::{GlobalAlloc, Layout}; use wdk_sys::{ - POOL_FLAG_NON_PAGED, SIZE_T, ULONG, + POOL_FLAG_NON_PAGED, + SIZE_T, + ULONG, ntddk::{ExAllocatePool2, ExFreePool}, }; diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 04633238c..af19fea89 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -25,9 +25,14 @@ use clap::{Args, Parser}; use tracing::{instrument, trace}; use crate::{ - ConfigError, CpuArchitecture, metadata, + ConfigError, + CpuArchitecture, + metadata, utils::{ - PathExt, 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, set_var, }, }; diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 503d24068..0ab63a3c9 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -15,7 +15,13 @@ use std::{ use thiserror::Error; use windows::{ Win32::System::Registry::{ - HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, RegCloseKey, RegGetValueA, RegOpenKeyExA, + HKEY, + HKEY_LOCAL_MACHINE, + KEY_READ, + RRF_RT_REG_SZ, + RegCloseKey, + RegGetValueA, + RegOpenKeyExA, }, core::{PCSTR, s}, }; @@ -796,7 +802,9 @@ mod tests { mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ - FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, SHGetKnownFolderPath, + FOLDERID_ProgramFiles, + KF_FLAG_DEFAULT, + SHGetKnownFolderPath, }; use super::*; diff --git a/crates/wdk-macros/src/lib.rs b/crates/wdk-macros/src/lib.rs index dddb43761..67e735602 100644 --- a/crates/wdk-macros/src/lib.rs +++ b/crates/wdk-macros/src/lib.rs @@ -15,11 +15,33 @@ use quote::{format_ident, quote, ToTokens}; use serde::{Deserialize, Serialize}; use syn::{ parse::{Parse, ParseStream, Parser}, - 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, }; /// Name of the `bindgen`-generated Rust module that contains the `TableIndex` diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index 4c0fbdd06..5b3bf4ce0 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -24,7 +24,13 @@ use tracing_subscriber::{ filter::{LevelFilter, ParseError}, }; use wdk_build::{ - ApiSubset, BuilderExt, Config, ConfigError, DriverConfig, KmdfConfig, UmdfConfig, + ApiSubset, + BuilderExt, + Config, + ConfigError, + DriverConfig, + KmdfConfig, + UmdfConfig, configure_wdk_library_build_and_then, }; diff --git a/crates/wdk/src/print.rs b/crates/wdk/src/print.rs index efc950e5c..5a0d1848f 100644 --- a/crates/wdk/src/print.rs +++ b/crates/wdk/src/print.rs @@ -277,7 +277,8 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer() { - const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = + "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ @@ -332,7 +333,8 @@ mod dbg_print_buf_writer { #[test] fn write_that_exceeds_buffer_prints_all() { - const TEST_STRING: &str = "This is a test string that exceeds the buffer size limit set for \ + const TEST_STRING: &str = + "This is a test string that exceeds the buffer size limit set for \ DbgPrintBufWriter. It should trigger multiple flushes to handle the overflow \ correctly. The buffer has a limited capacity of 511 bytes (512 minus 1 for null \ terminator), and this string is intentionally much longer. When writing this \ diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index afbfc5c3b..760688aba 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::{ - NTSTATUS, WDF_OBJECT_ATTRIBUTES, WDF_TIMER_CONFIG, WDFTIMER, call_unsafe_wdf_function_binding, + NTSTATUS, + WDF_OBJECT_ATTRIBUTES, + WDF_TIMER_CONFIG, + WDFTIMER, + call_unsafe_wdf_function_binding, }; use crate::nt_success; From a4e0f0940a801361037595847379b02b982cdfaa Mon Sep 17 00:00:00 2001 From: leon-xd Date: Tue, 5 Aug 2025 12:03:55 -0700 Subject: [PATCH 12/32] fixed import in cargo_make.rs --- crates/wdk-build/src/cargo_make.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index af19fea89..826b27ac8 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -31,7 +31,7 @@ use crate::{ utils::{ PathExt, detect_wdk_content_root, - get_latest_windows_sdk_version, + detect_windows_sdk_version, get_wdk_version_number, set_var, }, From 3b437280266130e6a4b499ab4019caf2627a06c7 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Tue, 7 Oct 2025 12:04:24 -0700 Subject: [PATCH 13/32] target detection instead of host detection --- crates/cargo-wdk/tests/common.rs | 28 ++++- crates/wdk-build/src/lib.rs | 11 +- crates/wdk-build/src/utils.rs | 184 +++++++++++++------------------ 3 files changed, 106 insertions(+), 117 deletions(-) diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index 3ee7d9321..4733e6789 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -3,7 +3,6 @@ #![allow(clippy::literal_string_with_formatting_args)] use fs4::fs_std::FileExt; -use wdk_build::utils::set_var; /// Sets the `RUSTFLAGS` environment variable to include `+crt-static`. /// @@ -15,10 +14,33 @@ use wdk_build::utils::set_var; pub fn set_crt_static_flag() { if let Ok(rustflags) = std::env::var("RUSTFLAGS") { let updated_rust_flags = format!("{rustflags} -C target-feature=+crt-static"); - set_var("RUSTFLAGS", updated_rust_flags); + + #[cfg(target_os = "windows")] + // SAFETY: This is only called on Windows hosts, so this is safe. + unsafe { + std::env::set_var("RUSTFLAGS", updated_rust_flags); + } + + #[cfg(not(target_os = "windows"))] + compile_error!( + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) + ); + println!("RUSTFLAGS set, adding the +crt-static: {rustflags:?}"); } else { - set_var("RUSTFLAGS", "-C target-feature=+crt-static"); + #[cfg(target_os = "windows")] + // SAFETY: This is only called on Windows hosts, so this is safe. + unsafe { + std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); + } + + #[cfg(not(target_os = "windows"))] + compile_error!( + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) + ); + println!( "No RUSTFLAGS set, setting it to: {:?}", std::env::var("RUSTFLAGS").expect("RUSTFLAGS not set") diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index e6ebacea6..57a31286b 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -26,7 +26,7 @@ use tracing::debug; pub mod cargo_make; pub mod metadata; -pub mod utils; +mod utils; mod bindgen; @@ -1339,7 +1339,7 @@ impl CpuArchitecture { #[tracing::instrument(level = "debug")] pub fn find_top_level_cargo_manifest() -> PathBuf { let out_dir = - PathBuf::from(std::env::var("OUT_DIR").expect( + PathBuf::from(var("OUT_DIR").expect( "Cargo should have set the OUT_DIR environment variable when executing build.rs", )); @@ -1506,7 +1506,8 @@ mod tests { use std::{collections::HashMap, ffi::OsStr, sync::Mutex}; use super::*; - use crate::utils::{remove_var, set_var}; + + use crate::utils::{set_var, remove_var}; mod two_part_version { use super::*; @@ -1742,7 +1743,7 @@ mod tests { // set requested environment variables for (key, value) in env_vars_key_value_pairs { - if let Ok(original_value) = std::env::var(key) { + if let Ok(original_value) = env::var(key) { let insert_result = original_env_vars.insert(key, original_value); assert!( insert_result.is_none(), @@ -1758,7 +1759,7 @@ mod tests { for (key, _) in env_vars_key_value_pairs { original_env_vars.get(key).map_or_else( || { - remove_var(key); + remove_var(key); }, |value| { set_var(key, value); diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 899b5939c..0875eaf1c 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -26,9 +26,6 @@ use windows::{ use crate::{ConfigError, CpuArchitecture, TwoPartVersion}; -/// The value for Windows in Rust's [`std::env::consts::OS`] -const RUST_ENV_CONST_OS_WINDOWS: &str = "windows"; - /// Detect `WDKContentRoot` Directory. Logic is based off of Toolset.props in /// NI(22H2) WDK #[must_use] @@ -359,93 +356,104 @@ pub fn find_max_version_in_directory>( }) } -/// Safely sets an environment variable, panicking if not running on a Windows -/// host. +/// Safely sets an environment variable. Will not compile if crate is not targeted for Windows. /// /// This function provides a safe wrapper around [`std::env::set_var`] that -/// became unsafe in Rust 2024 edition. It validates that the current **host** -/// OS (where the build is running) is Windows before calling the unsafe -/// function. -/// -/// Note: This checks the host OS, not the target OS. If you're cross-compiling -/// from macOS to Windows, this will still panic because the host (macOS) is not -/// Windows. +/// became unsafe in Rust 2024 edition. /// /// # Panics -/// -/// Panics if the current host OS is not Windows, since environment variable -/// operations are only guaranteed to be safe on Windows according to Rust -/// documentation. -/// -/// # Examples -/// -/// ``` -/// wdk_build::utils::set_var("MY_BUILD_VAR", "my_value"); -/// ``` +/// +/// This function may panic if key is empty, contains an ASCII equals sign '=' or the NUL character '\0', or when value contains the NUL character. +#[cfg(target_os = "windows")] pub fn set_var(key: K, value: V) where K: AsRef, V: AsRef, { - assert!( - env::consts::OS == RUST_ENV_CONST_OS_WINDOWS, - "Environment variable operations are only safe on Windows. This code is designed to run \ - on a Windows host machine in a WDK environment. Current host OS: {}", - env::consts::OS - ); - // SAFETY: We've verified this is running on Windows host, where env::set_var is + // SAFETY: We've verified this is targeted for Windows, where env::set_var is // always safe according to Rust documentation. unsafe { env::set_var(key, value); } } -/// Safely removes an environment variable, panicking if not running on a -/// Windows host. +#[cfg(not(target_os = "windows"))] +pub fn set_var(_key: K, _value: V) +where + K: AsRef, + V: AsRef, +{ + compile_error!( + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) + ); +} + +/// Safely removes an environment variable. Will not compile if crate is not targeted for Windows. /// /// This function provides a safe wrapper around [`std::env::remove_var`] that -/// became unsafe in Rust 2024 edition. It validates that the current **host** -/// OS (where the build is running) is Windows before calling the unsafe -/// function. -/// -/// Note: This checks the host OS, not the target OS. If you're cross-compiling -/// from macOS to Windows, this will still panic because the host (macOS) is not -/// Windows. +/// became unsafe in Rust 2024 edition. /// /// # Panics -/// -/// Panics if the current host OS is not Windows, since environment variable -/// operations are only guaranteed to be safe on Windows according to Rust -/// documentation. -/// -/// # Examples -/// -/// ``` -/// wdk_build::utils::remove_var("MY_BUILD_VAR"); -/// ``` -#[allow(dead_code)] +/// +/// This function may panic if key is empty, contains an ASCII equals sign '=' or the NUL character '\0', or when value contains the NUL character. +#[cfg(target_os = "windows")] pub fn remove_var(key: K) where K: AsRef, { - assert!( - env::consts::OS == RUST_ENV_CONST_OS_WINDOWS, - "Environment variable operations are only safe on Windows. This code is designed to run \ - on a Windows host machine in a WDK environment. Current host OS: {}", - env::consts::OS - ); - // SAFETY: We've verified this is running on Windows host, where env::remove_var - // is always safe according to Rust documentation. + // SAFETY: We've verified this is targeted for Windows, where env::remove_var + // is always safe according to documentation. unsafe { env::remove_var(key); } } +#[cfg(not(target_os = "windows"))] +pub fn remove_var(_key: K) +where K: AsRef +{ + compile_error!( + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) + ); +} + + #[cfg(test)] mod tests { use assert_fs::prelude::*; use super::*; + + // Function with_clean_env clears the inputted environment variable and runs the closure + fn with_clean_env(key: &str, f: F) + where + F: FnOnce(), + { + let original = env::var(key).ok(); + + // SAFETY: We have verified that this is built for a Windows host due to no compile errors from building `set_var`. + unsafe { + env::remove_var(key); + } + + f(); + + if let Some(val) = &original { + // SAFETY: We have verified that this is built for a Windows host due to no compile errors from building `set_var`. + unsafe { + env::set_var(key, val); + } + } else { + // SAFETY: We have verified that this is built for a Windows host due to no compile errors from building `set_var`. + unsafe { + env::remove_var(key); + } + } + + assert!(env::var(key).ok() == original); + } mod read_registry_key_string_value { use windows::Win32::UI::Shell::{ @@ -456,6 +464,7 @@ mod tests { use super::*; + #[test] fn read_reg_key_programfilesdir() { let program_files_dir = @@ -678,58 +687,15 @@ mod tests { use super::*; #[test] - fn set_var_works_on_windows() { - // This test will only pass on Windows host, which is the intended behavior - if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { - set_var("WDK_BUILD_TEST_VAR", "test_value"); - assert_eq!(env::var("WDK_BUILD_TEST_VAR").unwrap(), "test_value"); - remove_var("WDK_BUILD_TEST_VAR"); - } - } - - #[test] - fn remove_var_works_on_windows() { - // This test will only pass on Windows host, which is the intended behavior - if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { - set_var("WDK_BUILD_TEST_REMOVE_VAR", "test_value"); - assert_eq!(env::var("WDK_BUILD_TEST_REMOVE_VAR").unwrap(), "test_value"); - remove_var("WDK_BUILD_TEST_REMOVE_VAR"); - assert!(env::var("WDK_BUILD_TEST_REMOVE_VAR").is_err()); - } - } - - #[test] - #[should_panic(expected = "Environment variable operations are only safe on Windows")] - fn set_var_panics_on_non_windows() { - // This test simulates non-Windows behavior by checking the panic message - // In practice, this will only run on Windows in CI/development - if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { - // On Windows, manually trigger the panic for testing - panic!( - "Environment variable operations are only safe on Windows. This code is \ - designed to run on a Windows host machine in a WDK environment. Current host \ - OS: windows" - ); - } else { - set_var("TEST_VAR", "test_value"); - } - } - - #[test] - #[should_panic(expected = "Environment variable operations are only safe on Windows")] - fn remove_var_panics_on_non_windows() { - // This test simulates non-Windows behavior by checking the panic message - // In practice, this will only run on Windows in CI/development - if env::consts::OS == RUST_ENV_CONST_OS_WINDOWS { - // On Windows, manually trigger the panic for testing - panic!( - "Environment variable operations are only safe on Windows. This code is \ - designed to run on a Windows host machine in a WDK environment. Current host \ - OS: windows" - ); - } else { - remove_var("TEST_VAR"); - } + fn set_var_and_remove_var() { + let key = "WDK_BUILD_TEST_VAR"; + with_clean_env(key, || { + set_var(key, "test_value"); + assert_eq!(env::var(key).unwrap(), "test_value"); + remove_var(key); + assert!(env::var(key).is_err()); + }); } } + } From 18858d10bfbe7f3642e2821935faa171cf462dfd Mon Sep 17 00:00:00 2001 From: leon-xd Date: Wed, 8 Oct 2025 12:03:35 -0700 Subject: [PATCH 14/32] added rest of safety comments --- README.md | 2 ++ crates/cargo-wdk/templates/kmdf/lib.rs.tmp | 2 ++ crates/cargo-wdk/templates/umdf/lib.rs.tmp | 2 ++ crates/cargo-wdk/templates/wdm/lib.rs.tmp | 2 ++ .../umdf-driver-workspace/crates/driver_1/src/lib.rs | 2 ++ .../umdf-driver-workspace/crates/driver_2/src/lib.rs | 2 ++ crates/cargo-wdk/tests/kmdf-driver/src/lib.rs | 2 ++ .../mixed-package-kmdf-workspace/crates/driver/src/lib.rs | 2 ++ crates/cargo-wdk/tests/umdf-driver/src/lib.rs | 2 ++ crates/cargo-wdk/tests/wdm-driver/src/lib.rs | 2 ++ crates/wdk-sys/src/test_stubs.rs | 2 ++ .../tests/inputs/macrotest/wdf_driver_create.rs | 3 ++- .../outputs/beta/macrotest/bug_unused_imports.expanded.rs | 2 ++ .../tests/outputs/beta/macrotest/wdf_driver_create.expanded.rs | 2 ++ .../outputs/nightly/macrotest/bug_unused_imports.expanded.rs | 2 ++ .../outputs/nightly/macrotest/wdf_driver_create.expanded.rs | 2 ++ .../outputs/stable/macrotest/bug_unused_imports.expanded.rs | 2 ++ .../outputs/stable/macrotest/wdf_driver_create.expanded.rs | 2 ++ 18 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 33f01df5a..f48811513 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,8 @@ The crates in this repository are available from [`crates.io`](https://crates.io PCUNICODE_STRING, }; + // SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. + // No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/templates/kmdf/lib.rs.tmp b/crates/cargo-wdk/templates/kmdf/lib.rs.tmp index 3c1699a7b..6a6075faf 100644 --- a/crates/cargo-wdk/templates/kmdf/lib.rs.tmp +++ b/crates/cargo-wdk/templates/kmdf/lib.rs.tmp @@ -16,6 +16,8 @@ use wdk_alloc::WdkAllocator; #[global_allocator] static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( _driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/templates/umdf/lib.rs.tmp b/crates/cargo-wdk/templates/umdf/lib.rs.tmp index e610ad4cf..cd0931215 100644 --- a/crates/cargo-wdk/templates/umdf/lib.rs.tmp +++ b/crates/cargo-wdk/templates/umdf/lib.rs.tmp @@ -4,6 +4,8 @@ use wdk_sys::{ PCUNICODE_STRING, }; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( _driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/templates/wdm/lib.rs.tmp b/crates/cargo-wdk/templates/wdm/lib.rs.tmp index 3c1699a7b..6a6075faf 100644 --- a/crates/cargo-wdk/templates/wdm/lib.rs.tmp +++ b/crates/cargo-wdk/templates/wdm/lib.rs.tmp @@ -16,6 +16,8 @@ use wdk_alloc::WdkAllocator; #[global_allocator] static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( _driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs index 567b757ae..766cb5866 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_1/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs index 567b757ae..766cb5866 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/crates/driver_2/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/tests/kmdf-driver/src/lib.rs b/crates/cargo-wdk/tests/kmdf-driver/src/lib.rs index 3c1699a7b..6a6075faf 100644 --- a/crates/cargo-wdk/tests/kmdf-driver/src/lib.rs +++ b/crates/cargo-wdk/tests/kmdf-driver/src/lib.rs @@ -16,6 +16,8 @@ use wdk_alloc::WdkAllocator; #[global_allocator] static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( _driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index e4587f2d7..fae594cbc 100644 --- a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -47,6 +47,8 @@ static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: &mut DRIVER_OBJECT, diff --git a/crates/cargo-wdk/tests/umdf-driver/src/lib.rs b/crates/cargo-wdk/tests/umdf-driver/src/lib.rs index 567b757ae..766cb5866 100644 --- a/crates/cargo-wdk/tests/umdf-driver/src/lib.rs +++ b/crates/cargo-wdk/tests/umdf-driver/src/lib.rs @@ -33,6 +33,8 @@ use wdk_sys::{ /// /// # Safety /// Function is unsafe since it dereferences raw pointers passed to it from WDF +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, diff --git a/crates/cargo-wdk/tests/wdm-driver/src/lib.rs b/crates/cargo-wdk/tests/wdm-driver/src/lib.rs index 3c1699a7b..6a6075faf 100644 --- a/crates/cargo-wdk/tests/wdm-driver/src/lib.rs +++ b/crates/cargo-wdk/tests/wdm-driver/src/lib.rs @@ -16,6 +16,8 @@ use wdk_alloc::WdkAllocator; #[global_allocator] static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( _driver: PDRIVER_OBJECT, diff --git a/crates/wdk-sys/src/test_stubs.rs b/crates/wdk-sys/src/test_stubs.rs index 71d0462f1..ff301dc38 100644 --- a/crates/wdk-sys/src/test_stubs.rs +++ b/crates/wdk-sys/src/test_stubs.rs @@ -27,6 +27,8 @@ use crate::{DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING}; driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF" ))] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub const unsafe extern "system" fn driver_entry_stub( _driver: &mut DRIVER_OBJECT, diff --git a/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs index 095d067d9..ebdca79b2 100644 --- a/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs +++ b/tests/wdk-macros-tests/tests/inputs/macrotest/wdf_driver_create.rs @@ -2,7 +2,8 @@ // License: MIT OR Apache-2.0 #![no_main] #![deny(warnings)] - +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, 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 b1451a812..96284c628 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 @@ -23,6 +23,8 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, 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 d99bbb959..f12238697 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 @@ -1,5 +1,7 @@ #![no_main] #![deny(warnings)] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, 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 b1451a812..96284c628 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 @@ -23,6 +23,8 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, 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 d99bbb959..f12238697 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 @@ -1,5 +1,7 @@ #![no_main] #![deny(warnings)] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, 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 b1451a812..96284c628 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 @@ -23,6 +23,8 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, 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 d99bbb959..f12238697 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 @@ -1,5 +1,7 @@ #![no_main] #![deny(warnings)] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, From 177b8fb7cff601d7a5dd4b547973531142fd1595 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Wed, 8 Oct 2025 15:41:22 -0700 Subject: [PATCH 15/32] fmt, build working --- crates/cargo-wdk/src/actions/build/mod.rs | 2 +- crates/cargo-wdk/tests/common.rs | 12 +++-- crates/cargo-wdk/tests/new_command_test.rs | 2 +- crates/wdk-build/rust-driver-makefile.toml | 12 ++++- crates/wdk-build/src/bindgen.rs | 2 +- crates/wdk-build/src/cargo_make.rs | 9 +--- crates/wdk-build/src/lib.rs | 9 ++-- crates/wdk-build/src/utils.rs | 56 +++++++++++++--------- crates/wdk-sys/src/lib.rs | 8 +++- 9 files changed, 66 insertions(+), 46 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/mod.rs b/crates/cargo-wdk/src/actions/build/mod.rs index d78ecc58a..74b2bd1af 100644 --- a/crates/cargo-wdk/src/actions/build/mod.rs +++ b/crates/cargo-wdk/src/actions/build/mod.rs @@ -13,7 +13,7 @@ mod package_task; #[cfg(test)] mod tests; use std::{ - path::{absolute, Path, PathBuf}, + path::{Path, PathBuf, absolute}, result::Result::Ok, }; diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index 4733e6789..f4ee3ea17 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -14,16 +14,17 @@ use fs4::fs_std::FileExt; pub fn set_crt_static_flag() { if let Ok(rustflags) = std::env::var("RUSTFLAGS") { let updated_rust_flags = format!("{rustflags} -C target-feature=+crt-static"); - + #[cfg(target_os = "windows")] // SAFETY: This is only called on Windows hosts, so this is safe. unsafe { std::env::set_var("RUSTFLAGS", updated_rust_flags); } - #[cfg(not(target_os = "windows"))] + #[cfg(not(target_os = "windows"))] compile_error!( - "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK \ + environment. Please build using a Windows target. Current target: {}", env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) ); @@ -35,9 +36,10 @@ pub fn set_crt_static_flag() { std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); } - #[cfg(not(target_os = "windows"))] + #[cfg(not(target_os = "windows"))] compile_error!( - "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK \ + environment. Please build using a Windows target. Current target: {}", env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) ); diff --git a/crates/cargo-wdk/tests/new_command_test.rs b/crates/cargo-wdk/tests/new_command_test.rs index 7591bb24f..a83a50e19 100644 --- a/crates/cargo-wdk/tests/new_command_test.rs +++ b/crates/cargo-wdk/tests/new_command_test.rs @@ -145,7 +145,7 @@ fn create_and_build_new_driver_project(driver_type: &str) -> (String, String) { tmp_dir.path().join(&driver_name).display() ))); - // asert paths + // assert paths assert!(tmp_dir.join(&driver_name).is_dir()); assert!(tmp_dir.join(&driver_name).join("build.rs").is_file()); assert!(tmp_dir.join(&driver_name).join("Cargo.toml").is_file()); diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index 47b532af8..a7f9e50df 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -157,8 +157,18 @@ let serialized_wdk_metadata_map = wdk_build::metadata::to_map_with_prefix:: PathBuf { let out_dir = - PathBuf::from(var("OUT_DIR").expect( + PathBuf::from(env::var("OUT_DIR").expect( "Cargo should have set the OUT_DIR environment variable when executing build.rs", )); @@ -1506,8 +1506,7 @@ mod tests { use std::{collections::HashMap, ffi::OsStr, sync::Mutex}; use super::*; - - use crate::utils::{set_var, remove_var}; + use crate::utils::{remove_var, set_var}; mod two_part_version { use super::*; @@ -1759,7 +1758,7 @@ mod tests { for (key, _) in env_vars_key_value_pairs { original_env_vars.get(key).map_or_else( || { - remove_var(key); + remove_var(key); }, |value| { set_var(key, value); diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 0875eaf1c..78a02da72 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -12,16 +12,16 @@ use std::{ }; use windows::{ - core::{s, PCSTR}, Win32::System::Registry::{ - RegCloseKey, - RegGetValueA, - RegOpenKeyExA, HKEY, HKEY_LOCAL_MACHINE, KEY_READ, RRF_RT_REG_SZ, + RegCloseKey, + RegGetValueA, + RegOpenKeyExA, }, + core::{PCSTR, s}, }; use crate::{ConfigError, CpuArchitecture, TwoPartVersion}; @@ -356,14 +356,16 @@ pub fn find_max_version_in_directory>( }) } -/// Safely sets an environment variable. Will not compile if crate is not targeted for Windows. +/// Safely sets an environment variable. Will not compile if crate is not +/// targeted for Windows. /// /// This function provides a safe wrapper around [`std::env::set_var`] that /// became unsafe in Rust 2024 edition. /// /// # Panics -/// -/// This function may panic if key is empty, contains an ASCII equals sign '=' or the NUL character '\0', or when value contains the NUL character. +/// +/// This function may panic if key is empty, contains an ASCII equals sign '=' +/// or the NUL character '\0', or when value contains the NUL character. #[cfg(target_os = "windows")] pub fn set_var(key: K, value: V) where @@ -378,25 +380,29 @@ where } #[cfg(not(target_os = "windows"))] -pub fn set_var(_key: K, _value: V) -where +pub fn set_var(_key: K, _value: V) +where K: AsRef, V: AsRef, { compile_error!( - "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. \ + Please build using a Windows target. Current target: {}", env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) ); } -/// Safely removes an environment variable. Will not compile if crate is not targeted for Windows. +/// Safely removes an environment variable. Will not compile if crate is not +/// targeted for Windows. /// /// This function provides a safe wrapper around [`std::env::remove_var`] that /// became unsafe in Rust 2024 edition. /// /// # Panics -/// -/// This function may panic if key is empty, contains an ASCII equals sign '=' or the NUL character '\0', or when value contains the NUL character. +/// +/// This function may panic if key is empty, contains an ASCII equals sign '=' +/// or the NUL character '\0', or when value contains the NUL character. +#[allow(dead_code)] #[cfg(target_os = "windows")] pub fn remove_var(key: K) where @@ -409,31 +415,35 @@ where } } +#[allow(dead_code)] #[cfg(not(target_os = "windows"))] pub fn remove_var(_key: K) -where K: AsRef +where + K: AsRef, { compile_error!( - "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. Please build using a Windows target. Current target: {}", + "windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. \ + Please build using a Windows target. Current target: {}", env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) ); } - #[cfg(test)] mod tests { use assert_fs::prelude::*; use super::*; - - // Function with_clean_env clears the inputted environment variable and runs the closure + + // Function with_clean_env clears the inputted environment variable and runs the + // closure fn with_clean_env(key: &str, f: F) where F: FnOnce(), { let original = env::var(key).ok(); - // SAFETY: We have verified that this is built for a Windows host due to no compile errors from building `set_var`. + // SAFETY: We have verified that this is built for a Windows host due to no + // compile errors from building `set_var`. unsafe { env::remove_var(key); } @@ -441,12 +451,14 @@ mod tests { f(); if let Some(val) = &original { - // SAFETY: We have verified that this is built for a Windows host due to no compile errors from building `set_var`. + // SAFETY: We have verified that this is built for a Windows host due to no + // compile errors from building `set_var`. unsafe { env::set_var(key, val); } } else { - // SAFETY: We have verified that this is built for a Windows host due to no compile errors from building `set_var`. + // SAFETY: We have verified that this is built for a Windows host due to no + // compile errors from building `set_var`. unsafe { env::remove_var(key); } @@ -464,7 +476,6 @@ mod tests { use super::*; - #[test] fn read_reg_key_programfilesdir() { let program_files_dir = @@ -697,5 +708,4 @@ mod tests { }); } } - } diff --git a/crates/wdk-sys/src/lib.rs b/crates/wdk-sys/src/lib.rs index da3f93463..39a88977c 100644 --- a/crates/wdk-sys/src/lib.rs +++ b/crates/wdk-sys/src/lib.rs @@ -134,7 +134,9 @@ pub const extern "system" fn __CxxFrameHandler3() -> i32 { #[cfg(panic = "abort")] #[allow(missing_docs)] -#[no_mangle] +// SAFETY: __CxxFrameHandler4 is a required Windows C++ exception handler symbol. +// No other symbols in this crate export this name, preventing linker conflicts. +#[unsafe(no_mangle)] pub const extern "system" fn __CxxFrameHandler4() -> i32 { // This is a stub for the C++ exception handling frame handler. It's never // called but it needs to be distinct from __CxxFrameHandler3 to not confuse @@ -144,7 +146,9 @@ pub const extern "system" fn __CxxFrameHandler4() -> i32 { #[cfg(panic = "abort")] #[allow(missing_docs)] -#[no_mangle] +// SAFETY: __GSHandlerCheck_EH4 is a required Windows C++ exception handler symbol. +// No other symbols in this crate export this name, preventing linker conflicts. +#[unsafe(no_mangle)] pub const extern "system" fn __GSHandlerCheck_EH4() -> i32 { // This is a stub for the C++ exception handling frame handler. It's never // called but it needs to be distinct from __CxxFrameHandler3 and From 476a5976e0cd15942d749a3d54a2a9d2a65d59b4 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Wed, 8 Oct 2025 15:47:24 -0700 Subject: [PATCH 16/32] additional lockfile --- .../umdf-driver-workspace/Cargo.lock | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/Cargo.lock b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/Cargo.lock index 147698235..d3ee0ffb9 100644 --- a/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/Cargo.lock +++ b/crates/cargo-wdk/tests/emulated-workspace/umdf-driver-workspace/Cargo.lock @@ -127,10 +127,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.17" +version = "1.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb" dependencies = [ + "find-msvc-tools", "shlex", ] @@ -145,9 +146,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "clang-sys" @@ -250,6 +251,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "find-msvc-tools" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" + [[package]] name = "fs4" version = "0.13.1" @@ -555,9 +562,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", From 79608e35c75a9211052f94214e9a540afe2bea79 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Wed, 8 Oct 2025 15:54:28 -0700 Subject: [PATCH 17/32] fixed compile_error string --- crates/cargo-wdk/tests/common.rs | 6 ++---- crates/wdk-build/rust-driver-makefile.toml | 4 ++-- crates/wdk-build/src/utils.rs | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/cargo-wdk/tests/common.rs b/crates/cargo-wdk/tests/common.rs index f4ee3ea17..a5135bbbd 100644 --- a/crates/cargo-wdk/tests/common.rs +++ b/crates/cargo-wdk/tests/common.rs @@ -24,8 +24,7 @@ pub fn set_crt_static_flag() { #[cfg(not(target_os = "windows"))] compile_error!( "windows-drivers-rs is designed to be run on a Windows host machine in a WDK \ - environment. Please build using a Windows target. Current target: {}", - env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) + environment. Please build using a Windows target." ); println!("RUSTFLAGS set, adding the +crt-static: {rustflags:?}"); @@ -39,8 +38,7 @@ pub fn set_crt_static_flag() { #[cfg(not(target_os = "windows"))] compile_error!( "windows-drivers-rs is designed to be run on a Windows host machine in a WDK \ - environment. Please build using a Windows target. Current target: {}", - env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "unknown".to_string()) + environment. Please build using a Windows target." ); println!( diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index a7f9e50df..e82b9376f 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -159,8 +159,8 @@ let serialized_wdk_metadata_map = wdk_build::metadata::to_map_with_prefix:: Date: Wed, 8 Oct 2025 23:34:03 -0700 Subject: [PATCH 18/32] fixed failing tests --- crates/wdk-build/src/cargo_make.rs | 5 +++-- tests/customized-config-toml-workspace/Cargo.lock | 5 +++-- .../outputs/beta/macrotest/bug_unused_imports.expanded.rs | 2 -- .../outputs/beta/macrotest/wdf_driver_create.expanded.rs | 2 -- .../outputs/nightly/macrotest/bug_unused_imports.expanded.rs | 2 -- .../outputs/nightly/macrotest/wdf_driver_create.expanded.rs | 2 -- .../outputs/stable/macrotest/bug_unused_imports.expanded.rs | 2 -- .../outputs/stable/macrotest/wdf_driver_create.expanded.rs | 2 -- 8 files changed, 6 insertions(+), 16 deletions(-) diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 9a6da1746..d89cd90d1 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -699,8 +699,9 @@ pub fn setup_infverif_for_samples + ToString + ?Sized>( .parse::() .expect("Unable to parse the build number of the WDK version string as an int!"); let sample_flag = if version > MINIMUM_SAMPLES_FLAG_WDK_VERSION { - "/samples" // Note: Not currently implemented, so in samples TOML we - // currently skip infverif + // Note: Not currently implemented, so in samples TOML we currently skip + // infverif + "/samples" } else { "/msft" }; diff --git a/tests/customized-config-toml-workspace/Cargo.lock b/tests/customized-config-toml-workspace/Cargo.lock index c7e63176b..b665c3efe 100644 --- a/tests/customized-config-toml-workspace/Cargo.lock +++ b/tests/customized-config-toml-workspace/Cargo.lock @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "clang-sys" @@ -540,6 +540,7 @@ dependencies = [ "clap", "clap-cargo", "paste", + "regex", "rustversion", "semver", "serde", 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 96284c628..b1451a812 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 @@ -23,8 +23,6 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, 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 f12238697..d99bbb959 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 @@ -1,7 +1,5 @@ #![no_main] #![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, 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 96284c628..b1451a812 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 @@ -23,8 +23,6 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, 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 f12238697..d99bbb959 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 @@ -1,7 +1,5 @@ #![no_main] #![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, 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 96284c628..b1451a812 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 @@ -23,8 +23,6 @@ use wdk_sys::{ call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, }; -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: PDRIVER_OBJECT, 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 f12238697..d99bbb959 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 @@ -1,7 +1,5 @@ #![no_main] #![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] pub extern "system" fn driver_entry( driver: wdk_sys::PDRIVER_OBJECT, From 893002bc654b5e60c1fd446ed722389e9b41b730 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 9 Oct 2025 00:43:44 -0700 Subject: [PATCH 19/32] fix expanded macro --- .../mixed-package-kmdf-workspace/Cargo.lock | 19 +++++++++++++------ .../bug_tuple_struct_shadowing.expanded.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_device_create.expanded.rs | 2 +- ...device_create_device_interface.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- ...request_retrieve_output_buffer.expanded.rs | 2 +- .../wdf_spin_lock_acquire.expanded.rs | 2 +- .../wdf_verifier_dbg_break_point.expanded.rs | 2 +- .../bug_tuple_struct_shadowing.expanded.rs | 2 +- .../macrotest/bug_unused_imports.expanded.rs | 2 +- .../macrotest/wdf_device_create.expanded.rs | 2 +- ...device_create_device_interface.expanded.rs | 2 +- .../macrotest/wdf_driver_create.expanded.rs | 2 +- ...request_retrieve_output_buffer.expanded.rs | 2 +- .../wdf_spin_lock_acquire.expanded.rs | 2 +- .../wdf_verifier_dbg_break_point.expanded.rs | 2 +- 17 files changed, 29 insertions(+), 22 deletions(-) diff --git a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/Cargo.lock b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/Cargo.lock index 9a0115c63..fb7e9e4ec 100644 --- a/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/Cargo.lock +++ b/crates/cargo-wdk/tests/mixed-package-kmdf-workspace/Cargo.lock @@ -127,10 +127,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.17" +version = "1.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb" dependencies = [ + "find-msvc-tools", "shlex", ] @@ -145,9 +146,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "clang-sys" @@ -243,6 +244,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "find-msvc-tools" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" + [[package]] name = "fs4" version = "0.13.1" @@ -552,9 +559,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", 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 ca2b818d1..9001ca6c3 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 @@ -75,7 +75,7 @@ fn foo( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 b1451a812..634a9719f 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 @@ -86,7 +86,7 @@ pub extern "system" fn driver_entry( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 0e687de35..72f9a7ede 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 @@ -54,7 +54,7 @@ extern "C" fn evt_driver_device_add( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 1e10670e7..a7066878f 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 @@ -56,7 +56,7 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 d99bbb959..0049301cf 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 @@ -63,7 +63,7 @@ pub extern "system" fn driver_entry( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 c2654fcb8..b366b3dd4 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 @@ -54,7 +54,7 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 0e2142bf3..538a50995 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 @@ -38,7 +38,7 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 3e18daad9..3a1ba55f4 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 @@ -38,7 +38,7 @@ fn foo() { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 ca2b818d1..9001ca6c3 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 @@ -75,7 +75,7 @@ fn foo( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 b1451a812..634a9719f 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 @@ -86,7 +86,7 @@ pub extern "system" fn driver_entry( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 0e687de35..72f9a7ede 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 @@ -54,7 +54,7 @@ extern "C" fn evt_driver_device_add( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 1e10670e7..a7066878f 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 @@ -56,7 +56,7 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 d99bbb959..0049301cf 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 @@ -63,7 +63,7 @@ pub extern "system" fn driver_entry( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 c2654fcb8..b366b3dd4 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 @@ -54,7 +54,7 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 0e2142bf3..538a50995 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 @@ -38,7 +38,7 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 3e18daad9..3a1ba55f4 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 @@ -38,7 +38,7 @@ fn foo() { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; From 5ea1137dce33644af2d5e0278bd8ed6448a53fa3 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 9 Oct 2025 01:16:52 -0700 Subject: [PATCH 20/32] added commas to macrotest output --- .../beta/macrotest/bug_tuple_struct_shadowing.expanded.rs | 2 +- .../tests/outputs/beta/macrotest/wdf_device_create.expanded.rs | 2 +- .../macrotest/wdf_device_create_device_interface.expanded.rs | 2 +- .../macrotest/wdf_request_retrieve_output_buffer.expanded.rs | 2 +- .../outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs | 2 +- .../beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs | 2 +- .../stable/macrotest/bug_tuple_struct_shadowing.expanded.rs | 2 +- .../outputs/stable/macrotest/wdf_device_create.expanded.rs | 2 +- .../macrotest/wdf_device_create_device_interface.expanded.rs | 2 +- .../macrotest/wdf_request_retrieve_output_buffer.expanded.rs | 2 +- .../outputs/stable/macrotest/wdf_spin_lock_acquire.expanded.rs | 2 +- .../stable/macrotest/wdf_verifier_dbg_break_point.expanded.rs | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) 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 9001ca6c3..ca2b818d1 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 @@ -75,7 +75,7 @@ fn foo( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 72f9a7ede..0e687de35 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 @@ -54,7 +54,7 @@ extern "C" fn evt_driver_device_add( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 a7066878f..1e10670e7 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 @@ -56,7 +56,7 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 b366b3dd4..c2654fcb8 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 @@ -54,7 +54,7 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 538a50995..0e2142bf3 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 @@ -38,7 +38,7 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 3a1ba55f4..3e18daad9 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 @@ -38,7 +38,7 @@ fn foo() { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 9001ca6c3..ca2b818d1 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 @@ -75,7 +75,7 @@ fn foo( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 72f9a7ede..0e687de35 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 @@ -54,7 +54,7 @@ extern "C" fn evt_driver_device_add( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 a7066878f..1e10670e7 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 @@ -56,7 +56,7 @@ fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 b366b3dd4..c2654fcb8 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 @@ -54,7 +54,7 @@ fn process_wdf_request(request: wdk_sys::WDFREQUEST) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 538a50995..0e2142bf3 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 @@ -38,7 +38,7 @@ fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; 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 3a1ba55f4..3e18daad9 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 @@ -38,7 +38,7 @@ fn foo() { ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") + format_args!("Option should never be None"), ), ); }; From 0cb1df7f66e8128c1ee71fd5addca821b42e36a2 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Thu, 9 Oct 2025 10:25:15 -0700 Subject: [PATCH 21/32] updated nightly macro expansion tests --- .../outputs/nightly/macrotest/bug_unused_imports.expanded.rs | 2 +- .../outputs/nightly/macrotest/wdf_driver_create.expanded.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 b1451a812..634a9719f 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 @@ -86,7 +86,7 @@ pub extern "system" fn driver_entry( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; 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 d99bbb959..0049301cf 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 @@ -63,7 +63,7 @@ pub extern "system" fn driver_entry( ::core::panicking::panic_fmt( format_args!( "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), + format_args!("Option should never be None") ), ); }; From 7cf8289a540b710c55d6b3b2320f3dd8997a2482 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Thu, 9 Oct 2025 11:11:34 -0700 Subject: [PATCH 22/32] Apply suggestion from @Copilot Applied as *mut _ suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Leon Durrenberger --- crates/wdk/src/wdf/timer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index b1eeed1a3..0ff661e9a 100644 --- a/crates/wdk/src/wdf/timer.rs +++ b/crates/wdk/src/wdf/timer.rs @@ -40,7 +40,7 @@ impl Timer { WdfTimerCreate, timer_config, attributes, - &raw mut timer.wdf_timer, + &mut timer.wdf_timer as *mut _, ); } nt_success(nt_status).then_some(timer).ok_or(nt_status) From 0e7f74b8e03f95c9b6c6d180f71e81e29eae3a36 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Thu, 9 Oct 2025 11:12:22 -0700 Subject: [PATCH 23/32] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Leon Durrenberger --- crates/wdk/src/wdf/spinlock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wdk/src/wdf/spinlock.rs b/crates/wdk/src/wdf/spinlock.rs index 579f2ac4e..3334e3c8b 100644 --- a/crates/wdk/src/wdf/spinlock.rs +++ b/crates/wdk/src/wdf/spinlock.rs @@ -42,7 +42,7 @@ impl SpinLock { nt_status = call_unsafe_wdf_function_binding!( WdfSpinLockCreate, attributes, - &raw mut spin_lock.wdf_spin_lock, + &mut spin_lock.wdf_spin_lock as *mut _, ); } nt_success(nt_status).then_some(spin_lock).ok_or(nt_status) From 27458c2f92a7172ee19fbce37b451cfe818b5e09 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Tue, 14 Oct 2025 15:30:21 -0700 Subject: [PATCH 24/32] Updated safety comments --- crates/cargo-wdk/src/test_utils.rs | 4 ++-- crates/cargo-wdk/tests/test_utils/mod.rs | 4 ++-- crates/wdk-build/rust-driver-makefile.toml | 4 ++-- crates/wdk-build/src/utils.rs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/cargo-wdk/src/test_utils.rs b/crates/cargo-wdk/src/test_utils.rs index 39d01cf45..877cb9b10 100644 --- a/crates/cargo-wdk/src/test_utils.rs +++ b/crates/cargo-wdk/src/test_utils.rs @@ -113,8 +113,8 @@ pub fn remove_var(key: K) where K: AsRef, { - // SAFETY: We've verified this is targeted for Windows, where env::remove_var - // is always safe according to documentation. + // SAFETY: this function is only conditionally compiled for windows targets, and + // env::set_var is always safe for windows targets unsafe { std::env::remove_var(key); } diff --git a/crates/cargo-wdk/tests/test_utils/mod.rs b/crates/cargo-wdk/tests/test_utils/mod.rs index e5a182836..c816e9de9 100644 --- a/crates/cargo-wdk/tests/test_utils/mod.rs +++ b/crates/cargo-wdk/tests/test_utils/mod.rs @@ -162,8 +162,8 @@ pub fn remove_var(key: K) where K: AsRef, { - // SAFETY: We've verified this is targeted for Windows, where env::remove_var - // is always safe according to documentation. + // SAFETY: this function is only conditionally compiled for windows targets, and + // env::set_var is always safe for windows targets unsafe { std::env::remove_var(key); } diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index e82b9376f..4fa1bdba2 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -164,8 +164,8 @@ compile_error!( ); for (key, value) in &serialized_wdk_metadata_map { - // SAFETY: We've verified this is targeted for Windows, where std::env::set_var - // is always safe according to documentation. + // SAFETY: this function is only conditionally compiled for windows targets, and + // env::set_var is always safe for windows targets unsafe { std::env::set_var(key, value); } diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 6d513babf..2c51bcbee 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -366,8 +366,8 @@ where K: AsRef, V: AsRef, { - // SAFETY: We've verified this is targeted for Windows, where env::set_var is - // always safe according to Rust documentation. + // SAFETY: this function is only conditionally compiled for windows targets, and + // env::set_var is always safe for windows targets unsafe { env::set_var(key, value); } @@ -401,8 +401,8 @@ pub fn remove_var(key: K) where K: AsRef, { - // SAFETY: We've verified this is targeted for Windows, where env::remove_var - // is always safe according to documentation. + // SAFETY: this function is only conditionally compiled for windows targets, and + // env::set_var is always safe for windows targets unsafe { env::remove_var(key); } From 0d811d5f70c170c9ff7dac64d45a5abc4375d14d Mon Sep 17 00:00:00 2001 From: leon-xd Date: Tue, 14 Oct 2025 15:32:30 -0700 Subject: [PATCH 25/32] added cfg guard for safe_env_vars tests --- crates/wdk-build/src/utils.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 2c51bcbee..af5d758c1 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -695,6 +695,7 @@ mod tests { } } + #[cfg(target_os = "windows")] mod safe_env_vars { use super::*; From 8ca4e004b3faf05d92bb4c74a0ff4071799dc0a4 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Tue, 14 Oct 2025 15:41:16 -0700 Subject: [PATCH 26/32] Update crates/wdk/src/wdf/timer.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Leon Durrenberger --- crates/wdk/src/wdf/timer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wdk/src/wdf/timer.rs b/crates/wdk/src/wdf/timer.rs index 0ff661e9a..868533501 100644 --- a/crates/wdk/src/wdf/timer.rs +++ b/crates/wdk/src/wdf/timer.rs @@ -40,7 +40,7 @@ impl Timer { WdfTimerCreate, timer_config, attributes, - &mut timer.wdf_timer as *mut _, + &mut timer.wdf_timer as *mut WDFTIMER, ); } nt_success(nt_status).then_some(timer).ok_or(nt_status) From 5c4ae9e6d837c68e1eddf4ab517b2621c8a9cb27 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Tue, 14 Oct 2025 15:49:23 -0700 Subject: [PATCH 27/32] Removed accidental copied files --- .../macrotest/bug_tuple_struct_shadowing.rs | 45 +++++++- .../beta/macrotest/bug_unused_imports.rs | 63 ++++++++++- .../beta/macrotest/wdf_device_create.rs | 21 +++- .../wdf_device_create_device_interface.rs | 26 ++++- .../beta/macrotest/wdf_driver_create.rs | 29 ++++- .../wdf_request_retrieve_output_buffer.rs | 19 +++- .../beta/macrotest/wdf_spin_lock_acquire.rs | 12 +- .../macrotest/wdf_verifier_dbg_break_point.rs | 9 +- .../trybuild/wdf_api_that_does_not_exist.rs | 18 ++- .../wdf_device_create_unused_return_type.rs | 26 ++++- .../trybuild/wdf_driver_create_missing_arg.rs | 33 +++++- .../wdf_driver_create_wrong_arg_order.rs | 33 +++++- .../wdf_timer_create_missing_unsafe.rs | 17 ++- .../bug_tuple_struct_shadowing copy.rs | 44 -------- ...ug_tuple_struct_shadowing.expanded copy.rs | 91 --------------- .../macrotest/bug_tuple_struct_shadowing.rs | 45 +++++++- .../macrotest/bug_unused_imports copy.rs | 62 ----------- .../bug_unused_imports.expanded copy.rs | 105 ------------------ .../nightly/macrotest/bug_unused_imports.rs | 63 ++++++++++- .../macrotest/wdf_device_create copy.rs | 20 ---- .../wdf_device_create.expanded copy.rs | 71 ------------ .../nightly/macrotest/wdf_device_create.rs | 21 +++- ...wdf_device_create_device_interface copy.rs | 25 ----- ...e_create_device_interface.expanded copy.rs | 73 ------------ .../wdf_device_create_device_interface.rs | 26 ++++- .../macrotest/wdf_driver_create copy.rs | 28 ----- .../wdf_driver_create.expanded copy.rs | 82 -------------- .../nightly/macrotest/wdf_driver_create.rs | 29 ++++- ...wdf_request_retrieve_output_buffer copy.rs | 18 --- ...st_retrieve_output_buffer.expanded copy.rs | 72 ------------ .../wdf_request_retrieve_output_buffer.rs | 19 +++- .../macrotest/wdf_spin_lock_acquire copy.rs | 11 -- .../wdf_spin_lock_acquire.expanded copy.rs | 51 --------- .../macrotest/wdf_spin_lock_acquire.rs | 12 +- .../wdf_verifier_dbg_break_point copy.rs | 8 -- ..._verifier_dbg_break_point.expanded copy.rs | 51 --------- .../macrotest/wdf_verifier_dbg_break_point.rs | 9 +- .../trybuild/wdf_api_that_does_not_exist.rs | 18 ++- .../wdf_device_create_unused_return_type.rs | 26 ++++- .../trybuild/wdf_driver_create_missing_arg.rs | 33 +++++- .../wdf_driver_create_wrong_arg_order.rs | 33 +++++- .../wdf_timer_create_missing_unsafe.rs | 17 ++- .../macrotest/bug_tuple_struct_shadowing.rs | 45 +++++++- .../stable/macrotest/bug_unused_imports.rs | 63 ++++++++++- .../stable/macrotest/wdf_device_create.rs | 21 +++- .../wdf_device_create_device_interface.rs | 26 ++++- .../stable/macrotest/wdf_driver_create.rs | 29 ++++- .../wdf_request_retrieve_output_buffer.rs | 19 +++- .../stable/macrotest/wdf_spin_lock_acquire.rs | 12 +- .../macrotest/wdf_verifier_dbg_break_point.rs | 9 +- .../trybuild/wdf_api_that_does_not_exist.rs | 18 ++- .../wdf_device_create_unused_return_type.rs | 26 ++++- .../trybuild/wdf_driver_create_missing_arg.rs | 33 +++++- .../wdf_driver_create_wrong_arg_order.rs | 33 +++++- .../wdf_timer_create_missing_unsafe.rs | 17 ++- 55 files changed, 1014 insertions(+), 851 deletions(-) mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point copy.rs delete mode 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded copy.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs mode change 120000 => 100644 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs deleted file mode 120000 index cc095653a..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/bug_tuple_struct_shadowing.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs new file mode 100644 index 000000000..cb8fad625 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 + +#![no_main] +#![deny(warnings)] + +/// This is a regression test for a bug where the +/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented +/// anything in scope from having the same name as one of the c function's +/// parameter names. This resulted in the following compilation error: +/// +#[rustfmt::skip] +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ +/// error[E0530]: function parameters cannot shadow tuple structs +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 +/// | +/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); +/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here +/// ... +/// 34 | / call_unsafe_wdf_function_binding!( +/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, +/// 36 | | device_init.0, +/// 37 | | pnp_power_callbacks +/// 38 | | ) +/// | |_________^ cannot be named the same as a tuple struct +/// | +/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + + +use wdk_sys::call_unsafe_wdf_function_binding; + +#[repr(transparent)] +pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); + +fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { + unsafe { + call_unsafe_wdf_function_binding!( + WdfDeviceInitSetPnpPowerEventCallbacks, + device_init.0, + pnp_power_callbacks + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs deleted file mode 120000 index 93c7ab9b8..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/bug_unused_imports.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs new file mode 100644 index 000000000..784be3569 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 + +#![no_main] +#![deny(warnings)] + +//! This is a regression test for a bug where the arguments to the +//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into +//! scope, but rust-analyzer would treat them as unused imports. This resulted +//! in the following compilation error: +#[rustfmt::skip] +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ +/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 +/// | +/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... +/// | ^^^^^^^^^^^^^^^^^^^^^^^^ +/// | +/// note: the lint level is defined here +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 +/// | +/// 5 | #![deny(warnings)] +/// | ^^^^^^^^ +/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +use wdk_sys::{ + call_unsafe_wdf_function_binding, + NTSTATUS, + PCUNICODE_STRING, + PDRIVER_OBJECT, + ULONG, + WDFDRIVER, + WDF_DRIVER_CONFIG, + WDF_NO_HANDLE, + WDF_NO_OBJECT_ATTRIBUTES, +}; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: PDRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..Default::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver, + registry_path, + WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs deleted file mode 120000 index 20bd5908c..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_device_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs new file mode 100644 index 000000000..53b5fe95b --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +extern "C" fn evt_driver_device_add( + _driver: wdk_sys::WDFDRIVER, + mut device_init: *mut wdk_sys::WDFDEVICE_INIT, +) -> wdk_sys::NTSTATUS { + let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); + + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDeviceCreate, + &mut device_init, + wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, + &mut device_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs deleted file mode 120000 index e9f8c16bd..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_device_create_device_interface.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs new file mode 100644 index 000000000..36100950d --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +// {86E0D1E0-8089-11D0-9CE4-08003E301F73} +const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { + Data1: 0x86E0D1E0u32, + Data2: 0x8089u16, + Data3: 0x11D0u16, + Data4: [ + 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, + ], +}; + +fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDeviceCreateDeviceInterface, + wdf_device, + &GUID_DEVINTERFACE_COMPORT, + core::ptr::null(), + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs deleted file mode 120000 index 570f030b9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_driver_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs new file mode 100644 index 000000000..ebdca79b2 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: wdk_sys::PDRIVER_OBJECT, + registry_path: wdk_sys::PCUNICODE_STRING, +) -> wdk_sys::NTSTATUS { + let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as wdk_sys::ULONG, + ..Default::default() + }; + let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; + + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver, + registry_path, + wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs deleted file mode 120000 index f38625892..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_request_retrieve_output_buffer.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs new file mode 100644 index 000000000..6d79a31d4 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn process_wdf_request(request: wdk_sys::WDFREQUEST) { + let minimum_required_buffer_size = 32; + let mut output_buffer_ptr = std::ptr::null_mut(); + let _nt_status = unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfRequestRetrieveOutputBuffer, + request, + minimum_required_buffer_size, + &mut output_buffer_ptr, + std::ptr::null_mut() + ) + }; +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs deleted file mode 120000 index e77fcc3f9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_spin_lock_acquire.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs new file mode 100644 index 000000000..109209b70 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { + // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs deleted file mode 120000 index f2bb2b511..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_verifier_dbg_break_point.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs new file mode 100644 index 000000000..9a3872970 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn foo() { + unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs deleted file mode 120000 index 14059dc88..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_api_that_does_not_exist.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs new file mode 100644 index 000000000..177818eb0 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + // WdfApiThatDoesNotExist is a WDF API that does not exist! + unsafe { call_unsafe_wdf_function_binding!(WdfApiThatDoesNotExist, driver as PDRIVER_OBJECT,) } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs deleted file mode 120000 index 94c8088d7..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_device_create_unused_return_type.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs new file mode 100644 index 000000000..644a50050 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +extern "C" fn evt_driver_device_add( + _driver: WDFDRIVER, + mut device_init: *mut WDFDEVICE_INIT, +) -> NTSTATUS { + let mut device_handle_output: WDFDEVICE = WDF_NO_HANDLE.cast(); + + // The NTSTATUS return value of WdfDeviceCreate is unused! + unsafe { + call_unsafe_wdf_function_binding!( + WdfDeviceCreate, + &mut device_init, + WDF_NO_OBJECT_ATTRIBUTES, + &mut device_handle_output, + ) + }; + + 0 +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs deleted file mode 120000 index a3123ce4d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_driver_create_missing_arg.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs new file mode 100644 index 000000000..75ea68019 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..WDF_DRIVER_CONFIG::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver as PDRIVER_OBJECT, + registry_path, + // The object attributes are missing from this call! + // WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs deleted file mode 120000 index ff8e6c8f1..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_driver_create_wrong_arg_order.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs new file mode 100644 index 000000000..ffcca5e83 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..WDF_DRIVER_CONFIG::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver as PDRIVER_OBJECT, + registry_path, + // The order of the next two arguments is swapped! + &mut driver_config, + WDF_NO_OBJECT_ATTRIBUTES, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs deleted file mode 120000 index 4a715fd06..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_timer_create_missing_unsafe.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs new file mode 100644 index 000000000..6172fe55c --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +fn foo(timer_config: &mut WDF_TIMER_CONFIG, attributes: &mut WDF_OBJECT_ATTRIBUTES,) { + let mut timer = core::ptr::null_mut(); + let _nt_status = call_unsafe_wdf_function_binding!( + WdfTimerCreate, + timer_config, + attributes, + &mut timer, + ); +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing copy.rs deleted file mode 100644 index cb8fad625..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing copy.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -/// This is a regression test for a bug where the -/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented -/// anything in scope from having the same name as one of the c function's -/// parameter names. This resulted in the following compilation error: -/// -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error[E0530]: function parameters cannot shadow tuple structs -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 -/// | -/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); -/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here -/// ... -/// 34 | / call_unsafe_wdf_function_binding!( -/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, -/// 36 | | device_init.0, -/// 37 | | pnp_power_callbacks -/// 38 | | ) -/// | |_________^ cannot be named the same as a tuple struct -/// | -/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - - -use wdk_sys::call_unsafe_wdf_function_binding; - -#[repr(transparent)] -pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); - -fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceInitSetPnpPowerEventCallbacks, - device_init.0, - pnp_power_callbacks - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded copy.rs deleted file mode 100644 index ca2b818d1..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded copy.rs +++ /dev/null @@ -1,91 +0,0 @@ -#![no_main] -#![deny(warnings)] -/// This is a regression test for a bug where the -/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented -/// anything in scope from having the same name as one of the c function's -/// parameter names. This resulted in the following compilation error: -/// -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error[E0530]: function parameters cannot shadow tuple structs -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 -/// | -/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); -/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here -/// ... -/// 34 | / call_unsafe_wdf_function_binding!( -/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, -/// 36 | | device_init.0, -/// 37 | | pnp_power_callbacks -/// 38 | | ) -/// | |_________^ cannot be named the same as a tuple struct -/// | -/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -use wdk_sys::call_unsafe_wdf_function_binding; -#[repr(transparent)] -pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); -fn foo( - device_init: DeviceInit, - pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS, -) { - unsafe { - { - mod private__ { - use wdk_sys::*; - #[inline(always)] - pub unsafe fn wdf_device_init_set_pnp_power_event_callbacks_impl( - device_init__: PWDFDEVICE_INIT, - pnp_power_event_callbacks__: PWDF_PNPPOWER_EVENT_CALLBACKS, - ) { - let wdf_function: wdk_sys::PFN_WDFDEVICEINITSETPNPPOWEREVENTCALLBACKS = Some(unsafe { - let wdf_function_table = wdk_sys::WdfFunctions; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceInitSetPnpPowerEventCallbacksTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { - (wdf_function)( - wdk_sys::WdfDriverGlobals, - device_init__, - pnp_power_event_callbacks__, - ) - } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), - ), - ); - }; - } - } - } - private__::wdf_device_init_set_pnp_power_event_callbacks_impl( - device_init.0, - pnp_power_callbacks, - ) - } - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs deleted file mode 120000 index cc095653a..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/bug_tuple_struct_shadowing.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs new file mode 100644 index 000000000..cb8fad625 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 + +#![no_main] +#![deny(warnings)] + +/// This is a regression test for a bug where the +/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented +/// anything in scope from having the same name as one of the c function's +/// parameter names. This resulted in the following compilation error: +/// +#[rustfmt::skip] +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ +/// error[E0530]: function parameters cannot shadow tuple structs +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 +/// | +/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); +/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here +/// ... +/// 34 | / call_unsafe_wdf_function_binding!( +/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, +/// 36 | | device_init.0, +/// 37 | | pnp_power_callbacks +/// 38 | | ) +/// | |_________^ cannot be named the same as a tuple struct +/// | +/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + + +use wdk_sys::call_unsafe_wdf_function_binding; + +#[repr(transparent)] +pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); + +fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { + unsafe { + call_unsafe_wdf_function_binding!( + WdfDeviceInitSetPnpPowerEventCallbacks, + device_init.0, + pnp_power_callbacks + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports copy.rs deleted file mode 100644 index 784be3569..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports copy.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -//! This is a regression test for a bug where the arguments to the -//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into -//! scope, but rust-analyzer would treat them as unused imports. This resulted -//! in the following compilation error: -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 -/// | -/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... -/// | ^^^^^^^^^^^^^^^^^^^^^^^^ -/// | -/// note: the lint level is defined here -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 -/// | -/// 5 | #![deny(warnings)] -/// | ^^^^^^^^ -/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - -use wdk_sys::{ - call_unsafe_wdf_function_binding, - NTSTATUS, - PCUNICODE_STRING, - PDRIVER_OBJECT, - ULONG, - WDFDRIVER, - WDF_DRIVER_CONFIG, - WDF_NO_HANDLE, - WDF_NO_OBJECT_ATTRIBUTES, -}; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: PDRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..Default::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded copy.rs deleted file mode 100644 index 634a9719f..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded copy.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![no_main] -#![deny(warnings)] -//! This is a regression test for a bug where the arguments to the -//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into -//! scope, but rust-analyzer would treat them as unused imports. This resulted -//! in the following compilation error: -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 -/// | -/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... -/// | ^^^^^^^^^^^^^^^^^^^^^^^^ -/// | -/// note: the lint level is defined here -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 -/// | -/// 5 | #![deny(warnings)] -/// | ^^^^^^^^ -/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -use wdk_sys::{ - call_unsafe_wdf_function_binding, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, - WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES, -}; -#[unsafe(export_name = "DriverEntry")] -pub extern "system" fn driver_entry( - driver: PDRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..Default::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - unsafe { - { - mod private__ { - use wdk_sys::*; - #[must_use] - #[inline(always)] - pub unsafe fn wdf_driver_create_impl( - driver_object__: PDRIVER_OBJECT, - registry_path__: PCUNICODE_STRING, - driver_attributes__: PWDF_OBJECT_ATTRIBUTES, - driver_config__: PWDF_DRIVER_CONFIG, - driver__: *mut WDFDRIVER, - ) -> NTSTATUS { - let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { - let wdf_function_table = wdk_sys::WdfFunctions; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { - (wdf_function)( - wdk_sys::WdfDriverGlobals, - driver_object__, - registry_path__, - driver_attributes__, - driver_config__, - driver__, - ) - } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") - ), - ); - }; - } - } - } - private__::wdf_driver_create_impl( - driver, - registry_path, - WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs deleted file mode 120000 index 93c7ab9b8..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/bug_unused_imports.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs new file mode 100644 index 000000000..784be3569 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 + +#![no_main] +#![deny(warnings)] + +//! This is a regression test for a bug where the arguments to the +//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into +//! scope, but rust-analyzer would treat them as unused imports. This resulted +//! in the following compilation error: +#[rustfmt::skip] +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ +/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 +/// | +/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... +/// | ^^^^^^^^^^^^^^^^^^^^^^^^ +/// | +/// note: the lint level is defined here +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 +/// | +/// 5 | #![deny(warnings)] +/// | ^^^^^^^^ +/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +use wdk_sys::{ + call_unsafe_wdf_function_binding, + NTSTATUS, + PCUNICODE_STRING, + PDRIVER_OBJECT, + ULONG, + WDFDRIVER, + WDF_DRIVER_CONFIG, + WDF_NO_HANDLE, + WDF_NO_OBJECT_ATTRIBUTES, +}; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: PDRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..Default::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver, + registry_path, + WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create copy.rs deleted file mode 100644 index 53b5fe95b..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create copy.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -extern "C" fn evt_driver_device_add( - _driver: wdk_sys::WDFDRIVER, - mut device_init: *mut wdk_sys::WDFDEVICE_INIT, -) -> wdk_sys::NTSTATUS { - let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded copy.rs deleted file mode 100644 index 0e687de35..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.expanded copy.rs +++ /dev/null @@ -1,71 +0,0 @@ -#![no_main] -#![deny(warnings)] -extern "C" fn evt_driver_device_add( - _driver: wdk_sys::WDFDRIVER, - mut device_init: *mut wdk_sys::WDFDEVICE_INIT, -) -> wdk_sys::NTSTATUS { - let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); - unsafe { - { - mod private__ { - use wdk_sys::*; - #[must_use] - #[inline(always)] - pub unsafe fn wdf_device_create_impl( - device_init__: *mut PWDFDEVICE_INIT, - device_attributes__: PWDF_OBJECT_ATTRIBUTES, - device__: *mut WDFDEVICE, - ) -> NTSTATUS { - let wdf_function: wdk_sys::PFN_WDFDEVICECREATE = Some(unsafe { - let wdf_function_table = wdk_sys::WdfFunctions; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { - (wdf_function)( - wdk_sys::WdfDriverGlobals, - device_init__, - device_attributes__, - device__, - ) - } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), - ), - ); - }; - } - } - } - private__::wdf_device_create_impl( - &mut device_init, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - } - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs deleted file mode 120000 index 20bd5908c..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_device_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs new file mode 100644 index 000000000..53b5fe95b --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +extern "C" fn evt_driver_device_add( + _driver: wdk_sys::WDFDRIVER, + mut device_init: *mut wdk_sys::WDFDEVICE_INIT, +) -> wdk_sys::NTSTATUS { + let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); + + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDeviceCreate, + &mut device_init, + wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, + &mut device_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface copy.rs deleted file mode 100644 index 36100950d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface copy.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -// {86E0D1E0-8089-11D0-9CE4-08003E301F73} -const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { - Data1: 0x86E0D1E0u32, - Data2: 0x8089u16, - Data3: 0x11D0u16, - Data4: [ - 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, - ], -}; - -fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreateDeviceInterface, - wdf_device, - &GUID_DEVINTERFACE_COMPORT, - core::ptr::null(), - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded copy.rs deleted file mode 100644 index 1e10670e7..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.expanded copy.rs +++ /dev/null @@ -1,73 +0,0 @@ -#![no_main] -#![deny(warnings)] -const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { - Data1: 0x86E0D1E0u32, - Data2: 0x8089u16, - Data3: 0x11D0u16, - Data4: [0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8], -}; -fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { - unsafe { - { - mod private__ { - use wdk_sys::*; - #[must_use] - #[inline(always)] - pub unsafe fn wdf_device_create_device_interface_impl( - device__: WDFDEVICE, - interface_class_guid__: *const GUID, - reference_string__: PCUNICODE_STRING, - ) -> NTSTATUS { - let wdf_function: wdk_sys::PFN_WDFDEVICECREATEDEVICEINTERFACE = Some(unsafe { - let wdf_function_table = wdk_sys::WdfFunctions; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDeviceCreateDeviceInterfaceTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { - (wdf_function)( - wdk_sys::WdfDriverGlobals, - device__, - interface_class_guid__, - reference_string__, - ) - } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), - ), - ); - }; - } - } - } - private__::wdf_device_create_device_interface_impl( - wdf_device, - &GUID_DEVINTERFACE_COMPORT, - core::ptr::null(), - ) - } - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs deleted file mode 120000 index e9f8c16bd..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_device_create_device_interface.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs new file mode 100644 index 000000000..36100950d --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +// {86E0D1E0-8089-11D0-9CE4-08003E301F73} +const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { + Data1: 0x86E0D1E0u32, + Data2: 0x8089u16, + Data3: 0x11D0u16, + Data4: [ + 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, + ], +}; + +fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDeviceCreateDeviceInterface, + wdf_device, + &GUID_DEVINTERFACE_COMPORT, + core::ptr::null(), + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create copy.rs deleted file mode 100644 index ebdca79b2..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create copy.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: wdk_sys::PDRIVER_OBJECT, - registry_path: wdk_sys::PCUNICODE_STRING, -) -> wdk_sys::NTSTATUS { - let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as wdk_sys::ULONG, - ..Default::default() - }; - let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded copy.rs deleted file mode 100644 index 0049301cf..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.expanded copy.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![no_main] -#![deny(warnings)] -#[unsafe(export_name = "DriverEntry")] -pub extern "system" fn driver_entry( - driver: wdk_sys::PDRIVER_OBJECT, - registry_path: wdk_sys::PCUNICODE_STRING, -) -> wdk_sys::NTSTATUS { - let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as wdk_sys::ULONG, - ..Default::default() - }; - let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; - unsafe { - { - mod private__ { - use wdk_sys::*; - #[must_use] - #[inline(always)] - pub unsafe fn wdf_driver_create_impl( - driver_object__: PDRIVER_OBJECT, - registry_path__: PCUNICODE_STRING, - driver_attributes__: PWDF_OBJECT_ATTRIBUTES, - driver_config__: PWDF_DRIVER_CONFIG, - driver__: *mut WDFDRIVER, - ) -> NTSTATUS { - let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe { - let wdf_function_table = wdk_sys::WdfFunctions; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfDriverCreateTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { - (wdf_function)( - wdk_sys::WdfDriverGlobals, - driver_object__, - registry_path__, - driver_attributes__, - driver_config__, - driver__, - ) - } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None") - ), - ); - }; - } - } - } - private__::wdf_driver_create_impl( - driver, - registry_path, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs deleted file mode 120000 index 570f030b9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_driver_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs new file mode 100644 index 000000000..ebdca79b2 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: wdk_sys::PDRIVER_OBJECT, + registry_path: wdk_sys::PCUNICODE_STRING, +) -> wdk_sys::NTSTATUS { + let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as wdk_sys::ULONG, + ..Default::default() + }; + let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; + + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver, + registry_path, + wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer copy.rs deleted file mode 100644 index 6d79a31d4..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer copy.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn process_wdf_request(request: wdk_sys::WDFREQUEST) { - let minimum_required_buffer_size = 32; - let mut output_buffer_ptr = std::ptr::null_mut(); - let _nt_status = unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfRequestRetrieveOutputBuffer, - request, - minimum_required_buffer_size, - &mut output_buffer_ptr, - std::ptr::null_mut() - ) - }; -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded copy.rs deleted file mode 100644 index c2654fcb8..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.expanded copy.rs +++ /dev/null @@ -1,72 +0,0 @@ -#![no_main] -#![deny(warnings)] -fn process_wdf_request(request: wdk_sys::WDFREQUEST) { - let minimum_required_buffer_size = 32; - let mut output_buffer_ptr = std::ptr::null_mut(); - let _nt_status = unsafe { - { - mod private__ { - use wdk_sys::*; - #[must_use] - #[inline(always)] - pub unsafe fn wdf_request_retrieve_output_buffer_impl( - request__: WDFREQUEST, - minimum_required_size__: usize, - buffer__: *mut PVOID, - length__: *mut usize, - ) -> NTSTATUS { - let wdf_function: wdk_sys::PFN_WDFREQUESTRETRIEVEOUTPUTBUFFER = Some(unsafe { - let wdf_function_table = wdk_sys::WdfFunctions; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfRequestRetrieveOutputBufferTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { - (wdf_function)( - wdk_sys::WdfDriverGlobals, - request__, - minimum_required_size__, - buffer__, - length__, - ) - } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), - ), - ); - }; - } - } - } - private__::wdf_request_retrieve_output_buffer_impl( - request, - minimum_required_buffer_size, - &mut output_buffer_ptr, - std::ptr::null_mut(), - ) - } - }; -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs deleted file mode 120000 index f38625892..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_request_retrieve_output_buffer.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs new file mode 100644 index 000000000..6d79a31d4 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn process_wdf_request(request: wdk_sys::WDFREQUEST) { + let minimum_required_buffer_size = 32; + let mut output_buffer_ptr = std::ptr::null_mut(); + let _nt_status = unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfRequestRetrieveOutputBuffer, + request, + minimum_required_buffer_size, + &mut output_buffer_ptr, + std::ptr::null_mut() + ) + }; +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire copy.rs deleted file mode 100644 index 109209b70..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire copy.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { - // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded copy.rs deleted file mode 100644 index 0e2142bf3..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.expanded copy.rs +++ /dev/null @@ -1,51 +0,0 @@ -#![no_main] -#![deny(warnings)] -fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { - unsafe { - { - mod private__ { - use wdk_sys::*; - #[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; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfSpinLockAcquireTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { (wdf_function)(wdk_sys::WdfDriverGlobals, spin_lock__) } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), - ), - ); - }; - } - } - } - private__::wdf_spin_lock_acquire_impl(wdf_spin_lock) - }; - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs deleted file mode 120000 index e77fcc3f9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_spin_lock_acquire.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs new file mode 100644 index 000000000..109209b70 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { + // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point copy.rs deleted file mode 100644 index 9a3872970..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point copy.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn foo() { - unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded copy.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded copy.rs deleted file mode 100644 index 3e18daad9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.expanded copy.rs +++ /dev/null @@ -1,51 +0,0 @@ -#![no_main] -#![deny(warnings)] -fn foo() { - unsafe { - { - mod private__ { - use wdk_sys::*; - #[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; - let wdf_function_count = wdk_sys::wdf::__private::get_wdf_function_count(); - if true { - if !isize::try_from( - wdf_function_count - * core::mem::size_of::(), - ) - .is_ok() - { - ::core::panicking::panic( - "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, - wdf_function_count, - ); - core::mem::transmute( - wdf_function_table[wdk_sys::_WDFFUNCENUM::WdfVerifierDbgBreakPointTableIndex - as usize], - ) - }); - if let Some(wdf_function) = wdf_function { - unsafe { (wdf_function)(wdk_sys::WdfDriverGlobals) } - } else { - { - ::core::panicking::panic_fmt( - format_args!( - "internal error: entered unreachable code: {0}", - format_args!("Option should never be None"), - ), - ); - }; - } - } - } - private__::wdf_verifier_dbg_break_point_impl() - } - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs deleted file mode 120000 index f2bb2b511..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_verifier_dbg_break_point.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs new file mode 100644 index 000000000..9a3872970 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn foo() { + unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs deleted file mode 120000 index 14059dc88..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_api_that_does_not_exist.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs new file mode 100644 index 000000000..177818eb0 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + // WdfApiThatDoesNotExist is a WDF API that does not exist! + unsafe { call_unsafe_wdf_function_binding!(WdfApiThatDoesNotExist, driver as PDRIVER_OBJECT,) } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs deleted file mode 120000 index 94c8088d7..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_device_create_unused_return_type.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs new file mode 100644 index 000000000..644a50050 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +extern "C" fn evt_driver_device_add( + _driver: WDFDRIVER, + mut device_init: *mut WDFDEVICE_INIT, +) -> NTSTATUS { + let mut device_handle_output: WDFDEVICE = WDF_NO_HANDLE.cast(); + + // The NTSTATUS return value of WdfDeviceCreate is unused! + unsafe { + call_unsafe_wdf_function_binding!( + WdfDeviceCreate, + &mut device_init, + WDF_NO_OBJECT_ATTRIBUTES, + &mut device_handle_output, + ) + }; + + 0 +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs deleted file mode 120000 index a3123ce4d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_driver_create_missing_arg.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs new file mode 100644 index 000000000..75ea68019 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..WDF_DRIVER_CONFIG::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver as PDRIVER_OBJECT, + registry_path, + // The object attributes are missing from this call! + // WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs deleted file mode 120000 index ff8e6c8f1..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_driver_create_wrong_arg_order.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs new file mode 100644 index 000000000..ffcca5e83 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..WDF_DRIVER_CONFIG::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver as PDRIVER_OBJECT, + registry_path, + // The order of the next two arguments is swapped! + &mut driver_config, + WDF_NO_OBJECT_ATTRIBUTES, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs deleted file mode 120000 index 4a715fd06..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_timer_create_missing_unsafe.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs new file mode 100644 index 000000000..6172fe55c --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +fn foo(timer_config: &mut WDF_TIMER_CONFIG, attributes: &mut WDF_OBJECT_ATTRIBUTES,) { + let mut timer = core::ptr::null_mut(); + let _nt_status = call_unsafe_wdf_function_binding!( + WdfTimerCreate, + timer_config, + attributes, + &mut timer, + ); +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs deleted file mode 120000 index cc095653a..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/bug_tuple_struct_shadowing.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs new file mode 100644 index 000000000..cb8fad625 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 + +#![no_main] +#![deny(warnings)] + +/// This is a regression test for a bug where the +/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented +/// anything in scope from having the same name as one of the c function's +/// parameter names. This resulted in the following compilation error: +/// +#[rustfmt::skip] +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ +/// error[E0530]: function parameters cannot shadow tuple structs +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 +/// | +/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); +/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here +/// ... +/// 34 | / call_unsafe_wdf_function_binding!( +/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, +/// 36 | | device_init.0, +/// 37 | | pnp_power_callbacks +/// 38 | | ) +/// | |_________^ cannot be named the same as a tuple struct +/// | +/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + + +use wdk_sys::call_unsafe_wdf_function_binding; + +#[repr(transparent)] +pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); + +fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { + unsafe { + call_unsafe_wdf_function_binding!( + WdfDeviceInitSetPnpPowerEventCallbacks, + device_init.0, + pnp_power_callbacks + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs deleted file mode 120000 index 93c7ab9b8..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/bug_unused_imports.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs new file mode 100644 index 000000000..784be3569 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 + +#![no_main] +#![deny(warnings)] + +//! This is a regression test for a bug where the arguments to the +//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into +//! scope, but rust-analyzer would treat them as unused imports. This resulted +//! in the following compilation error: +#[rustfmt::skip] +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ +/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 +/// | +/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... +/// | ^^^^^^^^^^^^^^^^^^^^^^^^ +/// | +/// note: the lint level is defined here +/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 +/// | +/// 5 | #![deny(warnings)] +/// | ^^^^^^^^ +/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` +/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +use wdk_sys::{ + call_unsafe_wdf_function_binding, + NTSTATUS, + PCUNICODE_STRING, + PDRIVER_OBJECT, + ULONG, + WDFDRIVER, + WDF_DRIVER_CONFIG, + WDF_NO_HANDLE, + WDF_NO_OBJECT_ATTRIBUTES, +}; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: PDRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..Default::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver, + registry_path, + WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs deleted file mode 120000 index 20bd5908c..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_device_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs new file mode 100644 index 000000000..53b5fe95b --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +extern "C" fn evt_driver_device_add( + _driver: wdk_sys::WDFDRIVER, + mut device_init: *mut wdk_sys::WDFDEVICE_INIT, +) -> wdk_sys::NTSTATUS { + let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); + + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDeviceCreate, + &mut device_init, + wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, + &mut device_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs deleted file mode 120000 index e9f8c16bd..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_device_create_device_interface.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs new file mode 100644 index 000000000..36100950d --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +// {86E0D1E0-8089-11D0-9CE4-08003E301F73} +const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { + Data1: 0x86E0D1E0u32, + Data2: 0x8089u16, + Data3: 0x11D0u16, + Data4: [ + 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, + ], +}; + +fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDeviceCreateDeviceInterface, + wdf_device, + &GUID_DEVINTERFACE_COMPORT, + core::ptr::null(), + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs deleted file mode 120000 index 570f030b9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_driver_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs new file mode 100644 index 000000000..ebdca79b2 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: wdk_sys::PDRIVER_OBJECT, + registry_path: wdk_sys::PCUNICODE_STRING, +) -> wdk_sys::NTSTATUS { + let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as wdk_sys::ULONG, + ..Default::default() + }; + let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; + + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver, + registry_path, + wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs deleted file mode 120000 index f38625892..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_request_retrieve_output_buffer.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs new file mode 100644 index 000000000..6d79a31d4 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn process_wdf_request(request: wdk_sys::WDFREQUEST) { + let minimum_required_buffer_size = 32; + let mut output_buffer_ptr = std::ptr::null_mut(); + let _nt_status = unsafe { + wdk_sys::call_unsafe_wdf_function_binding!( + WdfRequestRetrieveOutputBuffer, + request, + minimum_required_buffer_size, + &mut output_buffer_ptr, + std::ptr::null_mut() + ) + }; +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs deleted file mode 120000 index e77fcc3f9..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_spin_lock_acquire.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs new file mode 100644 index 000000000..109209b70 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { + // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value + unsafe { + wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs deleted file mode 120000 index f2bb2b511..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/macrotest/wdf_verifier_dbg_break_point.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs new file mode 100644 index 000000000..9a3872970 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +fn foo() { + unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs deleted file mode 120000 index 14059dc88..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_api_that_does_not_exist.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs new file mode 100644 index 000000000..177818eb0 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + // WdfApiThatDoesNotExist is a WDF API that does not exist! + unsafe { call_unsafe_wdf_function_binding!(WdfApiThatDoesNotExist, driver as PDRIVER_OBJECT,) } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs deleted file mode 120000 index 94c8088d7..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_device_create_unused_return_type.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs new file mode 100644 index 000000000..644a50050 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +extern "C" fn evt_driver_device_add( + _driver: WDFDRIVER, + mut device_init: *mut WDFDEVICE_INIT, +) -> NTSTATUS { + let mut device_handle_output: WDFDEVICE = WDF_NO_HANDLE.cast(); + + // The NTSTATUS return value of WdfDeviceCreate is unused! + unsafe { + call_unsafe_wdf_function_binding!( + WdfDeviceCreate, + &mut device_init, + WDF_NO_OBJECT_ATTRIBUTES, + &mut device_handle_output, + ) + }; + + 0 +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs deleted file mode 120000 index a3123ce4d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_driver_create_missing_arg.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs new file mode 100644 index 000000000..75ea68019 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..WDF_DRIVER_CONFIG::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver as PDRIVER_OBJECT, + registry_path, + // The object attributes are missing from this call! + // WDF_NO_OBJECT_ATTRIBUTES, + &mut driver_config, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs deleted file mode 120000 index ff8e6c8f1..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_driver_create_wrong_arg_order.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs new file mode 100644 index 000000000..ffcca5e83 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. +// No other function in this compilation unit exports this name, preventing symbol conflicts. +#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry +pub extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + registry_path: PCUNICODE_STRING, +) -> NTSTATUS { + let mut driver_config = WDF_DRIVER_CONFIG { + Size: core::mem::size_of::() as ULONG, + ..WDF_DRIVER_CONFIG::default() + }; + let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; + + unsafe { + call_unsafe_wdf_function_binding!( + WdfDriverCreate, + driver as PDRIVER_OBJECT, + registry_path, + // The order of the next two arguments is swapped! + &mut driver_config, + WDF_NO_OBJECT_ATTRIBUTES, + driver_handle_output, + ) + } +} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs deleted file mode 120000 index 4a715fd06..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs +++ /dev/null @@ -1 +0,0 @@ -../../../inputs/trybuild/wdf_timer_create_missing_unsafe.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs new file mode 100644 index 000000000..6172fe55c --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation +// License: MIT OR Apache-2.0 +#![no_main] +#![deny(warnings)] + +use wdk_sys::*; + +fn foo(timer_config: &mut WDF_TIMER_CONFIG, attributes: &mut WDF_OBJECT_ATTRIBUTES,) { + let mut timer = core::ptr::null_mut(); + let _nt_status = call_unsafe_wdf_function_binding!( + WdfTimerCreate, + timer_config, + attributes, + &mut timer, + ); +} From c54587c8b668e32e1c8d017c6276835de26fbd62 Mon Sep 17 00:00:00 2001 From: leon-xd Date: Wed, 15 Oct 2025 15:58:17 -0700 Subject: [PATCH 28/32] Restore symbolic links in wdk-macros-tests from commit 17b05c3 --- .../macrotest/bug_tuple_struct_shadowing.rs | 45 +------------ .../beta/macrotest/bug_unused_imports.rs | 63 +------------------ .../beta/macrotest/wdf_device_create.rs | 21 +------ .../wdf_device_create_device_interface.rs | 26 +------- .../beta/macrotest/wdf_driver_create.rs | 29 +-------- .../wdf_request_retrieve_output_buffer.rs | 19 +----- .../beta/macrotest/wdf_spin_lock_acquire.rs | 12 +--- .../macrotest/wdf_verifier_dbg_break_point.rs | 9 +-- .../trybuild/wdf_api_that_does_not_exist.rs | 18 +----- .../wdf_device_create_unused_return_type.rs | 26 +------- .../trybuild/wdf_driver_create_missing_arg.rs | 33 +--------- .../wdf_driver_create_wrong_arg_order.rs | 33 +--------- .../wdf_timer_create_missing_unsafe.rs | 17 +---- .../macrotest/bug_tuple_struct_shadowing.rs | 45 +------------ .../nightly/macrotest/bug_unused_imports.rs | 63 +------------------ .../nightly/macrotest/wdf_device_create.rs | 21 +------ .../wdf_device_create_device_interface.rs | 26 +------- .../nightly/macrotest/wdf_driver_create.rs | 29 +-------- .../wdf_request_retrieve_output_buffer.rs | 19 +----- .../macrotest/wdf_spin_lock_acquire.rs | 12 +--- .../macrotest/wdf_verifier_dbg_break_point.rs | 9 +-- .../trybuild/wdf_api_that_does_not_exist.rs | 18 +----- .../wdf_device_create_unused_return_type.rs | 26 +------- .../trybuild/wdf_driver_create_missing_arg.rs | 33 +--------- .../wdf_driver_create_wrong_arg_order.rs | 33 +--------- .../wdf_timer_create_missing_unsafe.rs | 17 +---- .../macrotest/bug_tuple_struct_shadowing.rs | 45 +------------ .../stable/macrotest/bug_unused_imports.rs | 63 +------------------ .../stable/macrotest/wdf_device_create.rs | 21 +------ .../wdf_device_create_device_interface.rs | 26 +------- .../stable/macrotest/wdf_driver_create.rs | 29 +-------- .../wdf_request_retrieve_output_buffer.rs | 19 +----- .../stable/macrotest/wdf_spin_lock_acquire.rs | 12 +--- .../macrotest/wdf_verifier_dbg_break_point.rs | 9 +-- .../trybuild/wdf_api_that_does_not_exist.rs | 18 +----- .../wdf_device_create_unused_return_type.rs | 26 +------- .../trybuild/wdf_driver_create_missing_arg.rs | 33 +--------- .../wdf_driver_create_wrong_arg_order.rs | 33 +--------- .../wdf_timer_create_missing_unsafe.rs | 17 +---- 39 files changed, 39 insertions(+), 1014 deletions(-) mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs mode change 100644 => 120000 tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs deleted file mode 100644 index cb8fad625..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -/// This is a regression test for a bug where the -/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented -/// anything in scope from having the same name as one of the c function's -/// parameter names. This resulted in the following compilation error: -/// -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error[E0530]: function parameters cannot shadow tuple structs -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 -/// | -/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); -/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here -/// ... -/// 34 | / call_unsafe_wdf_function_binding!( -/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, -/// 36 | | device_init.0, -/// 37 | | pnp_power_callbacks -/// 38 | | ) -/// | |_________^ cannot be named the same as a tuple struct -/// | -/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - - -use wdk_sys::call_unsafe_wdf_function_binding; - -#[repr(transparent)] -pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); - -fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceInitSetPnpPowerEventCallbacks, - device_init.0, - pnp_power_callbacks - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs new file mode 120000 index 000000000..cc095653a --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/bug_tuple_struct_shadowing.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs deleted file mode 100644 index 784be3569..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -//! This is a regression test for a bug where the arguments to the -//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into -//! scope, but rust-analyzer would treat them as unused imports. This resulted -//! in the following compilation error: -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 -/// | -/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... -/// | ^^^^^^^^^^^^^^^^^^^^^^^^ -/// | -/// note: the lint level is defined here -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 -/// | -/// 5 | #![deny(warnings)] -/// | ^^^^^^^^ -/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - -use wdk_sys::{ - call_unsafe_wdf_function_binding, - NTSTATUS, - PCUNICODE_STRING, - PDRIVER_OBJECT, - ULONG, - WDFDRIVER, - WDF_DRIVER_CONFIG, - WDF_NO_HANDLE, - WDF_NO_OBJECT_ATTRIBUTES, -}; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: PDRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..Default::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs new file mode 120000 index 000000000..93c7ab9b8 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/bug_unused_imports.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs deleted file mode 100644 index 53b5fe95b..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -extern "C" fn evt_driver_device_add( - _driver: wdk_sys::WDFDRIVER, - mut device_init: *mut wdk_sys::WDFDEVICE_INIT, -) -> wdk_sys::NTSTATUS { - let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs new file mode 120000 index 000000000..20bd5908c --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_device_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs deleted file mode 100644 index 36100950d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -// {86E0D1E0-8089-11D0-9CE4-08003E301F73} -const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { - Data1: 0x86E0D1E0u32, - Data2: 0x8089u16, - Data3: 0x11D0u16, - Data4: [ - 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, - ], -}; - -fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreateDeviceInterface, - wdf_device, - &GUID_DEVINTERFACE_COMPORT, - core::ptr::null(), - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs new file mode 120000 index 000000000..e9f8c16bd --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create_device_interface.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_device_create_device_interface.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs deleted file mode 100644 index ebdca79b2..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: wdk_sys::PDRIVER_OBJECT, - registry_path: wdk_sys::PCUNICODE_STRING, -) -> wdk_sys::NTSTATUS { - let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as wdk_sys::ULONG, - ..Default::default() - }; - let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs new file mode 120000 index 000000000..570f030b9 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_driver_create.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_driver_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs deleted file mode 100644 index 6d79a31d4..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn process_wdf_request(request: wdk_sys::WDFREQUEST) { - let minimum_required_buffer_size = 32; - let mut output_buffer_ptr = std::ptr::null_mut(); - let _nt_status = unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfRequestRetrieveOutputBuffer, - request, - minimum_required_buffer_size, - &mut output_buffer_ptr, - std::ptr::null_mut() - ) - }; -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs new file mode 120000 index 000000000..f38625892 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_request_retrieve_output_buffer.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs deleted file mode 100644 index 109209b70..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { - // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs new file mode 120000 index 000000000..e77fcc3f9 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_spin_lock_acquire.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs deleted file mode 100644 index 9a3872970..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn foo() { - unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs new file mode 120000 index 000000000..f2bb2b511 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_verifier_dbg_break_point.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs deleted file mode 100644 index 177818eb0..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - // WdfApiThatDoesNotExist is a WDF API that does not exist! - unsafe { call_unsafe_wdf_function_binding!(WdfApiThatDoesNotExist, driver as PDRIVER_OBJECT,) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs new file mode 120000 index 000000000..14059dc88 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_api_that_does_not_exist.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_api_that_does_not_exist.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs deleted file mode 100644 index 644a50050..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -extern "C" fn evt_driver_device_add( - _driver: WDFDRIVER, - mut device_init: *mut WDFDEVICE_INIT, -) -> NTSTATUS { - let mut device_handle_output: WDFDEVICE = WDF_NO_HANDLE.cast(); - - // The NTSTATUS return value of WdfDeviceCreate is unused! - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - }; - - 0 -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs new file mode 120000 index 000000000..94c8088d7 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_device_create_unused_return_type.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_device_create_unused_return_type.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs deleted file mode 100644 index 75ea68019..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..WDF_DRIVER_CONFIG::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver as PDRIVER_OBJECT, - registry_path, - // The object attributes are missing from this call! - // WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs new file mode 120000 index 000000000..a3123ce4d --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_missing_arg.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_driver_create_missing_arg.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs deleted file mode 100644 index ffcca5e83..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..WDF_DRIVER_CONFIG::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver as PDRIVER_OBJECT, - registry_path, - // The order of the next two arguments is swapped! - &mut driver_config, - WDF_NO_OBJECT_ATTRIBUTES, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs new file mode 120000 index 000000000..ff8e6c8f1 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_driver_create_wrong_arg_order.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs deleted file mode 100644 index 6172fe55c..000000000 --- a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -fn foo(timer_config: &mut WDF_TIMER_CONFIG, attributes: &mut WDF_OBJECT_ATTRIBUTES,) { - let mut timer = core::ptr::null_mut(); - let _nt_status = call_unsafe_wdf_function_binding!( - WdfTimerCreate, - timer_config, - attributes, - &mut timer, - ); -} diff --git a/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs new file mode 120000 index 000000000..4a715fd06 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/beta/trybuild/wdf_timer_create_missing_unsafe.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_timer_create_missing_unsafe.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs deleted file mode 100644 index cb8fad625..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -/// This is a regression test for a bug where the -/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented -/// anything in scope from having the same name as one of the c function's -/// parameter names. This resulted in the following compilation error: -/// -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error[E0530]: function parameters cannot shadow tuple structs -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 -/// | -/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); -/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here -/// ... -/// 34 | / call_unsafe_wdf_function_binding!( -/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, -/// 36 | | device_init.0, -/// 37 | | pnp_power_callbacks -/// 38 | | ) -/// | |_________^ cannot be named the same as a tuple struct -/// | -/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - - -use wdk_sys::call_unsafe_wdf_function_binding; - -#[repr(transparent)] -pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); - -fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceInitSetPnpPowerEventCallbacks, - device_init.0, - pnp_power_callbacks - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs new file mode 120000 index 000000000..cc095653a --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/bug_tuple_struct_shadowing.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs deleted file mode 100644 index 784be3569..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -//! This is a regression test for a bug where the arguments to the -//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into -//! scope, but rust-analyzer would treat them as unused imports. This resulted -//! in the following compilation error: -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 -/// | -/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... -/// | ^^^^^^^^^^^^^^^^^^^^^^^^ -/// | -/// note: the lint level is defined here -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 -/// | -/// 5 | #![deny(warnings)] -/// | ^^^^^^^^ -/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - -use wdk_sys::{ - call_unsafe_wdf_function_binding, - NTSTATUS, - PCUNICODE_STRING, - PDRIVER_OBJECT, - ULONG, - WDFDRIVER, - WDF_DRIVER_CONFIG, - WDF_NO_HANDLE, - WDF_NO_OBJECT_ATTRIBUTES, -}; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: PDRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..Default::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs new file mode 120000 index 000000000..93c7ab9b8 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/bug_unused_imports.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs deleted file mode 100644 index 53b5fe95b..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -extern "C" fn evt_driver_device_add( - _driver: wdk_sys::WDFDRIVER, - mut device_init: *mut wdk_sys::WDFDEVICE_INIT, -) -> wdk_sys::NTSTATUS { - let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs new file mode 120000 index 000000000..20bd5908c --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_device_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs deleted file mode 100644 index 36100950d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -// {86E0D1E0-8089-11D0-9CE4-08003E301F73} -const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { - Data1: 0x86E0D1E0u32, - Data2: 0x8089u16, - Data3: 0x11D0u16, - Data4: [ - 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, - ], -}; - -fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreateDeviceInterface, - wdf_device, - &GUID_DEVINTERFACE_COMPORT, - core::ptr::null(), - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs new file mode 120000 index 000000000..e9f8c16bd --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_device_create_device_interface.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_device_create_device_interface.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs deleted file mode 100644 index ebdca79b2..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: wdk_sys::PDRIVER_OBJECT, - registry_path: wdk_sys::PCUNICODE_STRING, -) -> wdk_sys::NTSTATUS { - let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as wdk_sys::ULONG, - ..Default::default() - }; - let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs new file mode 120000 index 000000000..570f030b9 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_driver_create.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_driver_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs deleted file mode 100644 index 6d79a31d4..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn process_wdf_request(request: wdk_sys::WDFREQUEST) { - let minimum_required_buffer_size = 32; - let mut output_buffer_ptr = std::ptr::null_mut(); - let _nt_status = unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfRequestRetrieveOutputBuffer, - request, - minimum_required_buffer_size, - &mut output_buffer_ptr, - std::ptr::null_mut() - ) - }; -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs new file mode 120000 index 000000000..f38625892 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_request_retrieve_output_buffer.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_request_retrieve_output_buffer.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs deleted file mode 100644 index 109209b70..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { - // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs new file mode 120000 index 000000000..e77fcc3f9 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_spin_lock_acquire.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_spin_lock_acquire.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs deleted file mode 100644 index 9a3872970..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn foo() { - unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs new file mode 120000 index 000000000..f2bb2b511 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/wdf_verifier_dbg_break_point.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_verifier_dbg_break_point.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs deleted file mode 100644 index 177818eb0..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - // WdfApiThatDoesNotExist is a WDF API that does not exist! - unsafe { call_unsafe_wdf_function_binding!(WdfApiThatDoesNotExist, driver as PDRIVER_OBJECT,) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs new file mode 120000 index 000000000..14059dc88 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_api_that_does_not_exist.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_api_that_does_not_exist.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs deleted file mode 100644 index 644a50050..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -extern "C" fn evt_driver_device_add( - _driver: WDFDRIVER, - mut device_init: *mut WDFDEVICE_INIT, -) -> NTSTATUS { - let mut device_handle_output: WDFDEVICE = WDF_NO_HANDLE.cast(); - - // The NTSTATUS return value of WdfDeviceCreate is unused! - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - }; - - 0 -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs new file mode 120000 index 000000000..94c8088d7 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_device_create_unused_return_type.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_device_create_unused_return_type.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs deleted file mode 100644 index 75ea68019..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..WDF_DRIVER_CONFIG::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver as PDRIVER_OBJECT, - registry_path, - // The object attributes are missing from this call! - // WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs new file mode 120000 index 000000000..a3123ce4d --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_missing_arg.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_driver_create_missing_arg.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs deleted file mode 100644 index ffcca5e83..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..WDF_DRIVER_CONFIG::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver as PDRIVER_OBJECT, - registry_path, - // The order of the next two arguments is swapped! - &mut driver_config, - WDF_NO_OBJECT_ATTRIBUTES, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs new file mode 120000 index 000000000..ff8e6c8f1 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_driver_create_wrong_arg_order.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs deleted file mode 100644 index 6172fe55c..000000000 --- a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -fn foo(timer_config: &mut WDF_TIMER_CONFIG, attributes: &mut WDF_OBJECT_ATTRIBUTES,) { - let mut timer = core::ptr::null_mut(); - let _nt_status = call_unsafe_wdf_function_binding!( - WdfTimerCreate, - timer_config, - attributes, - &mut timer, - ); -} diff --git a/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs new file mode 120000 index 000000000..4a715fd06 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/nightly/trybuild/wdf_timer_create_missing_unsafe.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_timer_create_missing_unsafe.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs deleted file mode 100644 index cb8fad625..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -/// This is a regression test for a bug where the -/// [`call_unsafe_wdf_function_binding`] macro would generate code that prevented -/// anything in scope from having the same name as one of the c function's -/// parameter names. This resulted in the following compilation error: -/// -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error[E0530]: function parameters cannot shadow tuple structs -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.rs:34:9 -/// | -/// 30 | pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); -/// | ------------------------------------------------ the tuple struct `DeviceInit` is defined here -/// ... -/// 34 | / call_unsafe_wdf_function_binding!( -/// 35 | | WdfDeviceInitSetPnpPowerEventCallbacks, -/// 36 | | device_init.0, -/// 37 | | pnp_power_callbacks -/// 38 | | ) -/// | |_________^ cannot be named the same as a tuple struct -/// | -/// = note: this error originates in the macro `$crate::__proc_macros::call_unsafe_wdf_function_binding` which comes from the expansion of the macro `call_unsafe_wdf_function_binding` (in Nightly builds, run with -Z macro-backtrace for more info) -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - - -use wdk_sys::call_unsafe_wdf_function_binding; - -#[repr(transparent)] -pub struct DeviceInit(wdk_sys::PWDFDEVICE_INIT); - -fn foo(device_init: DeviceInit, pnp_power_callbacks: wdk_sys::PWDF_PNPPOWER_EVENT_CALLBACKS) { - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceInitSetPnpPowerEventCallbacks, - device_init.0, - pnp_power_callbacks - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs new file mode 120000 index 000000000..cc095653a --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_tuple_struct_shadowing.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/bug_tuple_struct_shadowing.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs deleted file mode 100644 index 784be3569..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 - -#![no_main] -#![deny(warnings)] - -//! This is a regression test for a bug where the arguments to the -//! [`call_unsafe_wdf_function_binding`] macro would need to be brought into -//! scope, but rust-analyzer would treat them as unused imports. This resulted -//! in the following compilation error: -#[rustfmt::skip] -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ -/// error: unused import: `WDF_NO_OBJECT_ATTRIBUTES` -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:31:49 -/// | -/// 31 | use wdk_sys::{call_unsafe_wdf_function_binding, WDF_NO_OBJECT_ATTRIBUTES, NTSTATUS, PDRIVER_OBJECT, ULONG, PCUNICODE_STRING, WDF_DRIVER_C... -/// | ^^^^^^^^^^^^^^^^^^^^^^^^ -/// | -/// note: the lint level is defined here -/// --> C:/windows-drivers-rs/tests/wdk-macros-tests/tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.rs:5:9 -/// | -/// 5 | #![deny(warnings)] -/// | ^^^^^^^^ -/// = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` -/// ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ - -use wdk_sys::{ - call_unsafe_wdf_function_binding, - NTSTATUS, - PCUNICODE_STRING, - PDRIVER_OBJECT, - ULONG, - WDFDRIVER, - WDF_DRIVER_CONFIG, - WDF_NO_HANDLE, - WDF_NO_OBJECT_ATTRIBUTES, -}; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: PDRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..Default::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs new file mode 120000 index 000000000..93c7ab9b8 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/bug_unused_imports.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/bug_unused_imports.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs deleted file mode 100644 index 53b5fe95b..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -extern "C" fn evt_driver_device_add( - _driver: wdk_sys::WDFDRIVER, - mut device_init: *mut wdk_sys::WDFDEVICE_INIT, -) -> wdk_sys::NTSTATUS { - let mut device_handle_output: wdk_sys::WDFDEVICE = wdk_sys::WDF_NO_HANDLE.cast(); - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs new file mode 120000 index 000000000..20bd5908c --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_device_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs deleted file mode 100644 index 36100950d..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -// {86E0D1E0-8089-11D0-9CE4-08003E301F73} -const GUID_DEVINTERFACE_COMPORT: wdk_sys::GUID = wdk_sys::GUID { - Data1: 0x86E0D1E0u32, - Data2: 0x8089u16, - Data3: 0x11D0u16, - Data4: [ - 0x9Cu8, 0xE4u8, 0x08u8, 0x00u8, 0x3Eu8, 0x30u8, 0x1Fu8, 0x73u8, - ], -}; - -fn create_device_interface(wdf_device: wdk_sys::WDFDEVICE) -> wdk_sys::NTSTATUS { - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDeviceCreateDeviceInterface, - wdf_device, - &GUID_DEVINTERFACE_COMPORT, - core::ptr::null(), - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs new file mode 120000 index 000000000..e9f8c16bd --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_device_create_device_interface.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_device_create_device_interface.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs deleted file mode 100644 index ebdca79b2..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: wdk_sys::PDRIVER_OBJECT, - registry_path: wdk_sys::PCUNICODE_STRING, -) -> wdk_sys::NTSTATUS { - let mut driver_config = wdk_sys::WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as wdk_sys::ULONG, - ..Default::default() - }; - let driver_handle_output = wdk_sys::WDF_NO_HANDLE as *mut wdk_sys::WDFDRIVER; - - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver, - registry_path, - wdk_sys::WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs new file mode 120000 index 000000000..570f030b9 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_driver_create.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_driver_create.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs deleted file mode 100644 index 6d79a31d4..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn process_wdf_request(request: wdk_sys::WDFREQUEST) { - let minimum_required_buffer_size = 32; - let mut output_buffer_ptr = std::ptr::null_mut(); - let _nt_status = unsafe { - wdk_sys::call_unsafe_wdf_function_binding!( - WdfRequestRetrieveOutputBuffer, - request, - minimum_required_buffer_size, - &mut output_buffer_ptr, - std::ptr::null_mut() - ) - }; -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs new file mode 120000 index 000000000..f38625892 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_request_retrieve_output_buffer.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_request_retrieve_output_buffer.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs deleted file mode 100644 index 109209b70..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn acquire_lock(wdf_spin_lock: wdk_sys::WDFSPINLOCK) { - // This demonstrates that the macro won't trigger a must_use warning on WDF APIs that don't return a value - unsafe { - wdk_sys::call_unsafe_wdf_function_binding!(WdfSpinLockAcquire, wdf_spin_lock); - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs new file mode 120000 index 000000000..e77fcc3f9 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_spin_lock_acquire.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_spin_lock_acquire.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs deleted file mode 100644 index 9a3872970..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -fn foo() { - unsafe { wdk_sys::call_unsafe_wdf_function_binding!(WdfVerifierDbgBreakPoint) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs new file mode 120000 index 000000000..f2bb2b511 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/macrotest/wdf_verifier_dbg_break_point.rs @@ -0,0 +1 @@ +../../../inputs/macrotest/wdf_verifier_dbg_break_point.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs deleted file mode 100644 index 177818eb0..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - // WdfApiThatDoesNotExist is a WDF API that does not exist! - unsafe { call_unsafe_wdf_function_binding!(WdfApiThatDoesNotExist, driver as PDRIVER_OBJECT,) } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs new file mode 120000 index 000000000..14059dc88 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_api_that_does_not_exist.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_api_that_does_not_exist.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs deleted file mode 100644 index 644a50050..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -extern "C" fn evt_driver_device_add( - _driver: WDFDRIVER, - mut device_init: *mut WDFDEVICE_INIT, -) -> NTSTATUS { - let mut device_handle_output: WDFDEVICE = WDF_NO_HANDLE.cast(); - - // The NTSTATUS return value of WdfDeviceCreate is unused! - unsafe { - call_unsafe_wdf_function_binding!( - WdfDeviceCreate, - &mut device_init, - WDF_NO_OBJECT_ATTRIBUTES, - &mut device_handle_output, - ) - }; - - 0 -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs new file mode 120000 index 000000000..94c8088d7 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_device_create_unused_return_type.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_device_create_unused_return_type.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs deleted file mode 100644 index 75ea68019..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..WDF_DRIVER_CONFIG::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver as PDRIVER_OBJECT, - registry_path, - // The object attributes are missing from this call! - // WDF_NO_OBJECT_ATTRIBUTES, - &mut driver_config, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs new file mode 120000 index 000000000..a3123ce4d --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_missing_arg.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_driver_create_missing_arg.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs deleted file mode 100644 index ffcca5e83..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. -// No other function in this compilation unit exports this name, preventing symbol conflicts. -#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry -pub extern "system" fn driver_entry( - driver: &mut DRIVER_OBJECT, - registry_path: PCUNICODE_STRING, -) -> NTSTATUS { - let mut driver_config = WDF_DRIVER_CONFIG { - Size: core::mem::size_of::() as ULONG, - ..WDF_DRIVER_CONFIG::default() - }; - let driver_handle_output = WDF_NO_HANDLE as *mut WDFDRIVER; - - unsafe { - call_unsafe_wdf_function_binding!( - WdfDriverCreate, - driver as PDRIVER_OBJECT, - registry_path, - // The order of the next two arguments is swapped! - &mut driver_config, - WDF_NO_OBJECT_ATTRIBUTES, - driver_handle_output, - ) - } -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs new file mode 120000 index 000000000..ff8e6c8f1 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_driver_create_wrong_arg_order.rs \ No newline at end of file diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs deleted file mode 100644 index 6172fe55c..000000000 --- a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation -// License: MIT OR Apache-2.0 -#![no_main] -#![deny(warnings)] - -use wdk_sys::*; - -fn foo(timer_config: &mut WDF_TIMER_CONFIG, attributes: &mut WDF_OBJECT_ATTRIBUTES,) { - let mut timer = core::ptr::null_mut(); - let _nt_status = call_unsafe_wdf_function_binding!( - WdfTimerCreate, - timer_config, - attributes, - &mut timer, - ); -} diff --git a/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs new file mode 120000 index 000000000..4a715fd06 --- /dev/null +++ b/tests/wdk-macros-tests/tests/outputs/stable/trybuild/wdf_timer_create_missing_unsafe.rs @@ -0,0 +1 @@ +../../../inputs/trybuild/wdf_timer_create_missing_unsafe.rs \ No newline at end of file From cdb0c0cf8b59ba45a4727b7d2ce6be598144141b Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 15 Oct 2025 16:04:33 -0700 Subject: [PATCH 29/32] Update crates/cargo-wdk/tests/test_utils/mod.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Leon Durrenberger --- crates/cargo-wdk/tests/test_utils/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-wdk/tests/test_utils/mod.rs b/crates/cargo-wdk/tests/test_utils/mod.rs index c816e9de9..dc8ed3cda 100644 --- a/crates/cargo-wdk/tests/test_utils/mod.rs +++ b/crates/cargo-wdk/tests/test_utils/mod.rs @@ -163,7 +163,7 @@ where K: AsRef, { // SAFETY: this function is only conditionally compiled for windows targets, and - // env::set_var is always safe for windows targets + // env::remove_var is always safe for windows targets unsafe { std::env::remove_var(key); } From 86b93992d24d36880734718e0fdfe17fba739cf0 Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 15 Oct 2025 16:04:50 -0700 Subject: [PATCH 30/32] Update crates/wdk-build/src/utils.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Leon Durrenberger --- crates/wdk-build/src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index af5d758c1..8daf17400 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -402,7 +402,7 @@ where K: AsRef, { // SAFETY: this function is only conditionally compiled for windows targets, and - // env::set_var is always safe for windows targets + // env::remove_var is always safe for windows targets unsafe { env::remove_var(key); } From a37a004d90b978aceb9205b164c082b7a61a9c6c Mon Sep 17 00:00:00 2001 From: Leon Durrenberger Date: Wed, 15 Oct 2025 16:05:09 -0700 Subject: [PATCH 31/32] Update crates/cargo-wdk/src/test_utils.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Leon Durrenberger --- crates/cargo-wdk/src/test_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-wdk/src/test_utils.rs b/crates/cargo-wdk/src/test_utils.rs index 877cb9b10..7f99ba437 100644 --- a/crates/cargo-wdk/src/test_utils.rs +++ b/crates/cargo-wdk/src/test_utils.rs @@ -114,7 +114,7 @@ where K: AsRef, { // SAFETY: this function is only conditionally compiled for windows targets, and - // env::set_var is always safe for windows targets + // env::remove_var is always safe for windows targets unsafe { std::env::remove_var(key); } From 9865b24c9885daf163a74192e9db76b804fa1c3a Mon Sep 17 00:00:00 2001 From: leon-xd Date: Wed, 15 Oct 2025 16:14:21 -0700 Subject: [PATCH 32/32] reverted all to_string functions to shorter path --- crates/cargo-wdk/src/actions/build/tests.rs | 2 +- crates/wdk-build/src/cargo_make.rs | 2 +- crates/wdk-build/src/lib.rs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index c7080ea44..dd2ff9ccd 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -1727,7 +1727,7 @@ impl TestBuildAction { &manifest_path, ] .into_iter() - .map(std::string::ToString::to_string) + .map(ToString::to_string) .collect(); if let Some(profile) = self.profile { expected_cargo_build_args.push("--profile".to_string()); diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index d89cd90d1..b7cd29d21 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -672,7 +672,7 @@ pub fn setup_wdk_version() -> Result, ConfigErr } set_var(WDK_VERSION_ENV_VAR, detected_sdk_version); - Ok([WDK_VERSION_ENV_VAR].map(std::string::ToString::to_string)) + Ok([WDK_VERSION_ENV_VAR].map(ToString::to_string)) } /// Sets the `WDK_INFVERIF_SAMPLE_FLAG` environment variable to contain the diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index b4590d7bb..eca5d787a 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -794,7 +794,7 @@ impl Config { "--warn-=no-microsoft", ] .into_iter() - .map(std::string::ToString::to_string) + .map(ToString::to_string) } /// Returns a [`String`] iterator over all the headers for a given @@ -949,7 +949,7 @@ impl Config { "Usbpmapi.h", ] .iter() - .map(std::string::ToString::to_string), + .map(ToString::to_string), ); if matches!( self.driver_config, @@ -958,7 +958,7 @@ impl Config { headers.extend( ["usbbusif.h", "usbdlib.h", "usbfnattach.h", "usbfnioctl.h"] .iter() - .map(std::string::ToString::to_string), + .map(ToString::to_string), ); } @@ -981,7 +981,7 @@ impl Config { "urs/1.0/UrsCx.h", ] .iter() - .map(std::string::ToString::to_string), + .map(ToString::to_string), ); let latest_ucx_header_path = self.ucx_header()?;