├── .gitignore ├── taplo.toml ├── .gitattributes ├── .vscode └── settings.json ├── general └── echo │ └── kmdf │ ├── driver │ └── DriverSync │ │ ├── build.rs │ │ ├── Cargo.toml │ │ ├── echo_2.inx │ │ └── src │ │ ├── wdf_object_context.rs │ │ ├── driver.rs │ │ ├── lib.rs │ │ ├── device.rs │ │ └── queue.rs │ └── exe │ ├── Cargo.toml │ └── src │ └── main.rs ├── tools └── dv │ └── kmdf │ └── fail_driver_pool_leak │ ├── build.rs │ ├── Cargo.toml │ ├── src │ ├── lib.rs │ └── driver.rs │ ├── fail_driver_pool_leak.inx │ └── README.md ├── .cargo └── config.toml ├── CODE_OF_CONDUCT.md ├── Makefile.toml ├── .github ├── dependabot.yaml └── workflows │ ├── cargo-audit.yaml │ ├── code-formatting-check.yaml │ ├── github-dependency-review.yaml │ ├── build.yaml │ ├── docs.yaml │ └── lint.yaml ├── Cargo.toml ├── LICENSE-MIT ├── rustfmt.toml ├── SECURITY.md ├── README.md ├── CONTRIBUTING.md ├── LICENSE-APACHE └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /taplo.toml: -------------------------------------------------------------------------------- 1 | exclude = ["target/**"] 2 | 3 | [formatting] 4 | # enable crlf endings since core.eol is CRLF by default on Windows 5 | crlf = true 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform normalization 2 | * text=auto 3 | 4 | *.rs text diff=rust 5 | *.toml text diff=toml 6 | Cargo.lock text 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.rustfmt.extraArgs": [ 3 | "+nightly" 4 | ], 5 | "rust-analyzer.rustfmt.rangeFormatting.enable": true, 6 | "evenBetterToml.formatter.crlf": true 7 | } -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // License: MIT OR Apache-2.0 3 | 4 | fn main() -> anyhow::Result<()> { 5 | Ok(wdk_build::configure_wdk_binary_build()?) 6 | } 7 | -------------------------------------------------------------------------------- /tools/dv/kmdf/fail_driver_pool_leak/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // License: MIT OR Apache-2.0 3 | 4 | fn main() -> anyhow::Result<()> { 5 | Ok(wdk_build::configure_wdk_binary_build()?) 6 | } 7 | -------------------------------------------------------------------------------- /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | # Any flags here must be also added to env.RUSTFLAGS in build.yaml due to rustflag overriding rules: https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags 3 | rustflags = ["-C", "target-feature=+crt-static"] 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /Makefile.toml: -------------------------------------------------------------------------------- 1 | extend = [ 2 | { path = "target/rust-driver-makefile.toml" }, 3 | { path = "target/rust-driver-sample-makefile.toml" }, 4 | ] 5 | 6 | [env] 7 | CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true 8 | 9 | [config] 10 | load_script = ''' 11 | #!@rust 12 | //! ```cargo 13 | //! [dependencies] 14 | //! wdk-build = "0.4.0" 15 | //! ``` 16 | #![allow(unused_doc_comments)] 17 | 18 | wdk_build::cargo_make::load_rust_driver_makefile()?; 19 | wdk_build::cargo_make::load_rust_driver_sample_makefile()? 20 | ''' 21 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "echo-2" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | license.workspace = true 6 | publish.workspace = true 7 | 8 | [package.metadata.wdk] 9 | # Using workspace wdk config 10 | 11 | [lib] 12 | crate-type = ["cdylib"] 13 | 14 | [dependencies] 15 | paste.workspace = true 16 | wdk.workspace = true 17 | wdk-alloc.workspace = true 18 | wdk-panic.workspace = true 19 | wdk-sys.workspace = true 20 | 21 | [build-dependencies] 22 | anyhow.workspace = true 23 | wdk-build.workspace = true 24 | 25 | [features] 26 | default = [] 27 | nightly = ["wdk/nightly", "wdk-sys/nightly"] 28 | -------------------------------------------------------------------------------- /tools/dv/kmdf/fail_driver_pool_leak/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fail_driver_pool_leak" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish.workspace = true 6 | repository.workspace = true 7 | license.workspace = true 8 | 9 | [package.metadata.wdk] 10 | # Using workspace wdk config 11 | 12 | [lib] 13 | crate-type = ["cdylib"] 14 | 15 | [dependencies] 16 | wdk.workspace = true 17 | wdk-alloc.workspace = true 18 | wdk-panic.workspace = true 19 | wdk-sys.workspace = true 20 | 21 | [build-dependencies] 22 | anyhow.workspace = true 23 | wdk-build.workspace = true 24 | 25 | [features] 26 | default = [] 27 | nightly = ["wdk/nightly", "wdk-sys/nightly"] 28 | -------------------------------------------------------------------------------- /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | day: "wednesday" 8 | timezone: "America/Los_Angeles" 9 | time: "06:00" 10 | commit-message: 11 | prefix: "chore" 12 | labels: 13 | - "type:dependabot" 14 | - "type:dependencies-cargo" 15 | 16 | - package-ecosystem: "github-actions" 17 | directory: "/" 18 | schedule: 19 | interval: "weekly" 20 | day: "wednesday" 21 | timezone: "America/Los_Angeles" 22 | time: "06:00" 23 | commit-message: 24 | prefix: "chore" 25 | labels: 26 | - "type:dependabot" 27 | - "type:dependencies-github-actions" 28 | -------------------------------------------------------------------------------- /general/echo/kmdf/exe/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "echoapp" 3 | version = "0.1.0" 4 | description = "Test app for kmdf echo-2 sample driver" 5 | keywords = ["windows", "kmdf", "driver", "wdk", "sample"] 6 | rust-version = "1.72.1" 7 | license.workspace = true 8 | edition.workspace = true 9 | publish.workspace = true 10 | 11 | [dependencies.once_cell] 12 | version = "1.19.0" 13 | 14 | [dependencies.uuid] 15 | version = "1.8.0" 16 | features = ["macro-diagnostics"] 17 | 18 | [dependencies.windows-sys] 19 | version = "0.59.0" 20 | features = [ 21 | "Win32_Devices_DeviceAndDriverInstallation", 22 | "Win32_Storage_FileSystem", 23 | "Win32_Foundation", 24 | "Win32_Security", 25 | "Win32_System_IO", 26 | "Win32_System_WindowsProgramming", 27 | "Win32_System_Threading", 28 | ] 29 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "general/echo/kmdf/driver/*", 4 | "general/echo/kmdf/exe", 5 | "tools/dv/kmdf/fail_driver_pool_leak", 6 | ] 7 | resolver = "2" 8 | 9 | [workspace.package] 10 | edition = "2021" 11 | publish = false 12 | repository = "https://github.com/microsoft/windows-rust-driver-samples" 13 | license = "MIT OR Apache-2.0" 14 | 15 | [workspace.metadata.wdk.driver-model] 16 | driver-type = "KMDF" 17 | kmdf-version-major = 1 18 | target-kmdf-version-minor = 33 19 | 20 | [profile.dev] 21 | panic = "abort" 22 | 23 | [profile.release] 24 | panic = "abort" 25 | lto = true 26 | 27 | [workspace.dependencies] 28 | anyhow = "1.0.89" 29 | paste = "1.0.14" 30 | wdk = "0.4.1" 31 | wdk-alloc = "0.4.1" 32 | wdk-build = "0.5.1" 33 | wdk-panic = "0.4.1" 34 | wdk-sys = "0.5.1" 35 | -------------------------------------------------------------------------------- /.github/workflows/cargo-audit.yaml: -------------------------------------------------------------------------------- 1 | name: Cargo Audit 2 | 3 | on: 4 | push: 5 | paths: 6 | - "**/Cargo.toml" 7 | - "**/Cargo.lock" 8 | pull_request: 9 | merge_group: 10 | schedule: # Trigger a job on default branch at 4AM PST everyday 11 | - cron: 0 11 * * * 12 | 13 | concurrency: 14 | group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} 15 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 16 | 17 | jobs: 18 | cargo_audit: 19 | name: Cargo Audit 20 | runs-on: windows-latest 21 | permissions: 22 | issues: write 23 | checks: write 24 | 25 | steps: 26 | - name: Checkout Repository 27 | uses: actions/checkout@v4 28 | 29 | - name: Run Cargo Audit 30 | uses: rustsec/audit-check@v1 31 | with: 32 | token: ${{ secrets.GITHUB_TOKEN }} 33 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE -------------------------------------------------------------------------------- /.github/workflows/code-formatting-check.yaml: -------------------------------------------------------------------------------- 1 | name: Code Formatting Check 2 | 3 | on: 4 | push: 5 | pull_request: 6 | merge_group: 7 | schedule: # Trigger a job on default branch at 4AM PST everyday 8 | - cron: 0 11 * * * 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} 12 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 13 | 14 | jobs: 15 | cargo-fmt: 16 | name: .rs Formatting Check 17 | runs-on: windows-latest 18 | 19 | steps: 20 | - name: Checkout Repository 21 | uses: actions/checkout@v4 22 | 23 | - name: Install Rust Toolchain (Nightly) 24 | uses: dtolnay/rust-toolchain@nightly 25 | with: 26 | components: rustfmt 27 | 28 | - name: Run Cargo Format 29 | run: cargo +nightly fmt --all -- --check 30 | 31 | taplo-fmt: 32 | name: .toml Formatting Check 33 | runs-on: windows-latest 34 | 35 | steps: 36 | - name: Checkout Repository 37 | uses: actions/checkout@v4 38 | 39 | - name: Install Rust Toolchain (Stable) 40 | uses: dtolnay/rust-toolchain@stable 41 | 42 | - name: Install taplo-cli 43 | uses: taiki-e/install-action@v2 44 | with: 45 | tool: taplo-cli 46 | 47 | - run: taplo fmt --check --diff 48 | name: Check TOML files formatting 49 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # https://rust-lang.github.io/rustfmt/ outlines all configuration options 2 | 3 | # Required to enable unstable features: https://github.com/rust-lang/rustfmt/issues/3387 4 | unstable_features = true 5 | 6 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3384 7 | condense_wildcard_suffixes = true 8 | 9 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3348 10 | format_code_in_doc_comments = true 11 | 12 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3354 13 | format_macro_matchers = true 14 | 15 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3353 16 | format_strings = true 17 | 18 | # Unstable: https://github.com/rust-lang/rustfmt/issues/5081 19 | hex_literal_case = "Upper" 20 | 21 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3361 22 | imports_layout = "HorizontalVertical" 23 | 24 | # Unstable: https://github.com/rust-lang/rustfmt/issues/4991 25 | imports_granularity = "Crate" 26 | 27 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3350 28 | normalize_comments = true 29 | 30 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3351 31 | normalize_doc_attributes = true 32 | 33 | # Unstable: https://github.com/rust-lang/rustfmt/issues/5083 34 | group_imports = "StdExternalCrate" 35 | 36 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3363 37 | reorder_impl_items = true 38 | 39 | # Unstable: https://github.com/rust-lang/rustfmt/issues/3347 40 | wrap_comments = true 41 | -------------------------------------------------------------------------------- /tools/dv/kmdf/fail_driver_pool_leak/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | //! # Abstract 5 | //! 6 | //! This KMDF sample contains an intentional error that is designed to 7 | //! demonstrate the capabilities and features of Driver Verifier and the Device 8 | //! Fundamental tests. 9 | //! 10 | //! The driver is designed to allocate memory using ExAllocatePool2 to its 11 | //! Device Context buffer when a device is added by the PnP manager. However, 12 | //! this buffer is not freed anywhere in the driver, including the driver unload 13 | //! function. 14 | //! 15 | //! By enabling Driver Verifier on this driver, the pool leak 16 | //! violation can be caught when the driver is unloaded and with an active KDNET 17 | //! session, the bug can be analyzed further. 18 | 19 | #![no_std] 20 | #![deny(clippy::all)] 21 | #![warn(clippy::pedantic)] 22 | #![warn(clippy::nursery)] 23 | #![warn(clippy::cargo)] 24 | #![allow(clippy::missing_safety_doc)] 25 | #![allow(clippy::doc_markdown)] 26 | 27 | #[cfg(not(test))] 28 | extern crate wdk_panic; 29 | 30 | #[cfg(not(test))] 31 | use wdk_alloc::WdkAllocator; 32 | 33 | #[cfg(not(test))] 34 | #[global_allocator] 35 | static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; 36 | 37 | use wdk_sys::{GUID, PVOID}; 38 | 39 | // {A1B2C3D4-E5F6-7890-1234-56789ABCDEF0} 40 | const GUID_DEVINTERFACE: GUID = GUID { 41 | Data1: 0xA1B2_C3D4u32, 42 | Data2: 0xE5F6u16, 43 | Data3: 0x7890u16, 44 | Data4: [ 45 | 0x12u8, 0x34u8, 0x56u8, 0x78u8, 0x9Au8, 0xBCu8, 0xDEu8, 0xF0u8, 46 | ], 47 | }; 48 | 49 | // Global Buffer for the driver 50 | static mut GLOBAL_BUFFER: PVOID = core::ptr::null_mut(); 51 | 52 | mod driver; 53 | -------------------------------------------------------------------------------- /.github/workflows/github-dependency-review.yaml: -------------------------------------------------------------------------------- 1 | name: Dependency Review 2 | 3 | on: 4 | push: 5 | pull_request: 6 | merge_group: 7 | 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} 10 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 11 | 12 | jobs: 13 | dependency-review: 14 | name: Github Dependency Review 15 | runs-on: ubuntu-latest 16 | permissions: 17 | pull-requests: write 18 | contents: read 19 | 20 | steps: 21 | - name: Checkout Repository 22 | uses: actions/checkout@v4 23 | 24 | - name: Dependency Review 25 | uses: actions/dependency-review-action@v4 26 | with: 27 | allow-licenses: >- 28 | MIT, 29 | Apache-2.0, 30 | BSD-3-Clause, 31 | ISC, 32 | Unicode-DFS-2016 33 | # anstyle@1.0.4 is licensed as (MIT OR Apache-2.0), but the Github api fails to detect it: https://github.com/rust-cli/anstyle/tree/main/crates/anstyle 34 | allow-dependencies-licenses: 'pkg:cargo/anstyle@1.0.4' 35 | comment-summary-in-pr: on-failure 36 | # Explicit refs required for merge_group and push triggers: 37 | # https://github.com/actions/dependency-review-action/issues/456 38 | # https://github.com/actions/dependency-review-action/issues/252 39 | base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || (github.event_name == 'push' && github.event.before || (github.event_name == 'merge_group' && 'main' || 'unsupported trigger' ) ) }} 40 | head-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || (github.event_name == 'push' && github.sha || (github.event_name == 'merge_group' && github.ref || 'unsupported trigger' ) ) }} 41 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/echo_2.inx: -------------------------------------------------------------------------------- 1 | ;=================================================================== 2 | ; Copyright (c)2023, Microsoft Corporation 3 | ; 4 | ;Module Name: 5 | ; ECHO_2.INF 6 | ;=================================================================== 7 | 8 | [Version] 9 | Signature = "$WINDOWS NT$" 10 | Class = Sample 11 | ClassGuid = {78A1C341-4539-11d3-B88D-00C04FAD5171} 12 | Provider = %ProviderString% 13 | PnpLockDown = 1 14 | 15 | [DestinationDirs] 16 | DefaultDestDir = 13 17 | 18 | [SourceDisksNames] 19 | 1 = %DiskId1%,,,"" 20 | 21 | [SourceDisksFiles] 22 | echo_2.sys = 1,, 23 | 24 | ; ================= Class section ===================== 25 | 26 | [ClassInstall32] 27 | Addreg=SampleClassReg 28 | 29 | [SampleClassReg] 30 | HKR,,,0,%ClassName% 31 | HKR,,Icon,,-5 32 | 33 | ; ================= Install section ================= 34 | 35 | [Manufacturer] 36 | %StdMfg%=Standard,NT$ARCH$.10.0...16299 37 | 38 | [Standard.NT$ARCH$.10.0...16299] 39 | %ECHO.DeviceDesc%=ECHO_Device, root\ECHO_2 40 | 41 | [ECHO_Device.NT$ARCH$] 42 | CopyFiles=Drivers_Dir 43 | 44 | [Drivers_Dir] 45 | echo_2.sys 46 | 47 | ; ================= Service installation ================= 48 | [ECHO_Device.NT$ARCH$.Services] 49 | AddService = ECHO_2, %SPSVCINST_ASSOCSERVICE%, ECHO_Service_Inst 50 | 51 | [ECHO_Service_Inst] 52 | DisplayName = %ECHO.SVCDESC% 53 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 54 | StartType = 3 ; SERVICE_DEMAND_START 55 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 56 | ServiceBinary = %13%\echo_2.sys 57 | 58 | ; ================= Strings ================= 59 | [Strings] 60 | SPSVCINST_ASSOCSERVICE = 0x00000002 61 | ProviderString = "TODO-Set-Provider" 62 | StdMfg = "(Standard system devices)" 63 | DiskId1 = "WDF Sample ECHO Installation Disk #1 (DriverSync)" 64 | ECHO.DeviceDesc = "Sample WDF ECHO Driver (DriverSync)" 65 | ECHO.SVCDESC = "Sample WDF ECHO Service (DriverSync)" 66 | ClassName = "Sample Device" 67 | -------------------------------------------------------------------------------- /tools/dv/kmdf/fail_driver_pool_leak/fail_driver_pool_leak.inx: -------------------------------------------------------------------------------- 1 | ;=================================================================== 2 | ; Copyright (c)2023, Microsoft Corporation 3 | ; 4 | ;Module Name: 5 | ; FAIL_DRIVER_POOL_LEAK.INF 6 | ;=================================================================== 7 | 8 | [Version] 9 | Signature = "$WINDOWS NT$" 10 | Class = Sample 11 | ClassGuid = {78A1C341-4539-11d3-B88D-00C04FAD5171} 12 | Provider = %ProviderString% 13 | PnpLockDown = 1 14 | 15 | [DestinationDirs] 16 | DefaultDestDir = 13 17 | 18 | [SourceDisksNames] 19 | 1 = %DiskId1%,,,"" 20 | 21 | [SourceDisksFiles] 22 | fail_driver_pool_leak.sys = 1,, 23 | 24 | ; ================= Install section ================= 25 | 26 | [Manufacturer] 27 | %StdMfg%=Standard,NT$ARCH$.10.0...16299 28 | 29 | [Standard.NT$ARCH$.10.0...16299] 30 | %FAIL_DRIVER_POOL_LEAK.DeviceDesc%=FAIL_DRIVER_POOL_LEAK_DEVICE, fail_driver_pool_leak 31 | 32 | [FAIL_DRIVER_POOL_LEAK_DEVICE.NT$ARCH$] 33 | CopyFiles=Drivers_Dir 34 | 35 | [Drivers_Dir] 36 | fail_driver_pool_leak.sys 37 | 38 | ; ================= Service installation ================= 39 | [FAIL_DRIVER_POOL_LEAK_Device.NT$ARCH$.Services] 40 | AddService = fail_driver_pool_leak, %SPSVCINST_ASSOCSERVICE%, fail_driver_pool_leak_svc_ins 41 | 42 | [fail_driver_pool_leak_svc_ins] 43 | DisplayName = %FAIL_DRIVER_POOL_LEAK.SVCDESC% 44 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 45 | StartType = 3 ; SERVICE_DEMAND_START 46 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 47 | ServiceBinary = %13%\fail_driver_pool_leak.sys 48 | 49 | ; ================= Strings ================= 50 | [Strings] 51 | SPSVCINST_ASSOCSERVICE = 0x00000002 52 | ProviderString = "Rust-DV-Fail-Sample" 53 | StdMfg = "(Standard system devices)" 54 | DiskId1 = "WDF FAIL_DRIVER_POOL_LEAK Installation Disk #1" 55 | FAIL_DRIVER_POOL_LEAK.DeviceDesc = "WDF FAIL_DRIVER_POOL_LEAK Device" 56 | FAIL_DRIVER_POOL_LEAK.SVCDESC = "WDF FAIL_DRIVER_POOL_LEAK Service" -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/src/wdf_object_context.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | use wdk_sys::{PCWDF_OBJECT_CONTEXT_TYPE_INFO, WDF_OBJECT_CONTEXT_TYPE_INFO}; 5 | 6 | #[repr(transparent)] 7 | pub struct WDFObjectContextTypeInfo(WDF_OBJECT_CONTEXT_TYPE_INFO); 8 | unsafe impl Sync for WDFObjectContextTypeInfo {} 9 | 10 | impl WDFObjectContextTypeInfo { 11 | pub const fn new(inner: WDF_OBJECT_CONTEXT_TYPE_INFO) -> Self { 12 | Self(inner) 13 | } 14 | 15 | pub const fn get_unique_type(&self) -> PCWDF_OBJECT_CONTEXT_TYPE_INFO { 16 | let inner = core::ptr::from_ref::(self).cast::(); 17 | // SAFETY: This dereference is sound since the underlying 18 | // WDF_OBJECT_CONTEXT_TYPE_INFO is guaranteed to have the same memory 19 | // layout as WDFObjectContextTypeInfo since WDFObjectContextTypeInfo is 20 | // declared as repr(transparent) 21 | unsafe { *inner }.UniqueType 22 | } 23 | } 24 | 25 | macro_rules! wdf_get_context_type_info { 26 | ($context_type:ident) => { 27 | paste::paste! { 28 | [].get_unique_type() 29 | } 30 | }; 31 | } 32 | 33 | pub(crate) use wdf_get_context_type_info; 34 | 35 | macro_rules! wdf_declare_context_type_with_name { 36 | ($context_type:ident , $casting_function:ident) => { 37 | paste::paste! { 38 | type [] = *mut $context_type; 39 | 40 | #[link_section = ".data"] 41 | pub static []: crate::wdf_object_context::WDFObjectContextTypeInfo = crate::wdf_object_context::WDFObjectContextTypeInfo::new( 42 | WDF_OBJECT_CONTEXT_TYPE_INFO { 43 | Size: crate::WDF_OBJECT_CONTEXT_TYPE_INFO_SIZE, 44 | ContextName: concat!(stringify!($context_type),'\0').as_bytes().as_ptr().cast(), 45 | ContextSize: core::mem::size_of::<$context_type>(), 46 | UniqueType: core::ptr::addr_of!([]).cast(), 47 | EvtDriverGetUniqueContextType: None, 48 | }); 49 | 50 | pub unsafe fn $casting_function(handle: WDFOBJECT) -> [] { 51 | unsafe { 52 | call_unsafe_wdf_function_binding!( 53 | WdfObjectGetTypedContextWorker, 54 | handle, 55 | crate::wdf_object_context::wdf_get_context_type_info!($context_type), 56 | ).cast() 57 | } 58 | } 59 | } 60 | }; 61 | } 62 | 63 | pub(crate) use wdf_declare_context_type_with_name; 64 | 65 | macro_rules! wdf_declare_context_type { 66 | ($context_type:ident) => { 67 | paste::paste! { 68 | crate::wdf_object_context::wdf_declare_context_type_with_name!($context_type, []); 69 | } 70 | }; 71 | } 72 | 73 | pub(crate) use wdf_declare_context_type; 74 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | pull_request: 6 | merge_group: 7 | schedule: # Trigger a job on default branch at 4AM PST everyday 8 | - cron: "0 11 * * *" 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} 12 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 13 | 14 | env: 15 | RUSTFLAGS: >- 16 | -D warnings 17 | -C target-feature=+crt-static 18 | 19 | jobs: 20 | build: 21 | name: Build 22 | strategy: 23 | fail-fast: false # Allow all matrix variants to complete even if some fail 24 | matrix: 25 | runner: 26 | - name: windows-latest 27 | arch: amd64 28 | - name: windows-11-arm 29 | arch: arm64 30 | 31 | wdk: 32 | - version: 10.0.22621 # NI WDK 33 | source: winget 34 | - version: 10.0.26100 # GE WDK 35 | source: nuget 36 | 37 | llvm: 38 | - 17.0.6 39 | 40 | rust_toolchain: 41 | - stable 42 | - beta 43 | - nightly 44 | 45 | cargo_profile: 46 | - dev 47 | - release 48 | 49 | target_triple: 50 | - name: x86_64-pc-windows-msvc 51 | arch: amd64 52 | - name: aarch64-pc-windows-msvc 53 | arch: arm64 54 | 55 | runs-on: ${{ matrix.runner.name }} 56 | 57 | steps: 58 | - name: Checkout Repository 59 | uses: actions/checkout@v4 60 | 61 | - name: Checkout windows-drivers-rs actions 62 | uses: actions/checkout@v4 63 | with: 64 | repository: microsoft/windows-drivers-rs 65 | ref: main 66 | path: _temp/windows-drivers-rs 67 | sparse-checkout: | 68 | .github/actions 69 | sparse-checkout-cone-mode: false 70 | 71 | - name: Copy actions to workspace 72 | shell: pwsh 73 | run: Copy-Item -Recurse -Force _temp/windows-drivers-rs/.github/actions .github/ 74 | 75 | - name: Install Winget 76 | uses: ./.github/actions/install-winget 77 | with: 78 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 79 | 80 | - name: Install Winget PowerShell Module 81 | shell: pwsh 82 | run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force 83 | 84 | - name: Install LLVM ${{ matrix.llvm }} 85 | uses: ./.github/actions/install-llvm 86 | with: 87 | version: ${{ matrix.llvm }} 88 | 89 | - name: Install WDK (${{ matrix.wdk.version }}) 90 | uses: ./.github/actions/install-wdk 91 | with: 92 | version: ${{ matrix.wdk.version }} 93 | source: ${{ matrix.wdk.source }} 94 | host: ${{ matrix.wdk.source == 'nuget' && matrix.runner.arch || '' }} 95 | target: ${{ matrix.wdk.source == 'nuget' && matrix.target_triple.arch || '' }} 96 | 97 | - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) 98 | uses: dtolnay/rust-toolchain@master 99 | with: 100 | toolchain: ${{ matrix.rust_toolchain }} 101 | targets: ${{ matrix.target_triple.name }} 102 | 103 | - name: Run Cargo Build 104 | run: cargo +${{ matrix.rust_toolchain }} build --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} --workspace 105 | 106 | # Steps to use cargo-make to build and package drivers 107 | - name: Install Cargo Make 108 | uses: taiki-e/install-action@v2 109 | with: 110 | tool: cargo-make 111 | 112 | - name: Build and Package Sample Drivers 113 | run: cargo make default +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} 114 | 115 | # Steps to use cargo-wdk to build and package drivers 116 | - name: Install cargo-wdk binary 117 | run: cargo +${{ matrix.rust_toolchain }} install cargo-wdk --locked --force 118 | 119 | - name: Build and Package Sample Drivers with cargo-wdk 120 | run: cargo +${{ matrix.rust_toolchain }} wdk build --sample --profile ${{ matrix.cargo_profile }} --target-arch ${{ matrix.target_triple.arch }} 121 | -------------------------------------------------------------------------------- /.github/workflows/docs.yaml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | 3 | on: 4 | push: 5 | pull_request: 6 | merge_group: 7 | schedule: # Trigger a job on default branch at 4AM PST everyday 8 | - cron: "0 11 * * *" 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} 12 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 13 | 14 | env: 15 | RUSTDOCFLAGS: -D warnings 16 | 17 | jobs: 18 | docs: 19 | name: Docs 20 | strategy: 21 | fail-fast: false # Allow all matrix variants to complete even if some fail 22 | matrix: 23 | runner: 24 | - name: windows-latest 25 | arch: amd64 26 | - name: windows-11-arm 27 | arch: arm64 28 | 29 | wdk: 30 | - version: 10.0.22621 # NI WDK 31 | source: winget 32 | - version: 10.0.26100 # GE WDK 33 | source: nuget 34 | 35 | llvm: 36 | - 17.0.6 37 | 38 | rust_toolchain: 39 | - stable 40 | - beta 41 | - nightly 42 | 43 | cargo_profile: 44 | - dev 45 | - release 46 | 47 | target_triple: 48 | - name: x86_64-pc-windows-msvc 49 | arch: amd64 50 | - name: aarch64-pc-windows-msvc 51 | arch: arm64 52 | 53 | runs-on: ${{ matrix.runner.name }} 54 | 55 | steps: 56 | - name: Checkout Repository 57 | uses: actions/checkout@v4 58 | 59 | - name: Checkout windows-drivers-rs actions 60 | uses: actions/checkout@v4 61 | with: 62 | repository: microsoft/windows-drivers-rs 63 | ref: main 64 | path: _temp/windows-drivers-rs 65 | sparse-checkout: | 66 | .github/actions 67 | sparse-checkout-cone-mode: false 68 | 69 | - name: Copy actions to workspace 70 | shell: pwsh 71 | run: Copy-Item -Recurse -Force _temp/windows-drivers-rs/.github/actions .github/ 72 | 73 | - name: Install Winget 74 | uses: ./.github/actions/install-winget 75 | with: 76 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 77 | 78 | - name: Install Winget PowerShell Module 79 | shell: pwsh 80 | run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force 81 | 82 | - name: Install LLVM ${{ matrix.llvm }} 83 | uses: ./.github/actions/install-llvm 84 | with: 85 | version: ${{ matrix.llvm }} 86 | 87 | - name: Install WDK (${{ matrix.wdk.version }}) 88 | uses: ./.github/actions/install-wdk 89 | with: 90 | version: ${{ matrix.wdk.version }} 91 | source: ${{ matrix.wdk.source }} 92 | host: ${{ matrix.wdk.source == 'nuget' && matrix.runner.arch || '' }} 93 | target: ${{ matrix.wdk.source == 'nuget' && matrix.target_triple.arch || '' }} 94 | 95 | - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) 96 | uses: dtolnay/rust-toolchain@master 97 | with: 98 | toolchain: ${{ matrix.rust_toolchain }} 99 | targets: ${{ matrix.target_triple.name }} 100 | 101 | - name: Run Cargo Doc 102 | # proc-macro crates must be excluded to avoid cargo doc bug: https://github.com/rust-lang/cargo/issues/10368 103 | run: cargo +${{ matrix.rust_toolchain }} doc --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} --workspace --exclude wdk-macros 104 | - name: Run Cargo Doc (--features nightly) 105 | if: matrix.rust_toolchain == 'nightly' 106 | # proc-macro crates must be excluded to avoid cargo doc bug: https://github.com/rust-lang/cargo/issues/10368 107 | run: cargo +${{ matrix.rust_toolchain }} doc --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} --workspace --exclude wdk-macros --features nightly 108 | - name: Run Cargo Doc w/ proc-macro crates 109 | # Skip duplicate runs on the same runner 110 | if: matrix.target_triple.arch == matrix.runner.arch 111 | # cargo doc can only generate documentation for proc-macro crates when --target is not specified due to a cargo doc bug: https://github.com/rust-lang/cargo/issues/7677 112 | run: cargo +${{ matrix.rust_toolchain }} doc --locked --profile ${{ matrix.cargo_profile }} 113 | 114 | - name: Run Cargo Doc w/ proc-macro crates (--features nightly) 115 | # Skip duplicate runs on the same runner 116 | if: ${{ matrix.target_triple.arch == matrix.runner.arch && matrix.rust_toolchain == 'nightly' }} 117 | # cargo doc can only generate documentation for proc-macro crates when --target is not specified due to a cargo doc bug: https://github.com/rust-lang/cargo/issues/7677 118 | run: cargo +${{ matrix.rust_toolchain }} doc --locked --profile ${{ matrix.cargo_profile }} --features nightly 119 | -------------------------------------------------------------------------------- /tools/dv/kmdf/fail_driver_pool_leak/README.md: -------------------------------------------------------------------------------- 1 | # Fail_Driver_Pool_Leak Sample Driver 2 | 3 | The `fail_driver_pool_leak` sample demonstrates running the [Device Fundamentals Tests](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/device-fundamentals-tests) and enabling the [Driver Verifier](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/driver-verifier) for a Rust driver. We have intentionally injected a pool leak fault in the driver by allocating a global buffer using WDM's `ExAllocatePool2` function and not freeing this buffer (using `ExFreePool`) anywhere in the driver. This fault, which is not caught at compile time, can be detected by running the Device Fundamentals Tests and also by enabling the Driver Verifier on the driver. 4 | 5 | ## Steps 6 | 7 | 1. Clone the repository and navigate to the project root. 8 | 9 | 2. Install [Clang](https://clang.llvm.org/get_started.html) 10 | * Easy install option: 11 | ``` 12 | winget install LLVM.LLVM 13 | ``` 14 | 15 | 3. Build the driver project using the following command in an [EWDK environment](https://learn.microsoft.com/en-us/legal/windows/hardware/enterprise-wdk-license-2022) - 16 | ``` 17 | cargo make 18 | ``` 19 | 4. Prepare a target system (a Hyper-V VM can be used) for testing 20 | 21 | Follow the below steps to setup the test system - 22 | 1. Disable Secure boot and start the system 23 | 2. Run "ipconfig" on the host system and note down the IP (if you are using Default Switch for the VM, note down the IP on the Default Switch) 24 | 3. Install and open WinDbg, click on "Attach to Kernel". The key for the connection will be generated in the test system in the next steps. 25 | 4. Connect to the test VM and run the following commands - 26 | ``` 27 | bcdedit /set testsigning on 28 | bcdedit /debug on 29 | bcdedit /dbgsettings net hostip: port:<50000-50030> 30 | 31 | ### Copy the key string output by the above command 32 | ``` 33 | 5. Paste the key in host's WinDbg prompt and connect to the kernel 34 | 6. Restart the target/test system 35 | ``` 36 | shutdown -r -t 0 37 | ``` 38 | 39 | 5. Copy the driver package, available under ".\target\debug\fail_driver_pool_leak_package" to the target system. 40 | 41 | 6. Copy "devgen.exe" from host to the target system. Alternatively you may install WDK on the target system and add the directory that contains "devgen.exe" to PATH variable. 42 | 43 | 7. Install the driver package and create the device in the target system using the below commands - 44 | ``` 45 | cd "fail_driver_pool_leak_package" 46 | devgen.exe /add /bus ROOT /hardwareid "fail_driver_pool_leak" 47 | 48 | ## Copy the Device ID. This will be used later to run the tests 49 | 50 | pnputil.exe /add-driver .\fail_driver_pool_leak.inf /install 51 | ``` 52 | 8. Enable Driver Verifier for 'fail_driver_pool_leak.sys' driver package 53 | 1. Open run command prompt (Start + R) or cmd as administator and run "verifier" 54 | 2. In the verifier manager, 55 | - Create Standard Settings 56 | - Select driver names from list 57 | - Select 'fail_driver_pool_leak.sys' 58 | - Finish 59 | - Restart the system 60 | 61 | 9. Follow the steps in https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/how-to-test-a-driver-at-runtime-from-a-command-prompt to run tests against the device managed by this driver 62 | 63 | 10. Install TAEF and WDTF on the test computer and run the following test - 64 | ``` 65 | cd "C:\Program Files (x86)\Windows Kits\10\Testing\Tests\Additional Tests\x64\DevFund" 66 | TE.exe .\Devfund_PnPDTest_WLK_Certification.dll /P:"DQ=DeviceID='ROOT\DEVGEN\{PASTE-DEVICE-ID-HERE}'" --rebootResumeOption:Manual 67 | ``` 68 | 69 | 11. The test will lead to a Bugcheck and a BlueScreen on the target system with the following error - 70 | ``` 71 | DRIVER_VERIFIER_DETECTED_VIOLATION (c4) 72 | ``` 73 | Run ```!analyze -v``` for detailed bugcheck report 74 | 75 | Run ```!verifier 3 fail_driver_pool_leak.sys``` for info on the allocations that were leaked that caused the bugcheck. 76 | 77 | 12. (Alternatively), the bugcheck can be observed when all the devices managed by this driver are removed, i.e, when the driver is unloaded from the system. 78 | You may use pnputil/devcon to enumerate and remove the devices - 79 | ``` 80 | # To enumerate the devices 81 | pnputil /enum-devices 82 | # To remove a device 83 | pnputil /remove-device "DEVICE-ID" 84 | ``` 85 | 86 | ### References 87 | 88 | - [TAEF](https://learn.microsoft.com/en-us/windows-hardware/drivers/taef/getting-started) 89 | - [WDTF](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdtf/wdtf-runtime-library) 90 | - [Testing a driver at runtime](https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/how-to-test-a-driver-at-runtime-from-a-command-prompt) 91 | - [Using WDF to Develop a Driver](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/using-the-framework-to-develop-a-driver) 92 | - [wdfmemory](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdfmemory/) -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | pull_request: 6 | merge_group: 7 | schedule: # Trigger a job on default branch at 4AM PST everyday 8 | - cron: "0 11 * * *" 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} 12 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 13 | 14 | jobs: 15 | clippy: 16 | name: Clippy 17 | permissions: 18 | checks: write 19 | strategy: 20 | fail-fast: false # Allow all matrix variants to complete even if some fail 21 | matrix: 22 | runner: 23 | - name: windows-latest 24 | arch: amd64 25 | - name: windows-11-arm 26 | arch: arm64 27 | 28 | wdk: 29 | - version: 10.0.22621 # NI WDK 30 | source: winget 31 | - version: 10.0.26100 # GE WDK 32 | source: nuget 33 | 34 | llvm: 35 | - 17.0.6 36 | 37 | rust_toolchain: 38 | - stable 39 | - beta 40 | - nightly 41 | 42 | cargo_profile: 43 | - dev 44 | - release 45 | 46 | target_triple: 47 | - name: x86_64-pc-windows-msvc 48 | arch: amd64 49 | - name: aarch64-pc-windows-msvc 50 | arch: arm64 51 | 52 | runs-on: ${{ matrix.runner.name }} 53 | steps: 54 | - name: Checkout Repository 55 | uses: actions/checkout@v4 56 | 57 | - name: Checkout windows-drivers-rs actions 58 | uses: actions/checkout@v4 59 | with: 60 | repository: microsoft/windows-drivers-rs 61 | ref: main 62 | path: _temp/windows-drivers-rs 63 | sparse-checkout: | 64 | .github/actions 65 | sparse-checkout-cone-mode: false 66 | 67 | - name: Copy actions to workspace 68 | shell: pwsh 69 | run: Copy-Item -Recurse -Force _temp/windows-drivers-rs/.github/actions .github/ 70 | 71 | - name: Install Winget 72 | uses: ./.github/actions/install-winget 73 | with: 74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 75 | 76 | - name: Install Winget PowerShell Module 77 | shell: pwsh 78 | run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force 79 | 80 | - name: Install LLVM ${{ matrix.llvm }} 81 | uses: ./.github/actions/install-llvm 82 | with: 83 | version: ${{ matrix.llvm }} 84 | 85 | - name: Install WDK (${{ matrix.wdk.version }}) 86 | uses: ./.github/actions/install-wdk 87 | with: 88 | version: ${{ matrix.wdk.version }} 89 | source: ${{ matrix.wdk.source }} 90 | host: ${{ matrix.wdk.source == 'nuget' && matrix.runner.arch || '' }} 91 | target: ${{ matrix.wdk.source == 'nuget' && matrix.target_triple.arch || '' }} 92 | 93 | - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) 94 | uses: dtolnay/rust-toolchain@master 95 | with: 96 | toolchain: ${{ matrix.rust_toolchain }} 97 | components: clippy 98 | targets: ${{ matrix.target_triple.name }} 99 | 100 | - name: Run Cargo Clippy 101 | run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} --all-targets -- -D warnings 102 | 103 | - name: Run Cargo Clippy (--features nightly) 104 | if: matrix.rust_toolchain == 'nightly' 105 | run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} --all-targets --features nightly -- -D warnings 106 | machete: 107 | name: Detect Unused Cargo Dependencies 108 | runs-on: windows-latest 109 | strategy: 110 | matrix: 111 | wdk: 112 | - 10.0.22621 # NI WDK 113 | 114 | steps: 115 | - name: Checkout Repository 116 | uses: actions/checkout@v4 117 | 118 | - name: Checkout windows-drivers-rs actions 119 | uses: actions/checkout@v4 120 | with: 121 | repository: microsoft/windows-drivers-rs 122 | ref: main 123 | path: _temp/windows-drivers-rs 124 | sparse-checkout: | 125 | .github/actions 126 | sparse-checkout-cone-mode: false 127 | 128 | - name: Copy actions to workspace 129 | shell: pwsh 130 | run: Copy-Item -Recurse -Force _temp/windows-drivers-rs/.github/actions .github/ 131 | 132 | - name: Install Winget 133 | uses: ./.github/actions/install-winget 134 | with: 135 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 136 | 137 | - name: Install Winget PowerShell Module 138 | shell: pwsh 139 | run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force 140 | 141 | - name: Install WDK (${{ matrix.wdk }}) 142 | uses: ./.github/actions/install-wdk 143 | with: 144 | version: ${{ matrix.wdk }} 145 | source: winget 146 | 147 | - name: Install Rust Toolchain 148 | uses: dtolnay/rust-toolchain@stable 149 | 150 | - name: Install Cargo Machete 151 | uses: taiki-e/install-action@v2 152 | with: 153 | tool: cargo-machete 154 | 155 | - name: Run Cargo Machete 156 | run: cargo machete 157 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/src/driver.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | use wdk::{nt_success, paged_code, println}; 5 | use wdk_sys::{ 6 | call_unsafe_wdf_function_binding, 7 | DRIVER_OBJECT, 8 | NTSTATUS, 9 | PCUNICODE_STRING, 10 | PDRIVER_OBJECT, 11 | PWDFDEVICE_INIT, 12 | STATUS_SUCCESS, 13 | UNICODE_STRING, 14 | WDFDRIVER, 15 | WDFOBJECT, 16 | WDFSTRING, 17 | WDF_DRIVER_CONFIG, 18 | WDF_DRIVER_VERSION_AVAILABLE_PARAMS, 19 | WDF_NO_HANDLE, 20 | WDF_NO_OBJECT_ATTRIBUTES, 21 | }; 22 | 23 | use crate::{device, WDF_DRIVER_CONFIG_SIZE, WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE}; 24 | 25 | extern crate alloc; 26 | 27 | use alloc::{slice, string::String}; 28 | 29 | /// `DriverEntry` initializes the driver and is the first routine called by the 30 | /// system after the driver is loaded. `DriverEntry` specifies the other entry 31 | /// points in the function driver, such as `EvtDevice` and `DriverUnload`. 32 | /// 33 | /// # Arguments 34 | /// 35 | /// * `driver` - represents the instance of the function driver that is loaded 36 | /// into memory. `DriverEntry` must initialize members of `DriverObject` 37 | /// before it returns to the caller. `DriverObject` is allocated by the system 38 | /// before the driver is loaded, and it is released by the system after the 39 | /// system unloads the function driver from memory. 40 | /// * `registry_path` - represents the driver specific path in the Registry. The 41 | /// function driver can use the path to store driver related data between 42 | /// reboots. The path does not store hardware instance specific data. 43 | /// 44 | /// # Return value: 45 | /// 46 | /// * `STATUS_SUCCESS` - if successful, 47 | /// * `STATUS_UNSUCCESSFUL` - otherwise. 48 | #[link_section = "INIT"] 49 | #[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry 50 | extern "system" fn driver_entry( 51 | driver: &mut DRIVER_OBJECT, 52 | registry_path: PCUNICODE_STRING, 53 | ) -> NTSTATUS { 54 | let mut driver_config = WDF_DRIVER_CONFIG { 55 | Size: WDF_DRIVER_CONFIG_SIZE, 56 | EvtDriverDeviceAdd: Some(echo_evt_device_add), 57 | ..WDF_DRIVER_CONFIG::default() 58 | }; 59 | let driver_handle_output = WDF_NO_HANDLE.cast::(); 60 | 61 | let nt_status = unsafe { 62 | call_unsafe_wdf_function_binding!( 63 | WdfDriverCreate, 64 | driver as PDRIVER_OBJECT, 65 | registry_path, 66 | WDF_NO_OBJECT_ATTRIBUTES, 67 | &raw mut driver_config, 68 | driver_handle_output, 69 | ) 70 | }; 71 | 72 | if !nt_success(nt_status) { 73 | println!("Error: WdfDriverCreate failed {nt_status:#010X}"); 74 | return nt_status; 75 | } 76 | 77 | echo_print_driver_version(); 78 | 79 | nt_status 80 | } 81 | 82 | /// `EvtDeviceAdd` is called by the framework in response to `AddDevice` 83 | /// call from the `PnP` manager. We create and initialize a device object to 84 | /// represent a new instance of the device. 85 | /// 86 | /// # Arguments: 87 | /// 88 | /// * `_driver` - Handle to a framework driver object created in `DriverEntry` 89 | /// * `device_init` - Pointer to a framework-allocated `WDFDEVICE_INIT` 90 | /// structure. 91 | /// 92 | /// # Return value: 93 | /// 94 | /// * `NTSTATUS` 95 | #[link_section = "PAGE"] 96 | extern "C" fn echo_evt_device_add(_driver: WDFDRIVER, device_init: PWDFDEVICE_INIT) -> NTSTATUS { 97 | paged_code!(); 98 | 99 | println!("Enter EchoEvtDeviceAdd"); 100 | 101 | let device_init = 102 | // SAFETY: WDF should always be providing a pointer that is properly aligned, dereferencable per https://doc.rust-lang.org/std/ptr/index.html#safety, and initialized. For the lifetime of the resulting reference, the pointed-to memory is never accessed through any other pointer. 103 | unsafe { 104 | device_init 105 | .as_mut() 106 | .expect("WDF should never provide a null pointer for device_init") 107 | }; 108 | device::echo_device_create(device_init) 109 | } 110 | 111 | /// This routine shows how to retrieve framework version string and 112 | /// also how to find out to which version of framework library the 113 | /// client driver is bound to. 114 | /// 115 | /// # Arguments: 116 | /// 117 | /// # Return value: 118 | /// 119 | /// * `NTSTATUS` 120 | #[link_section = "INIT"] 121 | fn echo_print_driver_version() -> NTSTATUS { 122 | // 1) Retreive version string and print that in the debugger. 123 | // 124 | let mut string: WDFSTRING = core::ptr::null_mut(); 125 | let mut us: UNICODE_STRING = UNICODE_STRING::default(); 126 | let mut nt_status = unsafe { 127 | call_unsafe_wdf_function_binding!( 128 | WdfStringCreate, 129 | core::ptr::null_mut(), 130 | WDF_NO_OBJECT_ATTRIBUTES, 131 | &raw mut string 132 | ) 133 | }; 134 | if !nt_success(nt_status) { 135 | println!("Error: WdfStringCreate failed {nt_status:#010X}"); 136 | return nt_status; 137 | } 138 | 139 | let driver = unsafe { (*wdk_sys::WdfDriverGlobals).Driver }; 140 | nt_status = unsafe { 141 | call_unsafe_wdf_function_binding!(WdfDriverRetrieveVersionString, driver, string) 142 | }; 143 | if !nt_success(nt_status) { 144 | // No need to worry about delete the string object because 145 | // by default it's parented to the driver and it will be 146 | // deleted when the driverobject is deleted when the DriverEntry 147 | // returns a failure status. 148 | // 149 | println!("Error: WdfDriverRetrieveVersionString failed {nt_status:#010X}"); 150 | return nt_status; 151 | } 152 | 153 | unsafe { 154 | call_unsafe_wdf_function_binding!(WdfStringGetUnicodeString, string, &raw mut us); 155 | }; 156 | let driver_version = String::from_utf16_lossy(unsafe { 157 | slice::from_raw_parts( 158 | us.Buffer, 159 | us.Length as usize / core::mem::size_of_val(&(*us.Buffer)), 160 | ) 161 | }); 162 | println!("Echo Sample {driver_version}"); 163 | 164 | unsafe { 165 | call_unsafe_wdf_function_binding!(WdfObjectDelete, string as WDFOBJECT); 166 | }; 167 | 168 | // 2) Find out to which version of framework this driver is bound to. 169 | // 170 | let mut ver = WDF_DRIVER_VERSION_AVAILABLE_PARAMS { 171 | Size: WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE, 172 | MajorVersion: 1, 173 | MinorVersion: 0, 174 | }; 175 | 176 | if unsafe { 177 | call_unsafe_wdf_function_binding!(WdfDriverIsVersionAvailable, driver, &raw mut ver) 178 | } > 0 179 | { 180 | println!("Yes, framework version is 1.0"); 181 | } else { 182 | println!("No, framework version is not 1.0"); 183 | } 184 | 185 | STATUS_SUCCESS 186 | } 187 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust Driver Samples 2 | 3 | This is a Rust port of the driver samples from the original [Windows Driver Samples on Github.](https://github.com/microsoft/Windows-driver-samples) 4 | 5 | The repository provides examples and best practices for Windows driver development in Rust using crates from [windows-drivers-rs.](https://github.com/microsoft/windows-drivers-rs) 6 | 7 | ## Getting Started 8 | 9 | ### Pre-requisites 10 | 11 | #### Required 12 | 13 | * Set up [EWDK Build Environment](https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/using-the-enterprise-wdk) 14 | * Easy install option: 15 | * Install the latest version from link 16 | * 17 | * Expand the ISO image to c:\ewdk 18 | * Start Environment by running in command prompt: 19 | * ```c:\ewdk\LaunchBuildEnv.cmd``` 20 | * Install [Clang](https://clang.llvm.org/get_started.html) 21 | * Easy install option: 22 | * `winget install LLVM.LLVM` 23 | 24 | * Install [Rust](https://www.rust-lang.org/tools/install) 25 | * Easy install option for x64 systems: 26 | 27 | ```pwsh 28 | Invoke-RestMethod -Uri "https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe" -OutFile "$env:USERPROFILE\Downloads\rustup-init.exe" 29 | & "$env:USERPROFILE\Downloads\rustup-init.exe" -y 30 | ``` 31 | 32 | #### Rust Setup 33 | 34 | Run the following commands after setting up Rust. 35 | 36 | `cargo install cargo-make --no-default-features --features tls-native` 37 | 38 | __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)__ 39 | 40 | ##### Optional 41 | 42 | These are not-required, but may make it easier to work in a rust environment: 43 | 44 | `cargo install cargo-expand cargo-edit cargo-workspaces` 45 | 46 | ## Documentation 47 | 48 | `cargo doc --document-private-items --open` 49 | 50 | ## Build and Test 51 | 52 | ### Build 53 | 54 | From an EWDK development command prompt, run: 55 | 56 | `cargo make` 57 | 58 | If build is successful, this will stamp the INF and create a CAT file placed with driver binary and INF in `Package` folder. 59 | 60 | ### Install 61 | 62 | #### One Time PC Setup 63 | 64 | 1. If Bitlocker is enabled, suspend Bitlocker 65 | Example: `manage-bde -protectors -disable C:` 66 | 1. Turn off Secure Boot via your UEFI/BIOS Settings 67 | Example: `shutdown -r -o -t 0` then pick Advanced -> UEFI Settings 68 | 1. If Bitlocker is enabled, suspend Bitlocker again 69 | Example: `manage-bde -protectors -disable C:` 70 | 1. Turn on test signing 71 | `bcdedit /set testsigning on` 72 | 1. Reboot 73 | `shutdown -r -t 0` 74 | 75 | 1. Copy the following to the DUT (Device Under Test: the computer you want to test the driver on): 76 | 1. The driver `package` folder located in the [Cargo Output Directory](https://doc.rust-lang.org/cargo/guide/build-cache.html). The Cargo Output Directory changes based off of build profile, target architecture, etc. 77 | * Ex. `\target\x86_64-pc-windows-msvc\debug\package`, `\target\x86_64-pc-windows-msvc\release\package`, `\target\aarch64-pc-windows-msvc\debug\package`, `\target\aarch64-pc-windows-msvc\release\package`, 78 | `\target\debug\package`, 79 | `\target\release\package` 80 | 1. The version of `devgen.exe` from the WDK Developer Tools that matches the archtecture of your DUT 81 | * Ex. `C:\ewdk\Program Files\Windows Kits\10\Tools\10.0.22621.0\x64\devgen.exe` 82 | 1. Install the Certificate on the DUT: 83 | 1. Double click the certificate 84 | 1. Click Install Certificate 85 | 1. Store Location: Local Machine -> Next 86 | 1. Place all certificates in the following Store -> Browse -> Trusted Root Certification Authorities -> Ok -> Next 87 | 1. Repeat 2-4 for Store -> Browse -> Trusted Publishers -> Ok -> Next 88 | 1. Finish 89 | 1. Install the driver from Admin Command Prompt: 90 | 1. In the package directory, run: `pnputil.exe /add-driver echo_2.inf /install` 91 | 1. Create a software device from Admin Command Prompt: 92 | 1. In the directory that `devgen.exe` was copied to, run: `devgen.exe /add /hardwareid "root\ECHO_2"` 93 | 94 | ### Test 95 | 96 | * To capture prints: 97 | * Start [DebugView](https://learn.microsoft.com/en-us/sysinternals/downloads/debugview) 98 | 1. Enable `Capture Kernel` 99 | 2. Enable `Enable Verbose Kernel Output` 100 | * Alternatively, you can see prints in an active Windbg session. 101 | 1. Attach WinDBG 102 | 2. `ed nt!Kd_DEFAULT_Mask 0xFFFFFFFF` 103 | 104 | ### Usage 105 | 106 | The echo driver can be tested by using the [included sample app](./general/echo/kmdf/exe). 107 | 108 | * cargo run --bin echoapp 109 | * Send single write and read request synchronously 110 | 111 | * cargo run --bin echoapp -- -Async 112 | * Send 100 reads and writes asynchronously 113 | 114 | Exit the app anytime by pressing Ctrl-C 115 | 116 | ## Windows driver development 117 | 118 | ### Windows Driver Kit (WDK) 119 | 120 | Take a look at the compilation of the new and changed driver-related content for Windows 11. Areas of improvement include camera, print, display, Near Field Communication (NFC), WLAN, Bluetooth, and more. 121 | 122 | [Find out what's new in the WDK](https://docs.microsoft.com/windows-hardware/drivers/what-s-new-in-driver-development) 123 | 124 | ### Windows Driver Frameworks 125 | 126 | The Windows Driver Frameworks (WDF) are a set of libraries that make it simple to write high-quality device drivers. 127 | 128 | [WDF driver development guide](https://docs.microsoft.com/windows-hardware/drivers/wdf/) 129 | 130 | ### Samples 131 | 132 | Use the samples in this repo to guide your Windows driver development. Whether you're just getting started or porting an older driver to the newest version of Windows, code samples are valuable guides on how to write drivers. 133 | 134 | For information about important changes that need to be made to the WDK sample drivers before releasing device drivers based on the sample code, see the following topic: 135 | 136 | [From Sample Code to Production Driver - What to Change in the Samples](https://docs.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/from-sample-code-to-production-driver) 137 | 138 | ## Trademarks 139 | 140 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft 141 | trademarks or logos is subject to and must follow 142 | [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). 143 | Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. 144 | Any use of third-party trademarks or logos are subject to those third-party's policies. 145 | -------------------------------------------------------------------------------- /tools/dv/kmdf/fail_driver_pool_leak/src/driver.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | use wdk::{nt_success, paged_code, println}; 5 | use wdk_sys::{ 6 | call_unsafe_wdf_function_binding, 7 | ntddk::ExAllocatePool2, 8 | DRIVER_OBJECT, 9 | NTSTATUS, 10 | PCUNICODE_STRING, 11 | PDRIVER_OBJECT, 12 | POOL_FLAG_NON_PAGED, 13 | SIZE_T, 14 | ULONG, 15 | WDFDEVICE, 16 | WDFDEVICE_INIT, 17 | WDFDRIVER, 18 | WDF_DRIVER_CONFIG, 19 | WDF_NO_HANDLE, 20 | WDF_NO_OBJECT_ATTRIBUTES, 21 | WDF_OBJECT_ATTRIBUTES, 22 | _WDF_EXECUTION_LEVEL, 23 | _WDF_SYNCHRONIZATION_SCOPE, 24 | }; 25 | 26 | use crate::{GLOBAL_BUFFER, GUID_DEVINTERFACE}; 27 | 28 | /// `DriverEntry` initializes the driver and is the first routine called by the 29 | /// system after the driver is loaded. `DriverEntry` specifies the other entry 30 | /// points in the function driver, such as `EvtDevice` and `DriverUnload`. 31 | /// 32 | /// # Arguments 33 | /// 34 | /// * `driver` - represents the instance of the function driver that is loaded 35 | /// into memory. `DriverEntry` must initialize members of `DriverObject` 36 | /// before it returns to the caller. `DriverObject` is allocated by the system 37 | /// before the driver is loaded, and it is released by the system after the 38 | /// system unloads the function driver from memory. 39 | /// * `registry_path` - represents the driver specific path in the Registry. The 40 | /// function driver can use the path to store driver related data between 41 | /// reboots. The path does not store hardware instance specific data. 42 | /// 43 | /// # Return value: 44 | /// 45 | /// * `STATUS_SUCCESS` - if successful, 46 | /// * `STATUS_UNSUCCESSFUL` - otherwise. 47 | #[link_section = "INIT"] 48 | #[export_name = "DriverEntry"] 49 | extern "system" fn driver_entry( 50 | driver: &mut DRIVER_OBJECT, 51 | registry_path: PCUNICODE_STRING, 52 | ) -> NTSTATUS { 53 | println!("Enter: driver_entry"); 54 | 55 | let mut driver_config = { 56 | let wdf_driver_config_size: ULONG; 57 | 58 | // clippy::cast_possible_truncation cannot currently check compile-time constants: https://github.com/rust-lang/rust-clippy/issues/9613 59 | #[allow(clippy::cast_possible_truncation)] 60 | { 61 | const WDF_DRIVER_CONFIG_SIZE: usize = core::mem::size_of::(); 62 | 63 | // Manually assert there is not truncation since clippy doesn't work for 64 | // compile-time constants 65 | const { assert!(WDF_DRIVER_CONFIG_SIZE <= ULONG::MAX as usize) } 66 | 67 | wdf_driver_config_size = WDF_DRIVER_CONFIG_SIZE as ULONG; 68 | } 69 | 70 | WDF_DRIVER_CONFIG { 71 | Size: wdf_driver_config_size, 72 | EvtDriverDeviceAdd: Some(evt_driver_device_add), 73 | EvtDriverUnload: Some(evt_driver_unload), 74 | ..WDF_DRIVER_CONFIG::default() 75 | } 76 | }; 77 | 78 | let driver_handle_output = WDF_NO_HANDLE.cast::(); 79 | 80 | let nt_status = unsafe { 81 | call_unsafe_wdf_function_binding!( 82 | WdfDriverCreate, 83 | driver as PDRIVER_OBJECT, 84 | registry_path, 85 | WDF_NO_OBJECT_ATTRIBUTES, 86 | &raw mut driver_config, 87 | driver_handle_output, 88 | ) 89 | }; 90 | 91 | if !nt_success(nt_status) { 92 | println!("Error: WdfDriverCreate failed {nt_status:#010X}"); 93 | return nt_status; 94 | } 95 | 96 | println!("Exit: driver_entry"); 97 | 98 | nt_status 99 | } 100 | 101 | /// `EvtDeviceAdd` is called by the framework in response to `AddDevice` 102 | /// call from the `PnP` manager. We create and initialize a device object to 103 | /// represent a new instance of the device. 104 | /// 105 | /// # Arguments: 106 | /// 107 | /// * `_driver` - Handle to a framework driver object created in `DriverEntry` 108 | /// * `device_init` - Pointer to a framework-allocated `WDFDEVICE_INIT` 109 | /// structure. 110 | /// 111 | /// # Return value: 112 | /// 113 | /// * `NTSTATUS` 114 | #[link_section = "PAGE"] 115 | extern "C" fn evt_driver_device_add( 116 | _driver: WDFDRIVER, 117 | mut device_init: *mut WDFDEVICE_INIT, 118 | ) -> NTSTATUS { 119 | paged_code!(); 120 | 121 | println!("Enter: evt_driver_device_add"); 122 | 123 | #[allow(clippy::cast_possible_truncation)] 124 | let mut attributes = WDF_OBJECT_ATTRIBUTES { 125 | Size: core::mem::size_of::() as ULONG, 126 | ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent, 127 | SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent, 128 | ..WDF_OBJECT_ATTRIBUTES::default() 129 | }; 130 | 131 | let mut device = WDF_NO_HANDLE as WDFDEVICE; 132 | let mut nt_status = unsafe { 133 | call_unsafe_wdf_function_binding!( 134 | WdfDeviceCreate, 135 | &raw mut device_init, 136 | &raw mut attributes, 137 | &raw mut device, 138 | ) 139 | }; 140 | 141 | if !nt_success(nt_status) { 142 | println!("Error: WdfDeviceCreate failed {nt_status:#010X}"); 143 | return nt_status; 144 | } 145 | 146 | // Allocate non-paged memory pool of 64 bytes (arbitrarily chosen) for the 147 | // Global buffer. This pool of memory is intentionally not freed by 148 | // the driver. 149 | unsafe { 150 | const LENGTH: usize = 64; 151 | GLOBAL_BUFFER = ExAllocatePool2(POOL_FLAG_NON_PAGED, LENGTH as SIZE_T, 's' as u32); 152 | } 153 | 154 | nt_status = unsafe { 155 | call_unsafe_wdf_function_binding!( 156 | WdfDeviceCreateDeviceInterface, 157 | device, 158 | &GUID_DEVINTERFACE, 159 | core::ptr::null_mut(), 160 | ) 161 | }; 162 | 163 | if !nt_success(nt_status) { 164 | println!("Error: WdfDeviceCreateDeviceInterface failed {nt_status:#010X}"); 165 | return nt_status; 166 | } 167 | 168 | println!("Exit: evt_driver_device_add"); 169 | 170 | nt_status 171 | } 172 | 173 | /// This event callback function is called before the driver is unloaded 174 | /// 175 | /// The EvtDriverUnload callback function must deallocate any 176 | /// non-device-specific system resources that the driver's DriverEntry routine 177 | /// allocated. 178 | /// 179 | /// # Argument: 180 | /// 181 | /// * `driver` - Handle to the framework driver object 182 | /// 183 | /// # Return Value: 184 | /// 185 | /// None 186 | extern "C" fn evt_driver_unload(_driver: WDFDRIVER) { 187 | println!("Enter: evt_driver_unload"); 188 | 189 | // Ideally, the memory allocated to the Global buffer in lib.rs L51 should 190 | // be freed here by calling the ExFreePool API. But to demonstrate the Driver 191 | // Verifier's ability to catch pool leaks, the buffer is deliberately not freed. 192 | 193 | // unsafe { wdk_sys::ntddk::ExFreePool(GLOBAL_BUFFER) }; 194 | 195 | println!("Exit: evt_driver_unload"); 196 | } 197 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | //! # Abstract 5 | //! 6 | //! This driver demonstrates use of a default I/O Queue, its 7 | //! request start events, cancellation event, and a synchronized DPC. 8 | //! 9 | //! To demonstrate asynchronous operation, the I/O requests are not completed 10 | //! immediately, but stored in the drivers private data structure, and a 11 | //! timer DPC will complete it next time the DPC runs. 12 | //! 13 | //! During the time the request is waiting for the DPC to run, it is 14 | //! made cancellable by the call `WdfRequestMarkCancelable`. This 15 | //! allows the test program to cancel the request and exit instantly. 16 | //! 17 | //! This rather complicated set of events is designed to demonstrate 18 | //! the driver frameworks synchronization of access to a device driver 19 | //! data structure, and a pointer which can be a proxy for device hardware 20 | //! registers or resources. 21 | //! 22 | //! This common data structure, or resource is accessed by new request 23 | //! events arriving, the DPC that completes it, and cancel processing. 24 | //! 25 | //! Notice the lack of specific lock/unlock operations. 26 | //! 27 | //! Even though this example utilizes a serial queue, a parallel queue 28 | //! would not need any additional explicit synchronization, just a 29 | //! strategy for managing multiple requests outstanding. 30 | 31 | #![no_std] 32 | #![deny(clippy::all)] 33 | #![warn(clippy::pedantic)] 34 | #![warn(clippy::nursery)] 35 | #![warn(clippy::cargo)] 36 | #![allow(clippy::missing_safety_doc)] 37 | 38 | mod device; 39 | mod driver; 40 | mod queue; 41 | 42 | #[cfg(not(test))] 43 | extern crate wdk_panic; 44 | 45 | use wdk::wdf; 46 | #[cfg(not(test))] 47 | use wdk_alloc::WdkAllocator; 48 | use wdk_sys::{ 49 | call_unsafe_wdf_function_binding, 50 | GUID, 51 | NTSTATUS, 52 | PVOID, 53 | ULONG, 54 | WDFOBJECT, 55 | WDFREQUEST, 56 | WDF_DRIVER_CONFIG, 57 | WDF_DRIVER_VERSION_AVAILABLE_PARAMS, 58 | WDF_IO_QUEUE_CONFIG, 59 | WDF_OBJECT_ATTRIBUTES, 60 | WDF_OBJECT_CONTEXT_TYPE_INFO, 61 | WDF_PNPPOWER_EVENT_CALLBACKS, 62 | WDF_TIMER_CONFIG, 63 | }; 64 | mod wdf_object_context; 65 | use core::sync::atomic::AtomicI32; 66 | 67 | use wdf_object_context::{wdf_declare_context_type, wdf_declare_context_type_with_name}; 68 | 69 | #[cfg(not(test))] 70 | #[global_allocator] 71 | static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; 72 | 73 | // {CDC35B6E-0BE4-4936-BF5F-5537380A7C1A} 74 | const GUID_DEVINTERFACE_ECHO: GUID = GUID { 75 | Data1: 0xCDC3_5B6Eu32, 76 | Data2: 0x0BE4u16, 77 | Data3: 0x4936u16, 78 | Data4: [ 79 | 0xBFu8, 0x5Fu8, 0x55u8, 0x37u8, 0x38u8, 0x0Au8, 0x7Cu8, 0x1Au8, 80 | ], 81 | }; 82 | 83 | // Declare queue context. 84 | // 85 | // ====== CONTEXT SETUP ========// 86 | 87 | // The device context performs the same job as 88 | // a WDM device extension in the driver frameworks 89 | pub struct DeviceContext { 90 | private_device_data: ULONG, // just a placeholder 91 | } 92 | wdf_declare_context_type!(DeviceContext); 93 | 94 | pub struct QueueContext { 95 | buffer: PVOID, 96 | length: usize, 97 | timer: wdf::Timer, 98 | current_request: WDFREQUEST, 99 | current_status: NTSTATUS, 100 | spin_lock: wdf::SpinLock, 101 | } 102 | wdf_declare_context_type_with_name!(QueueContext, queue_get_context); 103 | 104 | pub struct RequestContext { 105 | cancel_completion_ownership_count: AtomicI32, 106 | } 107 | wdf_declare_context_type_with_name!(RequestContext, request_get_context); 108 | 109 | // None of the below SIZE constants should be needed after an equivalent `WDF_STRUCTURE_SIZE` macro is added to `wdk-sys`: https://github.com/microsoft/windows-drivers-rs/issues/242 110 | 111 | #[allow( 112 | clippy::cast_possible_truncation, 113 | reason = "size_of::() is known to fit in ULONG due to below const assert" 114 | )] 115 | const WDF_DRIVER_CONFIG_SIZE: ULONG = { 116 | const S: usize = core::mem::size_of::(); 117 | const { 118 | assert!( 119 | S <= ULONG::MAX as usize, 120 | "size_of::() should fit in ULONG" 121 | ); 122 | }; 123 | S as ULONG 124 | }; 125 | 126 | #[allow( 127 | clippy::cast_possible_truncation, 128 | reason = "size_of::() is known to fit in ULONG due to \ 129 | below const assert" 130 | )] 131 | const WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE: ULONG = { 132 | const S: usize = core::mem::size_of::(); 133 | const { 134 | assert!( 135 | S <= ULONG::MAX as usize, 136 | "size_of::() should fit in ULONG" 137 | ); 138 | }; 139 | S as ULONG 140 | }; 141 | 142 | #[allow( 143 | clippy::cast_possible_truncation, 144 | reason = "size_of::() is known to fit in ULONG due to below const assert" 145 | )] 146 | const WDF_IO_QUEUE_CONFIG_SIZE: ULONG = { 147 | const S: usize = core::mem::size_of::(); 148 | const { 149 | assert!( 150 | S <= ULONG::MAX as usize, 151 | "size_of::() should fit in ULONG" 152 | ); 153 | }; 154 | S as ULONG 155 | }; 156 | 157 | #[allow( 158 | clippy::cast_possible_truncation, 159 | reason = "size_of::() is known to fit in ULONG due to below const \ 160 | assert" 161 | )] 162 | const WDF_OBJECT_ATTRIBUTES_SIZE: ULONG = { 163 | const S: usize = core::mem::size_of::(); 164 | const { 165 | assert!( 166 | S <= ULONG::MAX as usize, 167 | "size_of::() should fit in ULONG" 168 | ); 169 | }; 170 | S as ULONG 171 | }; 172 | 173 | #[allow( 174 | clippy::cast_possible_truncation, 175 | reason = "size_of::() is known to fit in ULONG due to below \ 176 | const assert" 177 | )] 178 | const WDF_OBJECT_CONTEXT_TYPE_INFO_SIZE: ULONG = { 179 | const S: usize = core::mem::size_of::(); 180 | const { 181 | assert!( 182 | S <= ULONG::MAX as usize, 183 | "size_of::() should fit in ULONG" 184 | ); 185 | }; 186 | S as ULONG 187 | }; 188 | 189 | #[allow( 190 | clippy::cast_possible_truncation, 191 | reason = "size_of::() is known to fit in ULONG due to below \ 192 | const assert" 193 | )] 194 | const WDF_PNPPOWER_EVENT_CALLBACKS_SIZE: ULONG = { 195 | const S: usize = core::mem::size_of::(); 196 | const { 197 | assert!( 198 | S <= ULONG::MAX as usize, 199 | "size_of::() should fit in ULONG" 200 | ); 201 | }; 202 | S as ULONG 203 | }; 204 | 205 | #[allow( 206 | clippy::cast_possible_truncation, 207 | reason = "size_of::() is known to fit in ULONG due to below const assert" 208 | )] 209 | const WDF_TIMER_CONFIG_SIZE: ULONG = { 210 | const S: usize = core::mem::size_of::(); 211 | const { 212 | assert!( 213 | S <= ULONG::MAX as usize, 214 | "size_of::() should fit in ULONG" 215 | ); 216 | }; 217 | S as ULONG 218 | }; 219 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to windows-drivers-rs 2 | 3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 5 | the rights to use your contribution. For details, visit . 6 | 7 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 8 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 9 | provided by the bot. You will only need to do this once across all repos using our CLA. 10 | 11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 14 | 15 | * [Code of Conduct](#coc) 16 | * [Issues and Bugs](#issue) 17 | * [Feature Requests](#feature) 18 | * [Submission Guidelines](#submit) 19 | * [Getting Started with windows-drivers-rs Development](#development) 20 | 21 | ## Code of Conduct 22 | 23 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 24 | 25 | ## Found an Issue? 26 | 27 | If you find a bug in the source code or a mistake in the documentation, you can help us by 28 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can 29 | [submit a Pull Request](#submit-pr) with a fix. 30 | 31 | ## Want a Feature? 32 | 33 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub 34 | Repository. If you would like to *implement* a new feature, please submit an issue with 35 | a proposal for your work first, to be sure that we can use it. 36 | 37 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr). 38 | 39 | ## Submission Guidelines 40 | 41 | ### Submitting an Issue 42 | 43 | Before you submit an issue, search the archive, maybe your question was already answered. 44 | 45 | If your issue appears to be a bug, and hasn't been reported, open a new issue. 46 | Help us to maximize the effort we can spend fixing issues and adding new 47 | features, by not reporting duplicate issues. Providing the following information will increase the 48 | chances of your issue being dealt with quickly: 49 | 50 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps 51 | * **Version** - what version is affected (e.g. 0.1.2) 52 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you 53 | * **Browsers and Operating System** - is this a problem with all browsers? 54 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps 55 | * **Related Issues** - has a similar issue been reported before? 56 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be 57 | causing the problem (line of code or commit) 58 | 59 | You can file new issues by providing the above information at the corresponding repository's issues link: ]. 60 | 61 | ### Submitting a Pull Request (PR) 62 | 63 | Before you submit your Pull Request (PR) consider the following guidelines: 64 | 65 | * Search the repository () for an open or closed PR 66 | that relates to your submission. You don't want to duplicate effort. 67 | 68 | * Make your changes in a new git fork: 69 | 70 | * Commit your changes using a descriptive commit message 71 | * Push your fork to GitHub: 72 | * In GitHub, create a pull request 73 | * If we suggest changes then: 74 | * Make the required updates. 75 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request): 76 | 77 | ```shell 78 | git rebase master -i 79 | git push -f 80 | ``` 81 | 82 | That's it! Thank you for your contribution! 83 | 84 | ## Getting Started with windows-drivers-rs Development 85 | 86 | ### Development Requirements 87 | 88 | The following tools should be installed as a part of the `windows-drivers-rs` developer workflow: 89 | 90 | * `cargo-expand`: `cargo install --locked cargo-expand` 91 | * `cargo-audit`: `cargo install --locked cargo-audit` 92 | * `cargo-udeps`: `cargo install --locked cargo-udeps` 93 | * `taplo-cli`: `cargo install --locked taplo-cli` 94 | 95 | **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) 96 | 97 | ### Generating Documentation 98 | 99 | * To compile and open documentation: `cargo doc --locked --open` 100 | * To include nightly features: `cargo +nightly doc --locked --open --features nightly` 101 | 102 | ### Policy on using Nightly/Unstable Features 103 | 104 | #### In `lib` and `bin` targets 105 | 106 | The crates in this repository are designed to work with `stable` rust. Some of the crates expose a `nightly` feature that adds additional functionality that requires unstable rust features in the `nightly` toolchains. 107 | 108 | #### In `test` targets and unit tests 109 | 110 | `test` targets and unit tests in other targets will automatically enable nightly features when a nightly toolchain is detected. This is done via the `nightly_toolchain` `cfg` value. This allows us to take advantage of unstable features (ex. [`assert_matches`](https://doc.rust-lang.org/std/assert_matches/macro.assert_matches.html)) in tests. 111 | 112 | ### Build and Test 113 | 114 | To **only build** the workspace: `cargo build` 115 | 116 | To **both** build and package the samples in the workspace: `cargo make --cwd .\crates\` 117 | 118 | ### Quality 119 | 120 | To maintain the quality of code, tests and tools are required to pass before contributions are accepted. This is a suggested list of things that should be run before contributions will be accepted: 121 | 122 | **_Functional Correctness:_** 123 | 124 | * `cargo test --locked --workspace --exclude sample-*` 125 | * To test `nightly` features: `cargo +nightly test --locked --workspace --exclude sample-* --features nightly` 126 | 127 | **_Static Analysis and Linting:_** 128 | 129 | * `cargo clippy --locked --all-targets -- -D warnings` 130 | * To lint `nightly` features: `cargo +nightly clippy --locked --all-targets --features nightly -- -D warnings` 131 | 132 | **_Formatting:_** 133 | 134 | * Check for consistent `.rs` file formatting: `cargo +nightly fmt --all -- --check` 135 | * Running `cargo +nightly fmt --all` resolves these formatting inconsistencies usually 136 | * `+nightly` is required to use some `nightly` configuration features in [the `rustfmt.toml` config](./rustfmt.toml) 137 | * Check for consistent `.toml` file formatting: `taplo fmt --check --diff` 138 | * Running `taplo fmt` resolves these formatting inconsistencies usually 139 | 140 | **_Dependency Analysis:_** 141 | 142 | * Scan for security advisories in dependent crates: `cargo audit --deny warnings` 143 | * Scan for unused dependencies: `cargo +nightly udeps --locked --all-targets` 144 | * `cargo udeps` requires `nightly` to function 145 | 146 | **_Rust Documentation Build Test_** 147 | 148 | * `cargo doc --locked` 149 | * To build docs for `nightly` features: `cargo +nightly doc --locked --features nightly` 150 | 151 | ### A Note on Code-Style 152 | 153 | Any bindings generated to C code maintains their original names, including their original style conventions(ex. PascalCase for functions). These bindings should all reside in `wdk-sys` and are marked as `unsafe` since all ffi is inherently `unsafe`. `wdk-sys` also retains manual implementations of wdk code (ex. because `bindgen` fails to resolve some macros). These should also maintain their original names and style. 154 | 155 | Any Rust wrappers written around the bindings should follow [Rust style and naming conventions](https://rust-lang.github.io/api-guidelines/naming.html) per RFC-430. Any wrappers around the FFI bindings should also be written to guarantee safety. Refer to [this](https://doc.rust-lang.org/nomicon/ffi.html#creating-a-safe-interface) for more information on writing safe rust wrappers to ffi code. 156 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/src/device.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | use wdk::{nt_success, paged_code, println}; 5 | use wdk_sys::{ 6 | call_unsafe_wdf_function_binding, 7 | NTSTATUS, 8 | STATUS_SUCCESS, 9 | WDFDEVICE, 10 | WDFDEVICE_INIT, 11 | WDFOBJECT, 12 | WDFQUEUE, 13 | WDF_NO_HANDLE, 14 | WDF_OBJECT_ATTRIBUTES, 15 | WDF_PNPPOWER_EVENT_CALLBACKS, 16 | _WDF_EXECUTION_LEVEL, 17 | _WDF_SYNCHRONIZATION_SCOPE, 18 | }; 19 | 20 | use crate::{ 21 | queue::echo_queue_initialize, 22 | queue_get_context, 23 | wdf_object_context::wdf_get_context_type_info, 24 | wdf_object_get_device_context, 25 | DeviceContext, 26 | GUID_DEVINTERFACE_ECHO, 27 | WDF_DEVICE_CONTEXT_TYPE_INFO, 28 | WDF_OBJECT_ATTRIBUTES_SIZE, 29 | WDF_PNPPOWER_EVENT_CALLBACKS_SIZE, 30 | WDF_REQUEST_CONTEXT_TYPE_INFO, 31 | }; 32 | 33 | /// Worker routine called to create a device and its software resources. 34 | /// 35 | /// # Arguments: 36 | /// 37 | /// * `device_init` - Pointer to an opaque init structure. Memory for this 38 | /// structure will be freed by the framework when the `WdfDeviceCreate` 39 | /// succeeds. So don't access the structure after that point. 40 | /// 41 | /// # Return value: 42 | /// 43 | /// * `NTSTATUS` 44 | #[link_section = "PAGE"] 45 | pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS { 46 | paged_code!(); 47 | 48 | // Register pnp/power callbacks so that we can start and stop the timer as the 49 | // device gets started and stopped. 50 | let mut pnp_power_callbacks = WDF_PNPPOWER_EVENT_CALLBACKS { 51 | Size: WDF_PNPPOWER_EVENT_CALLBACKS_SIZE, 52 | EvtDeviceSelfManagedIoInit: Some(echo_evt_device_self_managed_io_start), 53 | EvtDeviceSelfManagedIoSuspend: Some(echo_evt_device_self_managed_io_suspend), 54 | // Function used for both Init and Restart Callbacks 55 | EvtDeviceSelfManagedIoRestart: Some(echo_evt_device_self_managed_io_start), 56 | ..WDF_PNPPOWER_EVENT_CALLBACKS::default() 57 | }; 58 | 59 | // Register the PnP and power callbacks. Power policy related callbacks will be 60 | // registered later in SotwareInit. 61 | unsafe { 62 | call_unsafe_wdf_function_binding!( 63 | WdfDeviceInitSetPnpPowerEventCallbacks, 64 | device_init, 65 | &raw mut pnp_power_callbacks 66 | ); 67 | }; 68 | 69 | let mut attributes = WDF_OBJECT_ATTRIBUTES { 70 | Size: WDF_OBJECT_ATTRIBUTES_SIZE, 71 | ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent, 72 | SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent, 73 | ContextTypeInfo: wdf_get_context_type_info!(RequestContext), 74 | ..WDF_OBJECT_ATTRIBUTES::default() 75 | }; 76 | 77 | unsafe { 78 | call_unsafe_wdf_function_binding!( 79 | WdfDeviceInitSetRequestAttributes, 80 | device_init, 81 | &raw mut attributes 82 | ); 83 | }; 84 | 85 | let mut attributes = WDF_OBJECT_ATTRIBUTES { 86 | Size: WDF_OBJECT_ATTRIBUTES_SIZE, 87 | ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent, 88 | SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent, 89 | ContextTypeInfo: wdf_get_context_type_info!(DeviceContext), 90 | ..WDF_OBJECT_ATTRIBUTES::default() 91 | }; 92 | 93 | let mut device = WDF_NO_HANDLE as WDFDEVICE; 94 | let mut nt_status = unsafe { 95 | call_unsafe_wdf_function_binding!( 96 | WdfDeviceCreate, 97 | (core::ptr::addr_of_mut!(device_init)).cast(), 98 | &raw mut attributes, 99 | &raw mut device, 100 | ) 101 | }; 102 | 103 | if nt_success(nt_status) { 104 | // Get the device context and initialize it. WdfObjectGet_DEVICE_CONTEXT is an 105 | // inline function generated by WDF_DECLARE_CONTEXT_TYPE macro in the 106 | // device.h header file. This function will do the type checking and return 107 | // the device context. If you pass a wrong object handle 108 | // it will return NULL and assert if run under framework verifier mode. 109 | let device_context: *mut DeviceContext = 110 | unsafe { wdf_object_get_device_context(device as WDFOBJECT) }; 111 | unsafe { (*device_context).private_device_data = 0 }; 112 | 113 | // Create a device interface so that application can find and talk 114 | // to us. 115 | nt_status = unsafe { 116 | call_unsafe_wdf_function_binding!( 117 | WdfDeviceCreateDeviceInterface, 118 | device, 119 | &GUID_DEVINTERFACE_ECHO, 120 | core::ptr::null_mut(), 121 | ) 122 | }; 123 | 124 | if nt_success(nt_status) { 125 | // Initialize the I/O Package and any Queues 126 | nt_status = unsafe { echo_queue_initialize(device) }; 127 | } 128 | } 129 | nt_status 130 | } 131 | 132 | /// This event is called by the Framework when the device is started 133 | /// or restarted after a suspend operation. 134 | /// 135 | /// This function is not marked pageable because this function is in the 136 | /// device power up path. When a function is marked pagable and the code 137 | /// section is paged out, it will generate a page fault which could impact 138 | /// the fast resume behavior because the client driver will have to wait 139 | /// until the system drivers can service this page fault. 140 | /// 141 | /// # Arguments: 142 | /// 143 | /// * `device` - Handle to a framework device object. 144 | /// 145 | /// # Return value: 146 | /// 147 | /// * `NTSTATUS` - Failures will result in the device stack being torn down. 148 | extern "C" fn echo_evt_device_self_managed_io_start(device: WDFDEVICE) -> NTSTATUS { 149 | // Restart the queue and the periodic timer. We stopped them before going 150 | // into low power state. 151 | let queue: WDFQUEUE; 152 | 153 | println!("--> EchoEvtDeviceSelfManagedIoInit"); 154 | 155 | unsafe { 156 | queue = call_unsafe_wdf_function_binding!(WdfDeviceGetDefaultQueue, device); 157 | }; 158 | 159 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 160 | 161 | // Restart the queue and the periodic timer. We stopped them before going 162 | // into low power state. 163 | unsafe { call_unsafe_wdf_function_binding!(WdfIoQueueStart, queue) }; 164 | 165 | let due_time: i64 = -(100) * (10000); 166 | 167 | let _ = unsafe { (*queue_context).timer.start(due_time) }; 168 | 169 | println!("<-- EchoEvtDeviceSelfManagedIoInit"); 170 | 171 | STATUS_SUCCESS 172 | } 173 | 174 | /// This event is called by the Framework when the device is stopped 175 | /// for resource rebalance or suspended when the system is entering 176 | /// Sx state. 177 | /// 178 | /// # Arguments: 179 | /// 180 | /// * `device` - Handle to a framework device object. 181 | /// 182 | /// # Return value: 183 | /// 184 | /// * `NTSTATUS` - The driver is not allowed to fail this function. If it does, 185 | /// the device stack will be torn down. 186 | #[link_section = "PAGE"] 187 | unsafe extern "C" fn echo_evt_device_self_managed_io_suspend(device: WDFDEVICE) -> NTSTATUS { 188 | paged_code!(); 189 | 190 | println!("--> EchoEvtDeviceSelfManagedIoSuspend"); 191 | 192 | // Before we stop the timer we should make sure there are no outstanding 193 | // i/o. We need to do that because framework cannot suspend the device 194 | // if there are requests owned by the driver. There are two ways to solve 195 | // this issue: 1) We can wait for the outstanding I/O to be complete by the 196 | // periodic timer 2) Register EvtIoStop callback on the queue and acknowledge 197 | // the request to inform the framework that it's okay to suspend the device 198 | // with outstanding I/O. In this sample we will use the 1st approach 199 | // because it's pretty easy to do. We will restart the queue when the 200 | // device is restarted. 201 | let queue = unsafe { call_unsafe_wdf_function_binding!(WdfDeviceGetDefaultQueue, device) }; 202 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 203 | 204 | unsafe { 205 | call_unsafe_wdf_function_binding!(WdfIoQueueStopSynchronously, queue); 206 | // Stop the watchdog timer and wait for DPC to run to completion if it's already 207 | // fired. 208 | let _ = (*queue_context).timer.stop(true); 209 | }; 210 | 211 | println!("<-- EchoEvtDeviceSelfManagedIoSuspend"); 212 | 213 | STATUS_SUCCESS 214 | } 215 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /general/echo/kmdf/exe/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // License: MIT OR Apache-2.0 3 | 4 | //! The below implementation is a bit of a compromise in trying to help new devs 5 | //! find a 1 to 1 mapping to the original C sample app code versus a full proper 6 | //! Rust implementation 7 | 8 | #![deny(missing_docs)] 9 | #![deny(unsafe_op_in_unsafe_fn)] 10 | #![deny(clippy::all)] 11 | #![deny(clippy::pedantic)] 12 | #![deny(clippy::nursery)] 13 | #![deny(clippy::cargo)] 14 | #![deny(clippy::multiple_unsafe_ops_per_block)] 15 | #![deny(clippy::undocumented_unsafe_blocks)] 16 | #![deny(clippy::unnecessary_safety_doc)] 17 | #![deny(rustdoc::broken_intra_doc_links)] 18 | #![deny(rustdoc::private_intra_doc_links)] 19 | #![deny(rustdoc::missing_crate_level_docs)] 20 | #![deny(rustdoc::invalid_codeblock_attributes)] 21 | #![deny(rustdoc::invalid_html_tags)] 22 | #![deny(rustdoc::invalid_rust_codeblocks)] 23 | #![deny(rustdoc::bare_urls)] 24 | #![deny(rustdoc::unescaped_backticks)] 25 | #![deny(rustdoc::redundant_explicit_links)] 26 | 27 | use std::{env, error::Error, ffi::OsString, os::windows::prelude::*, sync::RwLock, thread}; 28 | 29 | use once_cell::sync::Lazy; 30 | use uuid::{uuid, Uuid}; 31 | use windows_sys::Win32::{ 32 | Devices::DeviceAndDriverInstallation, 33 | Foundation::{ 34 | CloseHandle, 35 | GetLastError, 36 | BOOL, 37 | ERROR_IO_PENDING, 38 | FALSE, 39 | HANDLE, 40 | INVALID_HANDLE_VALUE, 41 | }, 42 | Storage::FileSystem::{ 43 | CreateFileW, 44 | ReadFile, 45 | WriteFile, 46 | FILE_FLAG_OVERLAPPED, 47 | FILE_GENERIC_READ, 48 | FILE_GENERIC_WRITE, 49 | FILE_SHARE_READ, 50 | FILE_SHARE_WRITE, 51 | OPEN_EXISTING, 52 | }, 53 | System::{ 54 | Threading::INFINITE, 55 | IO::{CreateIoCompletionPort, GetQueuedCompletionStatus, OVERLAPPED, OVERLAPPED_0}, 56 | }, 57 | }; 58 | 59 | #[derive(Default, Debug)] 60 | struct Globals { 61 | perform_async_io: bool, 62 | limited_loops: bool, 63 | async_io_loops_num: usize, 64 | device_path: String, 65 | } 66 | 67 | static GLOBAL_DATA: Lazy> = Lazy::new(|| RwLock::new(Globals::default())); 68 | static GUID_DEVINTERFACE_ECHO: Uuid = uuid!("CDC35B6E-0BE4-4936-BF5F-5537380A7C1A"); 69 | static READER_TYPE: u32 = 1; 70 | static WRITER_TYPE: u32 = 2; 71 | static NUM_ASYNCH_IO: usize = 100; 72 | static BUFFER_SIZE: usize = 40 * 1024; 73 | 74 | fn main() -> Result<(), Box> { 75 | let argument_vector: Vec = env::args().collect(); 76 | let argument_count = argument_vector.len(); 77 | 78 | if argument_count > 1 { 79 | if argument_vector[1] == "-Async" { 80 | let mut globals = GLOBAL_DATA.write()?; 81 | globals.perform_async_io = true; 82 | if argument_count > 2 { 83 | globals.async_io_loops_num = argument_vector[2].parse::()?; 84 | globals.limited_loops = true; 85 | } else { 86 | globals.limited_loops = false; 87 | } 88 | } else { 89 | eprintln!( 90 | r" 91 | Usage: 92 | Echoapp.exe --- Send single write and read request synchronously 93 | Echoapp.exe -Async --- Send reads and writes asynchronously without terminating 94 | Echoapp.exe -Async --- Send reads and writes asynchronously 95 | Exit the app anytime by pressing Ctrl-C 96 | " 97 | ); 98 | return Err("Invalid Args".into()); 99 | } 100 | } 101 | 102 | get_device_path(&GUID_DEVINTERFACE_ECHO)?; 103 | 104 | let globals = GLOBAL_DATA.read()?; 105 | println!("DevicePath: {}", globals.device_path); 106 | let mut path_vec = globals.device_path.encode_utf16().collect::>(); 107 | let perform_async_io = globals.perform_async_io; 108 | drop(globals); 109 | 110 | let h_device: HANDLE; 111 | path_vec.push(0); 112 | let path = path_vec.as_ptr(); 113 | 114 | // SAFETY: 115 | // Call Win32 API FFI CreateFileW to access driver 116 | unsafe { 117 | h_device = CreateFileW( 118 | path, 119 | FILE_GENERIC_READ | FILE_GENERIC_WRITE, 120 | FILE_SHARE_READ | FILE_SHARE_WRITE, 121 | std::ptr::null(), 122 | OPEN_EXISTING, 123 | 0, 124 | std::ptr::null_mut(), 125 | ); 126 | } 127 | 128 | if h_device == INVALID_HANDLE_VALUE { 129 | return Err(format!( 130 | "Failed to open device. Error {}", 131 | // SAFETY: 132 | // - FFI contract: Called immediately after CreateFileW failure before any intervening 133 | // Win32/CRT calls that would overwrite thread-local error slot 134 | // - Concurrency: Reads thread-local storage only (no data races) 135 | // - Memory safety: Returns u32 value (no pointer dereferences) 136 | unsafe { GetLastError() } 137 | ) 138 | .into()); 139 | } 140 | 141 | println!("Opened device successfully"); 142 | 143 | if perform_async_io { 144 | println!("Starting AsyncIo"); 145 | 146 | let h = 147 | thread::spawn(|| -> Result<(), Box> { async_io(READER_TYPE) }); 148 | 149 | // Because async_io error requires Send + Sync but this function does not, 150 | // cannot use ? operator 151 | #[allow(clippy::question_mark)] 152 | if let Err(e) = async_io(WRITER_TYPE) { 153 | return Err(e); 154 | } 155 | 156 | h.join().unwrap().unwrap(); 157 | } else { 158 | perform_write_read_test(h_device, 512)?; 159 | 160 | perform_write_read_test(h_device, 30 * 1024)?; 161 | } 162 | 163 | Ok(()) 164 | } 165 | 166 | fn create_pattern_buffer(length: u32) -> Vec { 167 | let mut buf = Vec::::with_capacity(usize::try_from(length).unwrap()); 168 | let mut val: u8 = 0; 169 | 170 | for _ in 0..length { 171 | buf.push(val); 172 | val = val.wrapping_add(1); 173 | } 174 | 175 | buf 176 | } 177 | 178 | fn verify_pattern_buffer(buf: &[u8]) -> Result<(), Box> { 179 | let mut check_value: u8 = 0; 180 | for val in buf { 181 | if *val != check_value { 182 | return Err(format!( 183 | "Pattern changed. SB 0x{:02X}, Is 0x{:02X}", 184 | check_value, *val 185 | ) 186 | .into()); 187 | } 188 | check_value = check_value.wrapping_add(1); 189 | } 190 | Ok(()) 191 | } 192 | 193 | fn perform_write_read_test(h_device: HANDLE, test_length: u32) -> Result<(), Box> { 194 | let write_buffer = create_pattern_buffer(test_length); 195 | let mut read_buffer: Vec = vec![0; usize::try_from(test_length).unwrap()]; 196 | 197 | let mut r: BOOL; 198 | let mut bytes_returned: u32 = 0; 199 | 200 | // SAFETY: 201 | // Call Win32 API FFI WriteFile to write buffer to the driver 202 | unsafe { 203 | r = WriteFile( 204 | h_device, 205 | write_buffer.as_ptr().cast(), 206 | u32::try_from(write_buffer.len()).unwrap(), 207 | &mut bytes_returned, 208 | std::ptr::null_mut(), 209 | ); 210 | } 211 | 212 | if r == FALSE { 213 | return Err(format!( 214 | "PerformWriteReadTest: WriteFile failed: Error {}", 215 | // SAFETY: 216 | // - FFI contract: Called immediately after WriteFile failure before any intervening 217 | // Win32/CRT calls that would overwrite thread-local error slot 218 | // - Concurrency: Reads thread-local storage only (no data races) 219 | // - Memory safety: Returns u32 value (no pointer dereferences) 220 | unsafe { GetLastError() } 221 | ) 222 | .into()); 223 | } 224 | 225 | if bytes_returned != test_length { 226 | return Err(format!( 227 | "bytes written is not test length! Written {bytes_returned}, SB {test_length}" 228 | ) 229 | .into()); 230 | } 231 | 232 | println!("{bytes_returned} Pattern Bytes Written successfully"); 233 | 234 | bytes_returned = 0; 235 | 236 | // SAFETY: 237 | // Call Win32 API FFI ReadFile to read data from the driver 238 | unsafe { 239 | r = ReadFile( 240 | h_device, 241 | read_buffer.as_mut_ptr().cast(), 242 | test_length, 243 | &mut bytes_returned, 244 | std::ptr::null_mut(), 245 | ); 246 | } 247 | 248 | if r == FALSE { 249 | return Err(format!( 250 | "PerformWriteReadTest: ReadFile failed: Error {}", 251 | // SAFETY: 252 | // - FFI contract: Called immediately after ReadFile failure before any intervening 253 | // Win32/CRT calls that would overwrite thread-local error slot 254 | // - Concurrency: Reads thread-local storage only (no data races) 255 | // - Memory safety: Returns u32 value (no pointer dereferences) 256 | unsafe { GetLastError() } 257 | ) 258 | .into()); 259 | } 260 | 261 | // SAFETY: 262 | // Call set_len on the Vec that contains the buffer used in ReadFile to tell the 263 | // Vec how many bytes were actually put into the Vec 264 | unsafe { 265 | read_buffer.set_len(usize::try_from(bytes_returned).unwrap()); 266 | } 267 | 268 | if bytes_returned != test_length { 269 | return Err(format!( 270 | "bytes Read is not test length! Read {bytes_returned}, SB {test_length}" 271 | ) 272 | .into()); 273 | } 274 | 275 | println!("{bytes_returned} Pattern Bytes Read successfully"); 276 | 277 | verify_pattern_buffer(&read_buffer)?; 278 | 279 | println!("Pattern Verified successfully\n"); 280 | 281 | Ok(()) 282 | } 283 | 284 | fn async_io(thread_parameter: u32) -> Result<(), Box> { 285 | match async_io_work(thread_parameter) { 286 | Err(e) => Err(e.to_string().into()), 287 | Ok(()) => Ok(()), 288 | } 289 | } 290 | 291 | // In order to keep this function close to the original WDK app, ignoring large 292 | // function warning 293 | #[allow(clippy::too_many_lines)] 294 | fn async_io_work(io_type: u32) -> Result<(), Box> { 295 | let globals = GLOBAL_DATA.read()?; 296 | 297 | let h_device: HANDLE; 298 | let h_completion_port: HANDLE; 299 | let mut r: BOOL; 300 | 301 | // SAFETY: 302 | // Call Win32 API FFI CreateFileW to access driver 303 | unsafe { 304 | let mut path_vec = globals.device_path.encode_utf16().collect::>(); 305 | path_vec.push(0); 306 | let path = path_vec.as_ptr(); 307 | 308 | h_device = CreateFileW( 309 | path, 310 | FILE_GENERIC_READ | FILE_GENERIC_WRITE, 311 | FILE_SHARE_READ | FILE_SHARE_WRITE, 312 | std::ptr::null(), 313 | OPEN_EXISTING, 314 | FILE_FLAG_OVERLAPPED, 315 | std::ptr::null_mut(), 316 | ); 317 | } 318 | 319 | if h_device == INVALID_HANDLE_VALUE { 320 | return Err(format!( 321 | "Cannot open {} error {}", 322 | globals.device_path, 323 | // SAFETY: 324 | // - FFI contract: Called immediately after CreateFileW failure before any intervening 325 | // Win32/CRT calls that would overwrite thread-local error slot 326 | // - Concurrency: Reads thread-local storage only (no data races) 327 | // - Memory safety: Returns u32 value (no pointer dereferences) 328 | unsafe { GetLastError() } 329 | ) 330 | .into()); 331 | } 332 | 333 | // SAFETY: 334 | // Call Win32 API FFI CreateIoCompletionPort to get handle for completing async 335 | // requests 336 | unsafe { 337 | h_completion_port = CreateIoCompletionPort(h_device, std::ptr::null_mut(), 1, 0); 338 | } 339 | 340 | if h_completion_port.is_null() { 341 | return Err(format!( 342 | "Cannot open completion port {}", 343 | // SAFETY: 344 | // - FFI contract: Called immediately after CreateIoCompletionPort failure before any 345 | // intervening Win32/CRT calls that would overwrite thread-local error slot 346 | // - Concurrency: Reads thread-local storage only (no data races) 347 | // - Memory safety: Returns u32 value (no pointer dereferences) 348 | unsafe { GetLastError() } 349 | ) 350 | .into()); 351 | } 352 | 353 | let mut remaining_requests_to_receive = 0; 354 | let mut max_pending_requests = NUM_ASYNCH_IO; 355 | let mut remaining_requests_to_send = 0; 356 | if globals.limited_loops { 357 | remaining_requests_to_receive = globals.async_io_loops_num; 358 | if globals.async_io_loops_num > NUM_ASYNCH_IO { 359 | max_pending_requests = NUM_ASYNCH_IO; 360 | remaining_requests_to_send = globals.async_io_loops_num - NUM_ASYNCH_IO; 361 | } else { 362 | max_pending_requests = globals.async_io_loops_num; 363 | remaining_requests_to_send = 0; 364 | } 365 | } 366 | 367 | let mut ov_list: Vec = vec![ 368 | OVERLAPPED { 369 | Internal: 0, 370 | InternalHigh: 0, 371 | Anonymous: OVERLAPPED_0 { 372 | Pointer: std::ptr::null_mut(), 373 | }, 374 | hEvent: std::ptr::null_mut(), 375 | }; 376 | max_pending_requests 377 | ]; 378 | let mut buf: Vec = vec![0; max_pending_requests * BUFFER_SIZE]; 379 | 380 | for i in 0..max_pending_requests { 381 | // SAFETY: 382 | // Get the offset into the buffer for sending data at offset for request 'i' 383 | let buffer_offset = unsafe { 384 | (buf.as_mut_ptr() 385 | .offset(isize::try_from(i * BUFFER_SIZE).unwrap())) 386 | .cast() 387 | }; 388 | 389 | // SAFETY: 390 | // Get the pointer for the list of Overlapped array for ReadFile at the offset 391 | // for request 'i' 392 | let overlap_struct_offset = 393 | unsafe { ov_list.as_mut_ptr().offset(isize::try_from(i).unwrap()) }; 394 | 395 | if io_type == READER_TYPE { 396 | // SAFETY: 397 | // Call Win32 API FFI ReadFile to read from driver with an overlap option 398 | unsafe { 399 | r = ReadFile( 400 | h_device, 401 | buffer_offset, 402 | u32::try_from(BUFFER_SIZE).unwrap(), 403 | std::ptr::null_mut(), 404 | overlap_struct_offset, 405 | ); 406 | } 407 | 408 | if r == FALSE { 409 | // SAFETY: 410 | // - FFI contract: Called immediately after ReadFile failure before any 411 | // intervening Win32/CRT calls that would overwrite thread-local error slot 412 | // - Concurrency: Reads thread-local storage only (no data races) 413 | // - Memory safety: Returns u32 value (no pointer dereferences) 414 | let error = unsafe { GetLastError() }; 415 | if error != ERROR_IO_PENDING { 416 | return Err(format!("{i}th Read failed {error}",).into()); 417 | } 418 | } 419 | } else { 420 | // SAFETY: 421 | // Call Win32 API FFI WriteFile to write to driver with an overlap option 422 | unsafe { 423 | let mut number_of_bytes_written: u32 = 0; 424 | 425 | r = WriteFile( 426 | h_device, 427 | buffer_offset, 428 | u32::try_from(BUFFER_SIZE).unwrap(), 429 | &mut number_of_bytes_written, 430 | overlap_struct_offset, 431 | ); 432 | } 433 | 434 | if r == FALSE { 435 | // SAFETY: 436 | // - FFI contract: Called immediately after WriteFile failure before any 437 | // intervening Win32/CRT calls that would overwrite thread-local error slot 438 | // - Concurrency: Reads thread-local storage only (no data races) 439 | // - Memory safety: Returns u32 value (no pointer dereferences) 440 | let error = unsafe { GetLastError() }; 441 | if error != ERROR_IO_PENDING { 442 | return Err(format!("{i}th Write failed {error}").into()); 443 | } 444 | } 445 | } 446 | } 447 | 448 | loop { 449 | let mut number_of_bytes_transferred = 0; 450 | let mut key = 0; 451 | let mut completed_ov_ptr: *mut OVERLAPPED = std::ptr::null_mut(); 452 | 453 | // SAFETY: 454 | // Call Win32 API FFI GetQueuedCompletionStatus to access the status of the 455 | // completion request 456 | unsafe { 457 | r = GetQueuedCompletionStatus( 458 | h_completion_port, 459 | &mut number_of_bytes_transferred, 460 | &mut key, 461 | std::ptr::addr_of_mut!(completed_ov_ptr), 462 | INFINITE, 463 | ); 464 | } 465 | 466 | if r == FALSE { 467 | return Err(format!( 468 | "GetQueuedCompletionStatus failed {}", 469 | // SAFETY: 470 | // - FFI contract: Called immediately after GetQueuedCompletionStatus failure 471 | // before any intervening Win32/CRT calls that would overwrite thread-local error 472 | // slot 473 | // - Concurrency: Reads thread-local storage only (no data races) 474 | // - Memory safety: Returns u32 value (no pointer dereferences) 475 | unsafe { GetLastError() } 476 | ) 477 | .into()); 478 | } 479 | 480 | let i; 481 | 482 | // SAFETY: 483 | // Perform pointer math to determine which index 'i' to use by determining the 484 | // offset of 'completed_ov_ptr' from the start of the array given by 485 | // 'ov_list' 486 | unsafe { 487 | i = completed_ov_ptr.offset_from(ov_list.as_ptr()); 488 | } 489 | 490 | if io_type == READER_TYPE { 491 | println!("Number of bytes read by request number {i} is {number_of_bytes_transferred}",); 492 | 493 | if globals.limited_loops { 494 | remaining_requests_to_receive -= 1; 495 | if remaining_requests_to_receive == 0 { 496 | break; 497 | } 498 | 499 | if remaining_requests_to_send == 0 { 500 | continue; 501 | } 502 | 503 | remaining_requests_to_send -= 1; 504 | } 505 | 506 | let buffer_offset; 507 | 508 | // SAFETY: 509 | // Get the offset into the buffer for reading data at offset for request 'i' 510 | unsafe { 511 | buffer_offset = (buf 512 | .as_mut_ptr() 513 | .offset(i * isize::try_from(BUFFER_SIZE).unwrap())) 514 | .cast(); 515 | } 516 | 517 | // SAFETY: 518 | // Call Win32 API FFI ReadFile to read in data from the driver 519 | unsafe { 520 | r = ReadFile( 521 | h_device, 522 | buffer_offset, 523 | u32::try_from(BUFFER_SIZE).unwrap(), 524 | std::ptr::null_mut(), 525 | completed_ov_ptr, 526 | ); 527 | } 528 | 529 | if r == FALSE { 530 | // SAFETY: 531 | // - FFI contract: Called immediately after ReadFile failure before any 532 | // intervening Win32/CRT calls that would overwrite thread-local error slot 533 | // - Concurrency: Reads thread-local storage only (no data races) 534 | // - Memory safety: Returns u32 value (no pointer dereferences) 535 | let error = unsafe { GetLastError() }; 536 | if error != ERROR_IO_PENDING { 537 | return Err(format!("{i}th Read failed {error}").into()); 538 | } 539 | } 540 | } else { 541 | println!( 542 | "Number of bytes written by request number {i} is {number_of_bytes_transferred}", 543 | ); 544 | 545 | if globals.limited_loops { 546 | remaining_requests_to_receive -= 1; 547 | if remaining_requests_to_receive == 0 { 548 | break; 549 | } 550 | 551 | if remaining_requests_to_send == 0 { 552 | continue; 553 | } 554 | 555 | remaining_requests_to_send -= 1; 556 | } 557 | 558 | let buffer_offset; 559 | 560 | // SAFETY: 561 | // Get the offset into the buffer for sending data at offset for request 'i' 562 | unsafe { 563 | buffer_offset = (buf 564 | .as_mut_ptr() 565 | .offset(i * isize::try_from(BUFFER_SIZE).unwrap())) 566 | .cast(); 567 | } 568 | 569 | // SAFETY: 570 | // Call Win32 API FFI WriteFile to write data to the driver 571 | unsafe { 572 | r = WriteFile( 573 | h_device, 574 | buffer_offset, 575 | u32::try_from(BUFFER_SIZE).unwrap(), 576 | std::ptr::null_mut(), 577 | completed_ov_ptr, 578 | ); 579 | } 580 | 581 | if r == FALSE { 582 | // SAFETY: 583 | // - FFI contract: Called immediately after WriteFile failure before any 584 | // intervening Win32/CRT calls that would overwrite thread-local error slot 585 | // - Concurrency: Reads thread-local storage only (no data races) 586 | // - Memory safety: Returns u32 value (no pointer dereferences) 587 | let error = unsafe { GetLastError() }; 588 | if error != ERROR_IO_PENDING { 589 | return Err(format!("{i}th write failed {error}").into()); 590 | } 591 | } 592 | } 593 | } 594 | drop(globals); 595 | 596 | // SAFETY: 597 | // Call Win32 API FFI CloseHandle to close completion port handle 598 | unsafe { 599 | CloseHandle(h_completion_port); 600 | } 601 | 602 | // SAFETY: 603 | // Call Win32 API FFI CloseHandle to close device handle 604 | unsafe { 605 | CloseHandle(h_device); 606 | } 607 | 608 | Ok(()) 609 | } 610 | 611 | fn get_device_path(interface_guid: &Uuid) -> Result<(), Box> { 612 | let mut guid = windows_sys::core::GUID { 613 | data1: 0, 614 | data2: 0, 615 | data3: 0, 616 | data4: [0, 0, 0, 0, 0, 0, 0, 0], 617 | }; 618 | let guid_data4: &[u8; 8]; 619 | let mut device_interface_list_length: u32 = 0; 620 | let mut config_ret; 621 | 622 | (guid.data1, guid.data2, guid.data3, guid_data4) = interface_guid.as_fields(); 623 | guid.data4 = *guid_data4; 624 | 625 | // SAFETY: 626 | // Call Win32 API FFI CM_Get_Device_Interface_List_SizeW to determine size of 627 | // space needed for a subsequent request 628 | unsafe { 629 | config_ret = DeviceAndDriverInstallation::CM_Get_Device_Interface_List_SizeW( 630 | &mut device_interface_list_length, 631 | &guid, 632 | std::ptr::null(), 633 | DeviceAndDriverInstallation::CM_GET_DEVICE_INTERFACE_LIST_PRESENT, 634 | ); 635 | } 636 | 637 | if config_ret != DeviceAndDriverInstallation::CR_SUCCESS { 638 | return Err( 639 | format!("Error 0x{config_ret:08X} retrieving device interface list size.",).into(), 640 | ); 641 | } 642 | 643 | if device_interface_list_length <= 1 { 644 | return Err( 645 | "Error: No active device interfaces found. Is the sample driver loaded?".into(), 646 | ); 647 | } 648 | 649 | let mut buffer: Vec = vec![0; usize::try_from(device_interface_list_length).unwrap()]; 650 | let buffer_ptr = buffer.as_mut_ptr(); 651 | 652 | // SAFETY: 653 | // Call Win32 API FFI CM_Get_Device_Interface_ListW to get the list of Device 654 | // Interfaces that match the Interface GUID for the echo driver 655 | unsafe { 656 | config_ret = DeviceAndDriverInstallation::CM_Get_Device_Interface_ListW( 657 | &guid, 658 | std::ptr::null(), 659 | buffer_ptr, 660 | device_interface_list_length, 661 | DeviceAndDriverInstallation::CM_GET_DEVICE_INTERFACE_LIST_PRESENT, 662 | ); 663 | } 664 | 665 | if config_ret != DeviceAndDriverInstallation::CR_SUCCESS { 666 | return Err(format!("Error 0x{config_ret:08X} retrieving device interface list.").into()); 667 | } 668 | 669 | let path = OsString::from_wide(buffer.as_slice()); 670 | 671 | GLOBAL_DATA.write()?.device_path = path 672 | .into_string() 673 | .expect("Unable to convert Device Path to String"); 674 | 675 | Ok(()) 676 | } 677 | -------------------------------------------------------------------------------- /general/echo/kmdf/driver/DriverSync/src/queue.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // License: MIT OR Apache-2.0 3 | 4 | use core::sync::atomic::Ordering; 5 | 6 | use wdk::{nt_success, paged_code, println, wdf}; 7 | use wdk_sys::{ 8 | call_unsafe_wdf_function_binding, 9 | ntddk::{ExAllocatePool2, ExFreePool}, 10 | NTSTATUS, 11 | POOL_FLAG_NON_PAGED, 12 | SIZE_T, 13 | STATUS_BUFFER_OVERFLOW, 14 | STATUS_CANCELLED, 15 | STATUS_INSUFFICIENT_RESOURCES, 16 | STATUS_INVALID_DEVICE_REQUEST, 17 | STATUS_SUCCESS, 18 | WDFDEVICE, 19 | WDFMEMORY, 20 | WDFOBJECT, 21 | WDFQUEUE, 22 | WDFREQUEST, 23 | WDFTIMER, 24 | WDF_IO_QUEUE_CONFIG, 25 | WDF_NO_HANDLE, 26 | WDF_OBJECT_ATTRIBUTES, 27 | WDF_TIMER_CONFIG, 28 | _WDF_EXECUTION_LEVEL, 29 | _WDF_IO_QUEUE_DISPATCH_TYPE, 30 | _WDF_SYNCHRONIZATION_SCOPE, 31 | _WDF_TRI_STATE, 32 | }; 33 | 34 | use crate::{ 35 | queue_get_context, 36 | request_get_context, 37 | wdf_object_context::wdf_get_context_type_info, 38 | AtomicI32, 39 | QueueContext, 40 | RequestContext, 41 | WDF_IO_QUEUE_CONFIG_SIZE, 42 | WDF_OBJECT_ATTRIBUTES_SIZE, 43 | WDF_QUEUE_CONTEXT_TYPE_INFO, 44 | WDF_TIMER_CONFIG_SIZE, 45 | }; 46 | 47 | /// Set max write length for testing 48 | const MAX_WRITE_LENGTH: usize = 1024 * 40; 49 | 50 | /// Set timer period in ms 51 | const TIMER_PERIOD: u32 = 1000 * 10; 52 | 53 | /// This routine will interlock increment a value only if the current value 54 | /// is greater then the floor value. 55 | /// 56 | /// The volatile keyword on the Target pointer is absolutely required, otherwise 57 | /// the compiler might rearrange pointer dereferences and that cannot happen. 58 | /// 59 | /// # Arguments: 60 | /// 61 | /// * `target` - the value that will be pontetially incrmented 62 | /// * `floor` - the value in which the Target value must be greater then if it 63 | /// is to be incremented 64 | /// 65 | /// # Return value: 66 | /// 67 | /// The current value of Target. To detect failure, the return value will be 68 | /// <= Floor + 1. It is +1 because we cannot increment from the Floor value 69 | /// itself, so Floor+1 cannot be a successful return value. 70 | fn echo_interlocked_increment_floor(target: &AtomicI32, floor: i32) -> i32 { 71 | let mut current_value = target.load(Ordering::SeqCst); 72 | loop { 73 | if current_value <= floor { 74 | return current_value; 75 | } 76 | 77 | // currentValue will be the value that used to be Target if the exchange 78 | // was made or its current value if the exchange was not made. 79 | // 80 | match target.compare_exchange( 81 | current_value, 82 | current_value + 1, 83 | Ordering::SeqCst, 84 | Ordering::SeqCst, 85 | ) { 86 | // If oldValue == currentValue, then no one updated Target in between 87 | // the deref at the top and the InterlockecCompareExchange afterward 88 | // and we have successfully incremented the value and can exit the loop. 89 | Ok(_) => break, 90 | Err(v) => current_value = v, 91 | } 92 | } 93 | 94 | current_value + 1 95 | } 96 | 97 | /// Increment the value only if it is currently > 0. 98 | /// 99 | /// # Arguments: 100 | /// 101 | /// * `target` - the value to be incremented 102 | /// 103 | /// # Return value: 104 | /// 105 | /// Upon success, a value > 0. Upon failure, a value <= 0. 106 | fn echo_interlocked_increment_gtzero(target: &AtomicI32) -> i32 { 107 | echo_interlocked_increment_floor(target, 0) 108 | } 109 | 110 | /// The I/O dispatch callbacks for the frameworks device object 111 | /// are configured in this function. 112 | /// 113 | /// A single default I/O Queue is configured for serial request 114 | /// processing, and a driver context memory allocation is created 115 | /// to hold our structure `QUEUE_CONTEXT`. 116 | /// 117 | /// This memory may be used by the driver automatically synchronized 118 | /// by the Queue's presentation lock. 119 | /// 120 | /// The lifetime of this memory is tied to the lifetime of the I/O 121 | /// Queue object, and we register an optional destructor callback 122 | /// to release any private allocations, and/or resources. 123 | /// 124 | /// # Arguments: 125 | /// 126 | /// * `device` - Handle to a framework device object. 127 | /// 128 | /// # Return value: 129 | /// 130 | /// * `NTSTATUS` 131 | #[link_section = "PAGE"] 132 | pub unsafe fn echo_queue_initialize(device: WDFDEVICE) -> NTSTATUS { 133 | paged_code!(); 134 | 135 | let mut queue = WDF_NO_HANDLE as WDFQUEUE; 136 | 137 | // Configure a default queue so that requests that are not 138 | // configure-fowarded using WdfDeviceConfigureRequestDispatching to goto 139 | // other queues get dispatched here. 140 | let mut queue_config = WDF_IO_QUEUE_CONFIG { 141 | Size: WDF_IO_QUEUE_CONFIG_SIZE, 142 | PowerManaged: _WDF_TRI_STATE::WdfUseDefault, 143 | DefaultQueue: u8::from(true), 144 | DispatchType: _WDF_IO_QUEUE_DISPATCH_TYPE::WdfIoQueueDispatchSequential, 145 | EvtIoRead: Some(echo_evt_io_read), 146 | EvtIoWrite: Some(echo_evt_io_write), 147 | ..WDF_IO_QUEUE_CONFIG::default() 148 | }; 149 | 150 | // Fill in a callback for destroy, and our QUEUE_CONTEXT size 151 | let mut attributes = WDF_OBJECT_ATTRIBUTES { 152 | Size: WDF_OBJECT_ATTRIBUTES_SIZE, 153 | ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent, 154 | SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent, 155 | ContextTypeInfo: wdf_get_context_type_info!(QueueContext), 156 | EvtDestroyCallback: Some(echo_evt_io_queue_context_destroy), 157 | ..WDF_OBJECT_ATTRIBUTES::default() 158 | }; 159 | 160 | // Create queue. 161 | let nt_status = unsafe { 162 | call_unsafe_wdf_function_binding!( 163 | WdfIoQueueCreate, 164 | device, 165 | &raw mut queue_config, 166 | &raw mut attributes, 167 | &raw mut queue 168 | ) 169 | }; 170 | 171 | if !nt_success(nt_status) { 172 | println!("WdfIoQueueCreate failed {nt_status:#010X}"); 173 | return nt_status; 174 | } 175 | 176 | // Get our Driver Context memory from the returned Queue handle 177 | let queue_context: *mut QueueContext = unsafe { queue_get_context(queue as WDFOBJECT) }; 178 | unsafe { 179 | (*queue_context).buffer = core::ptr::null_mut(); 180 | (*queue_context).current_request = core::ptr::null_mut(); 181 | (*queue_context).current_status = STATUS_INVALID_DEVICE_REQUEST; 182 | } 183 | 184 | // Create the SpinLock. 185 | let mut attributes = WDF_OBJECT_ATTRIBUTES { 186 | Size: WDF_OBJECT_ATTRIBUTES_SIZE, 187 | ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent, 188 | SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent, 189 | ParentObject: queue as WDFOBJECT, 190 | ..WDF_OBJECT_ATTRIBUTES::default() 191 | }; 192 | 193 | match wdf::SpinLock::create(&mut attributes) { 194 | Err(status) => { 195 | println!("SpinLock create failed {nt_status:#010X}"); 196 | return status; 197 | } 198 | Ok(spin_lock) => unsafe { (*queue_context).spin_lock = spin_lock }, 199 | } 200 | 201 | // Create the Queue timer 202 | // 203 | // By not setting the synchronization scope and using the default at 204 | // WdfIoQueueCreate, we are explicitly *not* serializing against the queue's 205 | // lock. Instead, we will do that on our own. 206 | let mut timer_config = WDF_TIMER_CONFIG { 207 | Size: WDF_TIMER_CONFIG_SIZE, 208 | EvtTimerFunc: Some(echo_evt_timer_func), 209 | Period: TIMER_PERIOD, 210 | AutomaticSerialization: u8::from(true), 211 | TolerableDelay: 0, 212 | ..WDF_TIMER_CONFIG::default() 213 | }; 214 | 215 | match wdf::Timer::create(&mut timer_config, &mut attributes) { 216 | Err(status) => { 217 | println!("Timer create failed {nt_status:#010X}"); 218 | return status; 219 | } 220 | Ok(wdftimer) => unsafe { (*queue_context).timer = wdftimer }, 221 | } 222 | 223 | STATUS_SUCCESS 224 | } 225 | 226 | /// This is called when the Queue that our driver context memory 227 | /// is associated with is destroyed. 228 | /// 229 | /// # Arguments: 230 | /// 231 | /// * `object` - Queue object to be freed. 232 | /// 233 | /// # Return value: 234 | /// 235 | /// * `VOID` 236 | extern "C" fn echo_evt_io_queue_context_destroy(object: WDFOBJECT) { 237 | let queue_context = unsafe { queue_get_context(object) }; 238 | // Release any resources pointed to in the queue context. 239 | // 240 | // The body of the queue context will be released after 241 | // this callback handler returns 242 | 243 | // If Queue context has an I/O buffer, release it 244 | unsafe { 245 | if !(*queue_context).buffer.is_null() { 246 | ExFreePool((*queue_context).buffer); 247 | (*queue_context).buffer = core::ptr::null_mut(); 248 | } 249 | } 250 | } 251 | 252 | /// Decrements the cancel ownership count for the request. When the count 253 | /// reaches zero ownership has been acquired. 254 | /// 255 | /// # Arguments: 256 | /// 257 | /// * `request_context` - the context which holds the count. 258 | /// 259 | /// # Return value: 260 | /// 261 | /// * TRUE if the caller can complete the request, FALSE otherwise 262 | fn echo_decrement_request_cancel_ownership_count(request_context: *mut RequestContext) -> bool { 263 | let result = unsafe { 264 | (*request_context) 265 | .cancel_completion_ownership_count 266 | .fetch_sub(1, Ordering::SeqCst) 267 | }; 268 | 269 | result - 1 == 0 270 | } 271 | 272 | /// Attempts to increment the request ownership count so that it cannot be 273 | /// completed until the count has been decremented 274 | /// 275 | /// # Arguments: 276 | /// 277 | /// * `request_context` - the context which holds the count. 278 | /// 279 | /// # Return value: 280 | /// 281 | /// * TRUE if the count was incremented, FALSE otherwise 282 | fn echo_increment_request_cancel_ownership_count(request_context: *mut RequestContext) -> bool { 283 | // See comments in echo_interlocked_increment_floor as to why <= 1 is failure 284 | // 285 | (unsafe { 286 | echo_interlocked_increment_gtzero(&(*request_context).cancel_completion_ownership_count) 287 | }) > 1 288 | } 289 | 290 | /// Called when an I/O request is cancelled after the driver has marked 291 | /// the request cancellable. This callback is not automatically synchronized 292 | /// with the I/O callbacks since we have chosen not to use frameworks Device 293 | /// or Queue level locking. 294 | /// 295 | /// # Arguments: 296 | /// 297 | /// * `request` - Request being cancelled. 298 | /// 299 | /// # Return value: 300 | /// 301 | /// * `VOID` 302 | extern "C" fn echo_evt_request_cancel(request: WDFREQUEST) { 303 | let queue = unsafe { call_unsafe_wdf_function_binding!(WdfRequestGetIoQueue, request) }; 304 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 305 | let request_context = unsafe { request_get_context(request as WDFOBJECT) }; 306 | 307 | println!("echo_evt_request_cancel called on Request {:?}", request); 308 | 309 | // This book keeping is synchronized by the common 310 | // Queue presentation lock which we are now acquiring 311 | unsafe { (*queue_context).spin_lock.acquire() }; 312 | 313 | let complete_request: bool = echo_decrement_request_cancel_ownership_count(request_context); 314 | 315 | if complete_request { 316 | unsafe { 317 | (*queue_context).current_request = core::ptr::null_mut(); 318 | } 319 | } else { 320 | unsafe { 321 | (*queue_context).current_status = STATUS_CANCELLED; 322 | } 323 | } 324 | 325 | unsafe { (*queue_context).spin_lock.release() }; 326 | 327 | // Complete the request outside of holding any locks 328 | if complete_request { 329 | unsafe { 330 | call_unsafe_wdf_function_binding!( 331 | WdfRequestCompleteWithInformation, 332 | request, 333 | STATUS_CANCELLED, 334 | 0 335 | ); 336 | } 337 | } 338 | } 339 | 340 | /// Setup the request, intialize its context and mark it as cancelable. 341 | /// 342 | /// # Arguments: 343 | /// 344 | /// * `request` - Request being set up. 345 | /// * `queue` - Queue associated with the request 346 | /// 347 | /// # Return value: 348 | /// 349 | /// * `VOID` 350 | fn echo_set_current_request(request: WDFREQUEST, queue: WDFQUEUE) { 351 | let status: NTSTATUS; 352 | let request_context = unsafe { request_get_context(request as WDFOBJECT) }; 353 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 354 | 355 | // Set the ownership count to one. When a caller wants to claim ownership, 356 | // they will interlock decrement the count. When the count reaches zero, 357 | // ownership has been acquired and the caller may complete the request. 358 | unsafe { 359 | (*request_context).cancel_completion_ownership_count = AtomicI32::new(1); 360 | } 361 | 362 | // Defer the completion to another thread from the timer dpc 363 | unsafe { (*queue_context).spin_lock.acquire() }; 364 | unsafe { 365 | (*queue_context).current_request = request; 366 | (*queue_context).current_status = STATUS_SUCCESS; 367 | } 368 | 369 | // Set the cancel routine under the lock, otherwise if we set it outside 370 | // of the lock, the timer could run and attempt to mark the request 371 | // uncancelable before we can mark it cancelable on this thread. Use 372 | // WdfRequestMarkCancelableEx here to prevent to deadlock with ourselves 373 | // (cancel routine tries to acquire the queue object lock). 374 | unsafe { 375 | status = call_unsafe_wdf_function_binding!( 376 | WdfRequestMarkCancelableEx, 377 | request, 378 | Some(echo_evt_request_cancel) 379 | ); 380 | if !nt_success(status) { 381 | (*queue_context).current_request = core::ptr::null_mut(); 382 | } 383 | } 384 | 385 | unsafe { (*queue_context).spin_lock.release() }; 386 | 387 | unsafe { 388 | // Complete the request with an error when unable to mark it cancelable. 389 | if !nt_success(status) { 390 | call_unsafe_wdf_function_binding!( 391 | WdfRequestCompleteWithInformation, 392 | request, 393 | status, 394 | 0 395 | ); 396 | } 397 | } 398 | } 399 | 400 | /// This event is called when the framework receives `IRP_MJ_READ` request. 401 | /// It will copy the content from the queue-context buffer to the request 402 | /// buffer. If the driver hasn't received any write request earlier, the read 403 | /// returns zero. 404 | /// 405 | /// # Arguments: 406 | /// 407 | /// * `queue` - Handle to the framework queue object that is associated with the 408 | /// I/O request. 409 | /// * `request` - Handle to a framework request object. 410 | /// * `length` - number of bytes to be read. The default property of the queue 411 | /// is to not dispatch zero lenght read & write requests to the driver and 412 | /// complete is with status success. So we will never get a zero length 413 | /// request. 414 | /// 415 | /// # Return value: 416 | /// 417 | /// * `VOID` 418 | extern "C" fn echo_evt_io_read(queue: WDFQUEUE, request: WDFREQUEST, mut length: usize) { 419 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 420 | let mut memory = WDF_NO_HANDLE as WDFMEMORY; 421 | let mut nt_status: NTSTATUS; 422 | 423 | println!( 424 | "echo_evt_io_read called! queue {:?}, request {:?}, length {:?}", 425 | queue, request, length 426 | ); 427 | 428 | // No data to read 429 | unsafe { 430 | if (*queue_context).buffer.is_null() { 431 | call_unsafe_wdf_function_binding!( 432 | WdfRequestCompleteWithInformation, 433 | request, 434 | STATUS_SUCCESS, 435 | 0, 436 | ); 437 | return; 438 | } 439 | } 440 | 441 | // Read what we have 442 | unsafe { 443 | if (*queue_context).length < length { 444 | length = (*queue_context).length; 445 | } 446 | } 447 | 448 | // Get the request memory 449 | unsafe { 450 | nt_status = call_unsafe_wdf_function_binding!( 451 | WdfRequestRetrieveOutputMemory, 452 | request, 453 | &raw mut memory 454 | ); 455 | 456 | if !nt_success(nt_status) { 457 | println!("echo_evt_io_read Could not get request memory buffer {nt_status:#010X}"); 458 | call_unsafe_wdf_function_binding!( 459 | WdfRequestCompleteWithInformation, 460 | request, 461 | nt_status, 462 | 0 463 | ); 464 | return; 465 | } 466 | } 467 | 468 | // Copy the memory out 469 | unsafe { 470 | nt_status = call_unsafe_wdf_function_binding!( 471 | WdfMemoryCopyFromBuffer, 472 | memory, 473 | 0, 474 | (*queue_context).buffer, 475 | length 476 | ); 477 | 478 | if !nt_success(nt_status) { 479 | println!("echo_evt_io_read: WdfMemoryCopyFromBuffer failed {nt_status:#010X}"); 480 | call_unsafe_wdf_function_binding!(WdfRequestComplete, request, nt_status); 481 | return; 482 | } 483 | } 484 | 485 | // Set transfer information 486 | let [()] = unsafe { 487 | [call_unsafe_wdf_function_binding!( 488 | WdfRequestSetInformation, 489 | request, 490 | length as u64 491 | )] 492 | }; 493 | 494 | // Mark the request is cancelable. This must be the last thing we do because 495 | // the cancel routine can run immediately after we set it. This means that 496 | // CurrentRequest and CurrentStatus must be initialized before we mark the 497 | // request cancelable. 498 | echo_set_current_request(request, queue); 499 | } 500 | 501 | /// This event is invoked when the framework receives `IRP_MJ_WRITE` request. 502 | /// This routine allocates memory buffer, copies the data from the request to 503 | /// it, and stores the buffer pointer in the queue-context with the length 504 | /// variable representing the buffers length. The actual completion of the 505 | /// request is defered to the periodic timer dpc. 506 | /// 507 | /// # Arguments: 508 | /// 509 | /// * `queue` - Handle to the framework queue object that is associated with the 510 | /// I/O request. 511 | /// * `request` - Handle to a framework request object. 512 | /// * `length` - number of bytes to be read. The default property of the queue 513 | /// is to not dispatch zero lenght read & write requests to the driver and 514 | /// complete is with status success. So we will never get a zero length 515 | /// request. 516 | /// 517 | /// # Return value: 518 | /// 519 | /// * `VOID` 520 | extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: usize) { 521 | let mut memory = WDF_NO_HANDLE as WDFMEMORY; 522 | let mut status: NTSTATUS; 523 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 524 | 525 | println!( 526 | "echo_evt_io_write called! queue {:?}, request {:?}, length {:?}", 527 | queue, request, length 528 | ); 529 | 530 | if length > MAX_WRITE_LENGTH { 531 | println!( 532 | "echo_evt_io_write Buffer Length to big {:?}, Max is {:?}", 533 | length, MAX_WRITE_LENGTH 534 | ); 535 | unsafe { 536 | call_unsafe_wdf_function_binding!( 537 | WdfRequestCompleteWithInformation, 538 | request, 539 | STATUS_BUFFER_OVERFLOW, 540 | 0 541 | ); 542 | } 543 | } 544 | 545 | // Get the memory buffer 546 | unsafe { 547 | status = call_unsafe_wdf_function_binding!( 548 | WdfRequestRetrieveInputMemory, 549 | request, 550 | &raw mut memory 551 | ); 552 | if !nt_success(status) { 553 | println!("echo_evt_io_write Could not get request memory buffer {status:#010X}"); 554 | call_unsafe_wdf_function_binding!(WdfRequestComplete, request, status); 555 | return; 556 | } 557 | } 558 | 559 | // Release previous buffer if set 560 | unsafe { 561 | if !(*queue_context).buffer.is_null() { 562 | ExFreePool((*queue_context).buffer); 563 | (*queue_context).buffer = core::ptr::null_mut(); 564 | (*queue_context).length = 0; 565 | } 566 | 567 | // FIXME: Memory Tag 568 | (*queue_context).buffer = 569 | ExAllocatePool2(POOL_FLAG_NON_PAGED, length as SIZE_T, 's' as u32); 570 | if (*queue_context).buffer.is_null() { 571 | println!( 572 | "echo_evt_io_write Could not allocate {:?} byte buffer", 573 | length 574 | ); 575 | call_unsafe_wdf_function_binding!( 576 | WdfRequestComplete, 577 | request, 578 | STATUS_INSUFFICIENT_RESOURCES 579 | ); 580 | return; 581 | } 582 | } 583 | 584 | // Copy the memory in 585 | unsafe { 586 | status = call_unsafe_wdf_function_binding!( 587 | WdfMemoryCopyToBuffer, 588 | memory, 589 | 0, 590 | (*queue_context).buffer, 591 | length 592 | ); 593 | 594 | if !nt_success(status) { 595 | println!("echo_evt_io_write WdfMemoryCopyToBuffer failed {status:#010X}"); 596 | ExFreePool((*queue_context).buffer); 597 | (*queue_context).buffer = core::ptr::null_mut(); 598 | (*queue_context).length = 0; 599 | call_unsafe_wdf_function_binding!(WdfRequestComplete, request, status); 600 | return; 601 | } 602 | 603 | (*queue_context).length = length; 604 | } 605 | 606 | // Set transfer information 607 | unsafe { 608 | call_unsafe_wdf_function_binding!(WdfRequestSetInformation, request, length as u64); 609 | } 610 | 611 | // Mark the request is cancelable. This must be the last thing we do because 612 | // the cancel routine can run immediately after we set it. This means that 613 | // CurrentRequest and CurrentStatus must be initialized before we mark the 614 | // request cancelable. 615 | echo_set_current_request(request, queue); 616 | } 617 | 618 | /// This is the `TimerDPC` the driver sets up to complete requests. 619 | /// This function is registered when the WDFTIMER object is created. 620 | /// 621 | /// This function does *NOT* automatically synchronize with the I/O Queue 622 | /// callbacks and cancel routine, we must do it ourself in the routine. 623 | /// 624 | /// # Arguments: 625 | /// 626 | /// * `timer` - Handle to a framework Timer object. 627 | /// 628 | /// # Return value: 629 | /// 630 | /// * `VOID` 631 | unsafe extern "C" fn echo_evt_timer_func(timer: WDFTIMER) { 632 | // Default to failure. status is initialized so that the compiler does not 633 | // think we are using an uninitialized value when completing the request. 634 | let mut status; 635 | let mut cancel = false; 636 | let complete_request; 637 | let queue: WDFQUEUE; 638 | let request: WDFREQUEST; 639 | let mut request_context: *mut RequestContext = core::ptr::null_mut(); 640 | unsafe { 641 | queue = call_unsafe_wdf_function_binding!(WdfTimerGetParentObject, timer,) as WDFQUEUE; 642 | } 643 | let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; 644 | 645 | // We must synchronize with the cancel routine which will be taking the 646 | // request out of the context under this lock. 647 | unsafe { (*queue_context).spin_lock.acquire() }; 648 | unsafe { 649 | request = (*queue_context).current_request; 650 | } 651 | if !request.is_null() { 652 | request_context = unsafe { request_get_context(request as WDFOBJECT) }; 653 | if echo_increment_request_cancel_ownership_count(request_context) { 654 | cancel = true; 655 | } else { 656 | // What has happened is that the cancel routine has executed and 657 | // has already claimed cancel ownership of the request, but has not 658 | // yet acquired the object lock and cleared the CurrentRequest field 659 | // in queueContext. In this case, do nothing and let the cancel 660 | // routine run to completion and complete the request. 661 | } 662 | } 663 | 664 | unsafe { (*queue_context).spin_lock.release() }; 665 | 666 | // If we could not claim cancel ownership, we are done. 667 | if !cancel { 668 | return; 669 | } 670 | 671 | // The request handle and requestContext are valid until we release 672 | // the cancel ownership count we already acquired. 673 | unsafe { 674 | status = call_unsafe_wdf_function_binding!(WdfRequestUnmarkCancelable, request,); 675 | if status == STATUS_CANCELLED { 676 | complete_request = echo_decrement_request_cancel_ownership_count(request_context); 677 | 678 | if complete_request { 679 | println!( 680 | "CustomTimerDPC Request {:?} is STATUS_CANCELLED, but claimed completion \ 681 | ownership", 682 | request 683 | ); 684 | } else { 685 | println!( 686 | "CustomTimerDPC Request {:?} is STATUS_CANCELLED, not completing", 687 | request 688 | ); 689 | } 690 | } else { 691 | println!( 692 | "CustomTimerDPC successfully cleared cancel routine on request {:?}, status {:?}", 693 | request, status 694 | ); 695 | 696 | // Since we successfully removed the cancel routine (and we are not 697 | // currently racing with it), there is no need to use an interlocked 698 | // decrement to lower the cancel ownership count. 699 | 700 | // 2 is the initial count we set when we initialized 701 | // CancelCompletionOwnershipCount plus the call to 702 | // EchoIncrementRequestCancelOwnershipCount() 703 | (*request_context) 704 | .cancel_completion_ownership_count 705 | .fetch_sub(2, Ordering::SeqCst); 706 | complete_request = true; 707 | } 708 | } 709 | 710 | if complete_request { 711 | println!( 712 | "CustomTimerDPC Completing request {:?}, status {:?}", 713 | request, status 714 | ); 715 | 716 | // Clear the current request out of the queue context and complete 717 | // the request. 718 | unsafe { (*queue_context).spin_lock.acquire() }; 719 | unsafe { 720 | (*queue_context).current_request = core::ptr::null_mut(); 721 | status = (*queue_context).current_status; 722 | } 723 | unsafe { (*queue_context).spin_lock.release() }; 724 | 725 | unsafe { 726 | call_unsafe_wdf_function_binding!(WdfRequestComplete, request, status); 727 | } 728 | } 729 | } 730 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "1.1.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "anstream" 16 | version = "0.6.21" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 19 | dependencies = [ 20 | "anstyle", 21 | "anstyle-parse", 22 | "anstyle-query", 23 | "anstyle-wincon", 24 | "colorchoice", 25 | "is_terminal_polyfill", 26 | "utf8parse", 27 | ] 28 | 29 | [[package]] 30 | name = "anstyle" 31 | version = "1.0.13" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 34 | 35 | [[package]] 36 | name = "anstyle-parse" 37 | version = "0.2.3" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" 40 | dependencies = [ 41 | "utf8parse", 42 | ] 43 | 44 | [[package]] 45 | name = "anstyle-query" 46 | version = "1.1.3" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" 49 | dependencies = [ 50 | "windows-sys", 51 | ] 52 | 53 | [[package]] 54 | name = "anstyle-wincon" 55 | version = "3.0.9" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" 58 | dependencies = [ 59 | "anstyle", 60 | "once_cell_polyfill", 61 | "windows-sys", 62 | ] 63 | 64 | [[package]] 65 | name = "anyhow" 66 | version = "1.0.98" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" 69 | 70 | [[package]] 71 | name = "bindgen" 72 | version = "0.71.1" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" 75 | dependencies = [ 76 | "bitflags", 77 | "cexpr", 78 | "clang-sys", 79 | "itertools", 80 | "log", 81 | "prettyplease", 82 | "proc-macro2", 83 | "quote", 84 | "regex", 85 | "rustc-hash", 86 | "shlex", 87 | "syn", 88 | ] 89 | 90 | [[package]] 91 | name = "bitflags" 92 | version = "2.4.2" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" 95 | 96 | [[package]] 97 | name = "camino" 98 | version = "1.1.9" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" 101 | dependencies = [ 102 | "serde", 103 | ] 104 | 105 | [[package]] 106 | name = "cargo-platform" 107 | version = "0.1.7" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "694c8807f2ae16faecc43dc17d74b3eb042482789fd0eb64b39a2e04e087053f" 110 | dependencies = [ 111 | "serde", 112 | ] 113 | 114 | [[package]] 115 | name = "cargo_metadata" 116 | version = "0.19.2" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" 119 | dependencies = [ 120 | "camino", 121 | "cargo-platform", 122 | "semver", 123 | "serde", 124 | "serde_json", 125 | "thiserror", 126 | ] 127 | 128 | [[package]] 129 | name = "cc" 130 | version = "1.2.45" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe" 133 | dependencies = [ 134 | "find-msvc-tools", 135 | "shlex", 136 | ] 137 | 138 | [[package]] 139 | name = "cexpr" 140 | version = "0.6.0" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" 143 | dependencies = [ 144 | "nom", 145 | ] 146 | 147 | [[package]] 148 | name = "cfg-if" 149 | version = "1.0.4" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 152 | 153 | [[package]] 154 | name = "clang-sys" 155 | version = "1.7.0" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" 158 | dependencies = [ 159 | "glob", 160 | "libc", 161 | "libloading", 162 | ] 163 | 164 | [[package]] 165 | name = "clap" 166 | version = "4.5.51" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5" 169 | dependencies = [ 170 | "clap_builder", 171 | "clap_derive", 172 | ] 173 | 174 | [[package]] 175 | name = "clap-cargo" 176 | version = "0.15.2" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "d546f0e84ff2bfa4da1ce9b54be42285767ba39c688572ca32412a09a73851e5" 179 | dependencies = [ 180 | "anstyle", 181 | "clap", 182 | ] 183 | 184 | [[package]] 185 | name = "clap_builder" 186 | version = "4.5.51" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a" 189 | dependencies = [ 190 | "anstream", 191 | "anstyle", 192 | "clap_lex", 193 | "strsim", 194 | ] 195 | 196 | [[package]] 197 | name = "clap_derive" 198 | version = "4.5.49" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 201 | dependencies = [ 202 | "heck", 203 | "proc-macro2", 204 | "quote", 205 | "syn", 206 | ] 207 | 208 | [[package]] 209 | name = "clap_lex" 210 | version = "0.7.6" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 213 | 214 | [[package]] 215 | name = "colorchoice" 216 | version = "1.0.0" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" 219 | 220 | [[package]] 221 | name = "echo-2" 222 | version = "0.1.0" 223 | dependencies = [ 224 | "anyhow", 225 | "paste", 226 | "wdk", 227 | "wdk-alloc", 228 | "wdk-build", 229 | "wdk-panic", 230 | "wdk-sys", 231 | ] 232 | 233 | [[package]] 234 | name = "echoapp" 235 | version = "0.1.0" 236 | dependencies = [ 237 | "once_cell", 238 | "uuid", 239 | "windows-sys", 240 | ] 241 | 242 | [[package]] 243 | name = "either" 244 | version = "1.10.0" 245 | source = "registry+https://github.com/rust-lang/crates.io-index" 246 | checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" 247 | 248 | [[package]] 249 | name = "errno" 250 | version = "0.3.14" 251 | source = "registry+https://github.com/rust-lang/crates.io-index" 252 | checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" 253 | dependencies = [ 254 | "libc", 255 | "windows-sys", 256 | ] 257 | 258 | [[package]] 259 | name = "fail_driver_pool_leak" 260 | version = "0.1.0" 261 | dependencies = [ 262 | "anyhow", 263 | "wdk", 264 | "wdk-alloc", 265 | "wdk-build", 266 | "wdk-panic", 267 | "wdk-sys", 268 | ] 269 | 270 | [[package]] 271 | name = "find-msvc-tools" 272 | version = "0.1.4" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" 275 | 276 | [[package]] 277 | name = "fs4" 278 | version = "0.13.1" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4" 281 | dependencies = [ 282 | "rustix", 283 | "windows-sys", 284 | ] 285 | 286 | [[package]] 287 | name = "glob" 288 | version = "0.3.1" 289 | source = "registry+https://github.com/rust-lang/crates.io-index" 290 | checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" 291 | 292 | [[package]] 293 | name = "heck" 294 | version = "0.5.0" 295 | source = "registry+https://github.com/rust-lang/crates.io-index" 296 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 297 | 298 | [[package]] 299 | name = "is_terminal_polyfill" 300 | version = "1.70.2" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 303 | 304 | [[package]] 305 | name = "itertools" 306 | version = "0.13.0" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" 309 | dependencies = [ 310 | "either", 311 | ] 312 | 313 | [[package]] 314 | name = "itoa" 315 | version = "1.0.10" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" 318 | 319 | [[package]] 320 | name = "lazy_static" 321 | version = "1.5.0" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 324 | 325 | [[package]] 326 | name = "libc" 327 | version = "0.2.177" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" 330 | 331 | [[package]] 332 | name = "libloading" 333 | version = "0.8.9" 334 | source = "registry+https://github.com/rust-lang/crates.io-index" 335 | checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" 336 | dependencies = [ 337 | "cfg-if", 338 | "windows-link", 339 | ] 340 | 341 | [[package]] 342 | name = "linux-raw-sys" 343 | version = "0.11.0" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" 346 | 347 | [[package]] 348 | name = "log" 349 | version = "0.4.20" 350 | source = "registry+https://github.com/rust-lang/crates.io-index" 351 | checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 352 | 353 | [[package]] 354 | name = "matchers" 355 | version = "0.2.0" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" 358 | dependencies = [ 359 | "regex-automata", 360 | ] 361 | 362 | [[package]] 363 | name = "memchr" 364 | version = "2.7.1" 365 | source = "registry+https://github.com/rust-lang/crates.io-index" 366 | checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" 367 | 368 | [[package]] 369 | name = "minimal-lexical" 370 | version = "0.2.1" 371 | source = "registry+https://github.com/rust-lang/crates.io-index" 372 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 373 | 374 | [[package]] 375 | name = "nom" 376 | version = "7.1.3" 377 | source = "registry+https://github.com/rust-lang/crates.io-index" 378 | checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" 379 | dependencies = [ 380 | "memchr", 381 | "minimal-lexical", 382 | ] 383 | 384 | [[package]] 385 | name = "nu-ansi-term" 386 | version = "0.50.3" 387 | source = "registry+https://github.com/rust-lang/crates.io-index" 388 | checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" 389 | dependencies = [ 390 | "windows-sys", 391 | ] 392 | 393 | [[package]] 394 | name = "once_cell" 395 | version = "1.19.0" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" 398 | 399 | [[package]] 400 | name = "once_cell_polyfill" 401 | version = "1.70.2" 402 | source = "registry+https://github.com/rust-lang/crates.io-index" 403 | checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 404 | 405 | [[package]] 406 | name = "paste" 407 | version = "1.0.15" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" 410 | 411 | [[package]] 412 | name = "pin-project-lite" 413 | version = "0.2.13" 414 | source = "registry+https://github.com/rust-lang/crates.io-index" 415 | checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" 416 | 417 | [[package]] 418 | name = "prettyplease" 419 | version = "0.2.32" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "664ec5419c51e34154eec046ebcba56312d5a2fc3b09a06da188e1ad21afadf6" 422 | dependencies = [ 423 | "proc-macro2", 424 | "syn", 425 | ] 426 | 427 | [[package]] 428 | name = "proc-macro2" 429 | version = "1.0.103" 430 | source = "registry+https://github.com/rust-lang/crates.io-index" 431 | checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 432 | dependencies = [ 433 | "unicode-ident", 434 | ] 435 | 436 | [[package]] 437 | name = "quote" 438 | version = "1.0.40" 439 | source = "registry+https://github.com/rust-lang/crates.io-index" 440 | checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 441 | dependencies = [ 442 | "proc-macro2", 443 | ] 444 | 445 | [[package]] 446 | name = "regex" 447 | version = "1.12.2" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" 450 | dependencies = [ 451 | "aho-corasick", 452 | "memchr", 453 | "regex-automata", 454 | "regex-syntax", 455 | ] 456 | 457 | [[package]] 458 | name = "regex-automata" 459 | version = "0.4.13" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" 462 | dependencies = [ 463 | "aho-corasick", 464 | "memchr", 465 | "regex-syntax", 466 | ] 467 | 468 | [[package]] 469 | name = "regex-syntax" 470 | version = "0.8.8" 471 | source = "registry+https://github.com/rust-lang/crates.io-index" 472 | checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" 473 | 474 | [[package]] 475 | name = "rustc-hash" 476 | version = "2.1.1" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" 479 | 480 | [[package]] 481 | name = "rustix" 482 | version = "1.1.2" 483 | source = "registry+https://github.com/rust-lang/crates.io-index" 484 | checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" 485 | dependencies = [ 486 | "bitflags", 487 | "errno", 488 | "libc", 489 | "linux-raw-sys", 490 | "windows-sys", 491 | ] 492 | 493 | [[package]] 494 | name = "rustversion" 495 | version = "1.0.20" 496 | source = "registry+https://github.com/rust-lang/crates.io-index" 497 | checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" 498 | 499 | [[package]] 500 | name = "ryu" 501 | version = "1.0.16" 502 | source = "registry+https://github.com/rust-lang/crates.io-index" 503 | checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" 504 | 505 | [[package]] 506 | name = "scratch" 507 | version = "1.0.8" 508 | source = "registry+https://github.com/rust-lang/crates.io-index" 509 | checksum = "9f6280af86e5f559536da57a45ebc84948833b3bee313a7dd25232e09c878a52" 510 | 511 | [[package]] 512 | name = "semver" 513 | version = "1.0.26" 514 | source = "registry+https://github.com/rust-lang/crates.io-index" 515 | checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" 516 | dependencies = [ 517 | "serde", 518 | ] 519 | 520 | [[package]] 521 | name = "serde" 522 | version = "1.0.196" 523 | source = "registry+https://github.com/rust-lang/crates.io-index" 524 | checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" 525 | dependencies = [ 526 | "serde_derive", 527 | ] 528 | 529 | [[package]] 530 | name = "serde_derive" 531 | version = "1.0.196" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" 534 | dependencies = [ 535 | "proc-macro2", 536 | "quote", 537 | "syn", 538 | ] 539 | 540 | [[package]] 541 | name = "serde_json" 542 | version = "1.0.140" 543 | source = "registry+https://github.com/rust-lang/crates.io-index" 544 | checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" 545 | dependencies = [ 546 | "itoa", 547 | "memchr", 548 | "ryu", 549 | "serde", 550 | ] 551 | 552 | [[package]] 553 | name = "sharded-slab" 554 | version = "0.1.7" 555 | source = "registry+https://github.com/rust-lang/crates.io-index" 556 | checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" 557 | dependencies = [ 558 | "lazy_static", 559 | ] 560 | 561 | [[package]] 562 | name = "shlex" 563 | version = "1.3.0" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 566 | 567 | [[package]] 568 | name = "smallvec" 569 | version = "1.13.1" 570 | source = "registry+https://github.com/rust-lang/crates.io-index" 571 | checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" 572 | 573 | [[package]] 574 | name = "strsim" 575 | version = "0.11.0" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" 578 | 579 | [[package]] 580 | name = "syn" 581 | version = "2.0.109" 582 | source = "registry+https://github.com/rust-lang/crates.io-index" 583 | checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f" 584 | dependencies = [ 585 | "proc-macro2", 586 | "quote", 587 | "unicode-ident", 588 | ] 589 | 590 | [[package]] 591 | name = "thiserror" 592 | version = "2.0.12" 593 | source = "registry+https://github.com/rust-lang/crates.io-index" 594 | checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" 595 | dependencies = [ 596 | "thiserror-impl", 597 | ] 598 | 599 | [[package]] 600 | name = "thiserror-impl" 601 | version = "2.0.12" 602 | source = "registry+https://github.com/rust-lang/crates.io-index" 603 | checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" 604 | dependencies = [ 605 | "proc-macro2", 606 | "quote", 607 | "syn", 608 | ] 609 | 610 | [[package]] 611 | name = "thread_local" 612 | version = "1.1.7" 613 | source = "registry+https://github.com/rust-lang/crates.io-index" 614 | checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" 615 | dependencies = [ 616 | "cfg-if", 617 | "once_cell", 618 | ] 619 | 620 | [[package]] 621 | name = "tracing" 622 | version = "0.1.41" 623 | source = "registry+https://github.com/rust-lang/crates.io-index" 624 | checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" 625 | dependencies = [ 626 | "pin-project-lite", 627 | "tracing-attributes", 628 | "tracing-core", 629 | ] 630 | 631 | [[package]] 632 | name = "tracing-attributes" 633 | version = "0.1.30" 634 | source = "registry+https://github.com/rust-lang/crates.io-index" 635 | checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" 636 | dependencies = [ 637 | "proc-macro2", 638 | "quote", 639 | "syn", 640 | ] 641 | 642 | [[package]] 643 | name = "tracing-core" 644 | version = "0.1.34" 645 | source = "registry+https://github.com/rust-lang/crates.io-index" 646 | checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" 647 | dependencies = [ 648 | "once_cell", 649 | "valuable", 650 | ] 651 | 652 | [[package]] 653 | name = "tracing-log" 654 | version = "0.2.0" 655 | source = "registry+https://github.com/rust-lang/crates.io-index" 656 | checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" 657 | dependencies = [ 658 | "log", 659 | "once_cell", 660 | "tracing-core", 661 | ] 662 | 663 | [[package]] 664 | name = "tracing-subscriber" 665 | version = "0.3.20" 666 | source = "registry+https://github.com/rust-lang/crates.io-index" 667 | checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" 668 | dependencies = [ 669 | "matchers", 670 | "nu-ansi-term", 671 | "once_cell", 672 | "regex-automata", 673 | "sharded-slab", 674 | "smallvec", 675 | "thread_local", 676 | "tracing", 677 | "tracing-core", 678 | "tracing-log", 679 | ] 680 | 681 | [[package]] 682 | name = "unicode-ident" 683 | version = "1.0.12" 684 | source = "registry+https://github.com/rust-lang/crates.io-index" 685 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 686 | 687 | [[package]] 688 | name = "utf8parse" 689 | version = "0.2.2" 690 | source = "registry+https://github.com/rust-lang/crates.io-index" 691 | checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 692 | 693 | [[package]] 694 | name = "uuid" 695 | version = "1.8.0" 696 | source = "registry+https://github.com/rust-lang/crates.io-index" 697 | checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" 698 | dependencies = [ 699 | "uuid-macro-internal", 700 | ] 701 | 702 | [[package]] 703 | name = "uuid-macro-internal" 704 | version = "1.8.0" 705 | source = "registry+https://github.com/rust-lang/crates.io-index" 706 | checksum = "9881bea7cbe687e36c9ab3b778c36cd0487402e270304e8b1296d5085303c1a2" 707 | dependencies = [ 708 | "proc-macro2", 709 | "quote", 710 | "syn", 711 | ] 712 | 713 | [[package]] 714 | name = "valuable" 715 | version = "0.1.0" 716 | source = "registry+https://github.com/rust-lang/crates.io-index" 717 | checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" 718 | 719 | [[package]] 720 | name = "wdk" 721 | version = "0.4.1" 722 | source = "registry+https://github.com/rust-lang/crates.io-index" 723 | checksum = "1fd496a19ec75c3d98f8be805f62ebde4651fc01babf681b832d8bae9c584d25" 724 | dependencies = [ 725 | "cfg-if", 726 | "tracing", 727 | "tracing-subscriber", 728 | "wdk-build", 729 | "wdk-sys", 730 | ] 731 | 732 | [[package]] 733 | name = "wdk-alloc" 734 | version = "0.4.1" 735 | source = "registry+https://github.com/rust-lang/crates.io-index" 736 | checksum = "0000f9d158618c1dce7de647338e8219f9d6b618abd140c373c0552c6dbda1ca" 737 | dependencies = [ 738 | "tracing", 739 | "tracing-subscriber", 740 | "wdk-build", 741 | "wdk-sys", 742 | ] 743 | 744 | [[package]] 745 | name = "wdk-build" 746 | version = "0.5.1" 747 | source = "registry+https://github.com/rust-lang/crates.io-index" 748 | checksum = "2c150122a579af759770b354064cd2994d29e97525d904f65ff1412ad5122766" 749 | dependencies = [ 750 | "anyhow", 751 | "bindgen", 752 | "camino", 753 | "cargo_metadata", 754 | "cfg-if", 755 | "clap", 756 | "clap-cargo", 757 | "paste", 758 | "regex", 759 | "rustversion", 760 | "semver", 761 | "serde", 762 | "serde_json", 763 | "thiserror", 764 | "tracing", 765 | "windows", 766 | ] 767 | 768 | [[package]] 769 | name = "wdk-macros" 770 | version = "0.5.1" 771 | source = "registry+https://github.com/rust-lang/crates.io-index" 772 | checksum = "b288d5ef6b276345d197fe0b82ef274dcb5a1f658a2294c67ff85b775f63ee26" 773 | dependencies = [ 774 | "cfg-if", 775 | "fs4", 776 | "itertools", 777 | "proc-macro2", 778 | "quote", 779 | "scratch", 780 | "serde", 781 | "serde_json", 782 | "syn", 783 | ] 784 | 785 | [[package]] 786 | name = "wdk-panic" 787 | version = "0.4.1" 788 | source = "registry+https://github.com/rust-lang/crates.io-index" 789 | checksum = "e594cced255434b29bfca586a74653985281377ff4e36b8cfa58fd4c4c63073a" 790 | 791 | [[package]] 792 | name = "wdk-sys" 793 | version = "0.5.1" 794 | source = "registry+https://github.com/rust-lang/crates.io-index" 795 | checksum = "5e13e19ed97609bc1d1236806019309ca2d47aaad6d3217ab374e73c9ff3b8a9" 796 | dependencies = [ 797 | "anyhow", 798 | "bindgen", 799 | "cargo_metadata", 800 | "cc", 801 | "cfg-if", 802 | "rustversion", 803 | "serde_json", 804 | "thiserror", 805 | "tracing", 806 | "tracing-subscriber", 807 | "wdk-build", 808 | "wdk-macros", 809 | ] 810 | 811 | [[package]] 812 | name = "windows" 813 | version = "0.58.0" 814 | source = "registry+https://github.com/rust-lang/crates.io-index" 815 | checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" 816 | dependencies = [ 817 | "windows-core", 818 | "windows-targets", 819 | ] 820 | 821 | [[package]] 822 | name = "windows-core" 823 | version = "0.58.0" 824 | source = "registry+https://github.com/rust-lang/crates.io-index" 825 | checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" 826 | dependencies = [ 827 | "windows-implement", 828 | "windows-interface", 829 | "windows-result", 830 | "windows-strings", 831 | "windows-targets", 832 | ] 833 | 834 | [[package]] 835 | name = "windows-implement" 836 | version = "0.58.0" 837 | source = "registry+https://github.com/rust-lang/crates.io-index" 838 | checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" 839 | dependencies = [ 840 | "proc-macro2", 841 | "quote", 842 | "syn", 843 | ] 844 | 845 | [[package]] 846 | name = "windows-interface" 847 | version = "0.58.0" 848 | source = "registry+https://github.com/rust-lang/crates.io-index" 849 | checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" 850 | dependencies = [ 851 | "proc-macro2", 852 | "quote", 853 | "syn", 854 | ] 855 | 856 | [[package]] 857 | name = "windows-link" 858 | version = "0.2.1" 859 | source = "registry+https://github.com/rust-lang/crates.io-index" 860 | checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 861 | 862 | [[package]] 863 | name = "windows-result" 864 | version = "0.2.0" 865 | source = "registry+https://github.com/rust-lang/crates.io-index" 866 | checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" 867 | dependencies = [ 868 | "windows-targets", 869 | ] 870 | 871 | [[package]] 872 | name = "windows-strings" 873 | version = "0.1.0" 874 | source = "registry+https://github.com/rust-lang/crates.io-index" 875 | checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" 876 | dependencies = [ 877 | "windows-result", 878 | "windows-targets", 879 | ] 880 | 881 | [[package]] 882 | name = "windows-sys" 883 | version = "0.59.0" 884 | source = "registry+https://github.com/rust-lang/crates.io-index" 885 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 886 | dependencies = [ 887 | "windows-targets", 888 | ] 889 | 890 | [[package]] 891 | name = "windows-targets" 892 | version = "0.52.6" 893 | source = "registry+https://github.com/rust-lang/crates.io-index" 894 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 895 | dependencies = [ 896 | "windows_aarch64_gnullvm", 897 | "windows_aarch64_msvc", 898 | "windows_i686_gnu", 899 | "windows_i686_gnullvm", 900 | "windows_i686_msvc", 901 | "windows_x86_64_gnu", 902 | "windows_x86_64_gnullvm", 903 | "windows_x86_64_msvc", 904 | ] 905 | 906 | [[package]] 907 | name = "windows_aarch64_gnullvm" 908 | version = "0.52.6" 909 | source = "registry+https://github.com/rust-lang/crates.io-index" 910 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 911 | 912 | [[package]] 913 | name = "windows_aarch64_msvc" 914 | version = "0.52.6" 915 | source = "registry+https://github.com/rust-lang/crates.io-index" 916 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 917 | 918 | [[package]] 919 | name = "windows_i686_gnu" 920 | version = "0.52.6" 921 | source = "registry+https://github.com/rust-lang/crates.io-index" 922 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 923 | 924 | [[package]] 925 | name = "windows_i686_gnullvm" 926 | version = "0.52.6" 927 | source = "registry+https://github.com/rust-lang/crates.io-index" 928 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 929 | 930 | [[package]] 931 | name = "windows_i686_msvc" 932 | version = "0.52.6" 933 | source = "registry+https://github.com/rust-lang/crates.io-index" 934 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 935 | 936 | [[package]] 937 | name = "windows_x86_64_gnu" 938 | version = "0.52.6" 939 | source = "registry+https://github.com/rust-lang/crates.io-index" 940 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 941 | 942 | [[package]] 943 | name = "windows_x86_64_gnullvm" 944 | version = "0.52.6" 945 | source = "registry+https://github.com/rust-lang/crates.io-index" 946 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 947 | 948 | [[package]] 949 | name = "windows_x86_64_msvc" 950 | version = "0.52.6" 951 | source = "registry+https://github.com/rust-lang/crates.io-index" 952 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 953 | --------------------------------------------------------------------------------