diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 601c12d..d14119f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -106,6 +106,21 @@ jobs: with: tool: cargo-make + # Cargo's build-dir layout v2 nests rust-script's long package name twice, + # pushing the cargo-make load_script binary's output path past 260 + # characters (MAX_PATH). MSVC's link.exe does not support longer paths, + # so linking fails with LNK1104 (cannot open file). + # rust-script runs cargo from %LOCALAPPDATA%\rust-script\projects\, so + # this config shortens build-dir for rust-script builds only. A global + # build-dir would break wdk-build, which looks for Cargo.lock above OUT_DIR. + - name: Shorten rust-script build-dir + run: | + $configDir = Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) 'rust-script\.cargo' + New-Item -ItemType Directory -Force $configDir | Out-Null + $buildDir = (Join-Path $env:RUNNER_TEMP 'rsb') -replace '\\', '/' + Set-Content (Join-Path $configDir 'config.toml') "[build]`nbuild-dir = '$buildDir'" + shell: pwsh + - name: Build and Package Sample Drivers # Unset RUSTFLAGS for cargo-make to work around RUSTFLAGS leaking into # rust-script compilation of wdk-build (path dep via symlink defeats diff --git a/Cargo.lock b/Cargo.lock index 7eb6e8a..45acafe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,7 +47,7 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -58,32 +58,31 @@ checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] name = "anyhow" -version = "1.0.98" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" [[package]] name = "bindgen" -version = "0.71.1" +version = "0.73.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa" dependencies = [ "bitflags", "cexpr", "clang-sys", - "itertools", "log", "prettyplease", "proc-macro2", "quote", "regex", "rustc-hash", - "shlex", + "shlex 2.0.1", "syn", ] @@ -95,27 +94,28 @@ checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "camino" -version = "1.1.9" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +checksum = "bbbad30e4b4c14a39e3cc8aed085a12a327257c316619c93581e017bc52be591" dependencies = [ - "serde", + "serde_core", ] [[package]] name = "cargo-platform" -version = "0.1.7" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "694c8807f2ae16faecc43dc17d74b3eb042482789fd0eb64b39a2e04e087053f" +checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba" dependencies = [ "serde", + "serde_core", ] [[package]] name = "cargo_metadata" -version = "0.19.2" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" +checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9" dependencies = [ "camino", "cargo-platform", @@ -132,7 +132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe" dependencies = [ "find-msvc-tools", - "shlex", + "shlex 1.3.0", ] [[package]] @@ -173,9 +173,9 @@ dependencies = [ [[package]] name = "clap-cargo" -version = "0.15.2" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d546f0e84ff2bfa4da1ce9b54be42285767ba39c688572ca32412a09a73851e5" +checksum = "ac0fb996b5acdd543c8b8ff723c719715d437fdce607ac1fda01c977f568020d" dependencies = [ "anstyle", "clap", @@ -236,7 +236,7 @@ version = "0.1.0" dependencies = [ "once_cell", "uuid", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -252,7 +252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -275,12 +275,12 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" [[package]] name = "fs4" -version = "0.13.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4" +checksum = "7e72ed92b67c146290f88e9c89d60ca163ea417a446f61ffd7b72df3e7f1dfd5" dependencies = [ "rustix", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -303,9 +303,9 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "itertools" -version = "0.13.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" dependencies = [ "either", ] @@ -387,7 +387,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -487,7 +487,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -496,12 +496,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" -[[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - [[package]] name = "scratch" version = "1.0.8" @@ -510,27 +504,38 @@ checksum = "9f6280af86e5f559536da57a45ebc84948833b3bee313a7dd25232e09c878a52" [[package]] name = "semver" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" dependencies = [ "serde", + "serde_core", ] [[package]] name = "serde" -version = "1.0.196" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -539,14 +544,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", "memchr", - "ryu", "serde", + "serde_core", + "zmij", ] [[package]] @@ -564,6 +570,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + [[package]] name = "smallvec" version = "1.13.1" @@ -718,9 +730,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "wdk" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd496a19ec75c3d98f8be805f62ebde4651fc01babf681b832d8bae9c584d25" +checksum = "7a4be5148364938f4fbebceeb2db8d57c686e9c3282c9851191193eb09160e46" dependencies = [ "cfg-if", "tracing", @@ -731,9 +743,9 @@ dependencies = [ [[package]] name = "wdk-alloc" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0000f9d158618c1dce7de647338e8219f9d6b618abd140c373c0552c6dbda1ca" +checksum = "60b694f1faaa8caad4b3b4f9c5875984482ac7c30eacdca06c3f40840d739dc5" dependencies = [ "tracing", "tracing-subscriber", @@ -743,9 +755,9 @@ dependencies = [ [[package]] name = "wdk-build" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c150122a579af759770b354064cd2994d29e97525d904f65ff1412ad5122766" +checksum = "16f5c1804e317c1a316c5c8b81df269eaa4df220d03fb6b47315c298f21a592f" dependencies = [ "anyhow", "bindgen", @@ -767,9 +779,9 @@ dependencies = [ [[package]] name = "wdk-macros" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b288d5ef6b276345d197fe0b82ef274dcb5a1f658a2294c67ff85b775f63ee26" +checksum = "76c0b7b42d1742fb231a330a86b0b8d035b526f2f63896156f51a2da3d41e381" dependencies = [ "cfg-if", "fs4", @@ -784,15 +796,21 @@ dependencies = [ [[package]] name = "wdk-panic" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e594cced255434b29bfca586a74653985281377ff4e36b8cfa58fd4c4c63073a" +checksum = "0a7bd2b0ef836921f74a7b61bbe90c9b2b76b8fc438d4b1666f3942f667c7b76" +dependencies = [ + "tracing", + "tracing-subscriber", + "wdk", + "wdk-build", +] [[package]] name = "wdk-sys" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e13e19ed97609bc1d1236806019309ca2d47aaad6d3217ab374e73c9ff3b8a9" +checksum = "e2799500b02cd6362c902412a9d5bed0dee70fa12e61fc90c72372594baee55f" dependencies = [ "anyhow", "bindgen", @@ -810,32 +828,54 @@ dependencies = [ [[package]] name = "windows" -version = "0.58.0" +version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" dependencies = [ "windows-core", - "windows-targets", ] [[package]] name = "windows-core" -version = "0.58.0" +version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ "windows-implement", "windows-interface", + "windows-link", "windows-result", "windows-strings", - "windows-targets", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", ] [[package]] name = "windows-implement" -version = "0.58.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", @@ -844,9 +884,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.58.0" +version = "0.59.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", @@ -859,23 +899,32 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core", + "windows-link", +] + [[package]] name = "windows-result" -version = "0.2.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" dependencies = [ - "windows-targets", + "windows-link", ] [[package]] name = "windows-strings" -version = "0.1.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" dependencies = [ - "windows-result", - "windows-targets", + "windows-link", ] [[package]] @@ -887,6 +936,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -903,6 +961,15 @@ dependencies = [ "windows_x86_64_msvc", ] +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -950,3 +1017,9 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml index dbc4cce..6bdb116 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,10 @@ panic = "abort" lto = true [workspace.dependencies] -anyhow = "1.0.89" +anyhow = "1.0.103" paste = "1.0.14" -wdk = "0.4.1" -wdk-alloc = "0.4.1" -wdk-build = "0.5.1" -wdk-panic = "0.4.1" -wdk-sys = "0.5.1" +wdk = "0.5.0" +wdk-alloc = "0.4.2" +wdk-build = "0.6.0" +wdk-panic = "0.5.0" +wdk-sys = "0.5.2" diff --git a/Makefile.toml b/Makefile.toml index 68891ff..196ba70 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -11,7 +11,7 @@ load_script = ''' #!@rust //! ```cargo //! [dependencies] -//! wdk-build = "0.4.0" +//! wdk-build = "0.6.0" //! ``` #![allow(unused_doc_comments)] diff --git a/general/echo/kmdf/driver/DriverSync/src/device.rs b/general/echo/kmdf/driver/DriverSync/src/device.rs index 77af6ca..378cf4b 100644 --- a/general/echo/kmdf/driver/DriverSync/src/device.rs +++ b/general/echo/kmdf/driver/DriverSync/src/device.rs @@ -47,8 +47,8 @@ use crate::{ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS { paged_code!(); - // Register pnp/power callbacks so that we can start and stop the timer as the - // device gets started and stopped. + // Register pnp/power callbacks so that we can start and stop the timer as + // the device gets started and stopped. let mut pnp_power_callbacks = WDF_PNPPOWER_EVENT_CALLBACKS { Size: WDF_PNPPOWER_EVENT_CALLBACKS_SIZE, EvtDeviceSelfManagedIoInit: Some(echo_evt_device_self_managed_io_start), @@ -58,8 +58,8 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS { ..WDF_PNPPOWER_EVENT_CALLBACKS::default() }; - // Register the PnP and power callbacks. Power policy related callbacks will be - // registered later in SotwareInit. + // Register the PnP and power callbacks. Power policy related callbacks will + // be registered later in SotwareInit. unsafe { call_unsafe_wdf_function_binding!( WdfDeviceInitSetPnpPowerEventCallbacks, @@ -103,10 +103,10 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS { }; if nt_success(nt_status) { - // Get the device context and initialize it. WdfObjectGet_DEVICE_CONTEXT is an - // inline function generated by WDF_DECLARE_CONTEXT_TYPE macro in the - // device.h header file. This function will do the type checking and return - // the device context. If you pass a wrong object handle + // Get the device context and initialize it. WdfObjectGet_DEVICE_CONTEXT + // is an inline function generated by WDF_DECLARE_CONTEXT_TYPE macro in + // the device.h header file. This function will do the type checking and + // return the device context. If you pass a wrong object handle // it will return NULL and assert if run under framework verifier mode. let device_context: *mut DeviceContext = unsafe { wdf_object_get_device_context(device as WDFOBJECT) }; @@ -162,7 +162,8 @@ extern "C" fn echo_evt_device_self_managed_io_start(device: WDFDEVICE) -> NTSTAT "SYSTEM_TIME_UNITS should fit in i64" ); }; - // Negative marks the value as a relative (rather than absolute) timeout. + // Negative marks the value as a relative (rather than absolute) + // timeout. -(SYSTEM_TIME_UNITS as i64) }; @@ -213,18 +214,18 @@ unsafe extern "C" fn echo_evt_device_self_managed_io_suspend(device: WDFDEVICE) // i/o. We need to do that because framework cannot suspend the device // if there are requests owned by the driver. There are two ways to solve // this issue: 1) We can wait for the outstanding I/O to be complete by the - // periodic timer 2) Register EvtIoStop callback on the queue and acknowledge - // the request to inform the framework that it's okay to suspend the device - // with outstanding I/O. In this sample we will use the 1st approach - // because it's pretty easy to do. We will restart the queue when the - // device is restarted. + // periodic timer 2) Register EvtIoStop callback on the queue and + // acknowledge the request to inform the framework that it's okay to suspend + // the device with outstanding I/O. In this sample we will use the 1st + // approach because it's pretty easy to do. We will restart the queue when + // the device is restarted. let queue = unsafe { call_unsafe_wdf_function_binding!(WdfDeviceGetDefaultQueue, device) }; let queue_context = unsafe { queue_get_context(queue as WDFOBJECT) }; unsafe { call_unsafe_wdf_function_binding!(WdfIoQueueStopSynchronously, queue); - // Stop the watchdog timer and wait for DPC to run to completion if it's already - // fired. + // Stop the watchdog timer and wait for DPC to run to completion if it's + // already fired. let _ = (*queue_context).timer.stop(true); }; diff --git a/general/echo/kmdf/driver/DriverSync/src/queue.rs b/general/echo/kmdf/driver/DriverSync/src/queue.rs index 1439cba..afde22c 100644 --- a/general/echo/kmdf/driver/DriverSync/src/queue.rs +++ b/general/echo/kmdf/driver/DriverSync/src/queue.rs @@ -77,9 +77,10 @@ fn echo_interlocked_increment_floor(target: &AtomicI32, floor: i32) -> i32 { Ordering::SeqCst, Ordering::SeqCst, ) { - // If oldValue == currentValue, then no one updated Target in between - // the deref at the top and the InterlockecCompareExchange afterward - // and we have successfully incremented the value and can exit the loop. + // If oldValue == currentValue, then no one updated Target in + // between the deref at the top and the InterlockecCompareExchange + // afterward and we have successfully incremented the value and can + // exit the loop. Ok(_) => break, Err(v) => current_value = v, } @@ -287,7 +288,8 @@ fn echo_decrement_request_cancel_ownership_count(request_context: *mut RequestCo /// /// * TRUE if the count was incremented, FALSE otherwise fn echo_increment_request_cancel_ownership_count(request_context: *mut RequestContext) -> bool { - // See comments in echo_interlocked_increment_floor as to why <= 1 is failure + // See comments in echo_interlocked_increment_floor as to why <= 1 is + // failure // (unsafe { echo_interlocked_increment_gtzero(&(*request_context).cancel_completion_ownership_count) @@ -498,10 +500,10 @@ extern "C" fn echo_evt_io_read(queue: WDFQUEUE, request: WDFREQUEST, mut length: )] }; - // Mark the request is cancelable. This must be the last thing we do because - // the cancel routine can run immediately after we set it. This means that - // CurrentRequest and CurrentStatus must be initialized before we mark the - // request cancelable. + // Mark the request is cancelable. This must be the last thing we do + // because the cancel routine can run immediately after we set it. This + // means that CurrentRequest and CurrentStatus must be initialized before we + // mark the request cancelable. echo_set_current_request(request, queue); } @@ -623,10 +625,10 @@ extern "C" fn echo_evt_io_write(queue: WDFQUEUE, request: WDFREQUEST, length: us call_unsafe_wdf_function_binding!(WdfRequestSetInformation, request, length as u64); } - // Mark the request is cancelable. This must be the last thing we do because - // the cancel routine can run immediately after we set it. This means that - // CurrentRequest and CurrentStatus must be initialized before we mark the - // request cancelable. + // Mark the request is cancelable. This must be the last thing we do + // because the cancel routine can run immediately after we set it. This + // means that CurrentRequest and CurrentStatus must be initialized before we + // mark the request cancelable. echo_set_current_request(request, queue); } diff --git a/general/echo/kmdf/exe/src/main.rs b/general/echo/kmdf/exe/src/main.rs index 22590d6..4d2685f 100644 --- a/general/echo/kmdf/exe/src/main.rs +++ b/general/echo/kmdf/exe/src/main.rs @@ -134,8 +134,9 @@ Exit the app anytime by pressing Ctrl-C return Err(format!( "Failed to open device. Error {}", // SAFETY: - // - FFI contract: Called immediately after CreateFileW failure before any intervening - // Win32/CRT calls that would overwrite thread-local error slot + // - FFI contract: Called immediately after CreateFileW failure + // before any intervening Win32/CRT calls that would overwrite + // thread-local error slot // - Concurrency: Reads thread-local storage only (no data races) // - Memory safety: Returns u32 value (no pointer dereferences) unsafe { GetLastError() } @@ -151,8 +152,8 @@ Exit the app anytime by pressing Ctrl-C let h = thread::spawn(|| -> Result<(), Box> { async_io(READER_TYPE) }); - // Because async_io error requires Send + Sync but this function does not, - // cannot use ? operator + // Because async_io error requires Send + Sync but this function does + // not, cannot use ? operator #[allow(clippy::question_mark)] if let Err(e) = async_io(WRITER_TYPE) { return Err(e); @@ -218,8 +219,9 @@ fn perform_write_read_test(h_device: HANDLE, test_length: u32) -> Result<(), Box return Err(format!( "PerformWriteReadTest: WriteFile failed: Error {}", // SAFETY: - // - FFI contract: Called immediately after WriteFile failure before any intervening - // Win32/CRT calls that would overwrite thread-local error slot + // - FFI contract: Called immediately after WriteFile failure before + // any intervening Win32/CRT calls that would overwrite + // thread-local error slot // - Concurrency: Reads thread-local storage only (no data races) // - Memory safety: Returns u32 value (no pointer dereferences) unsafe { GetLastError() } @@ -254,8 +256,9 @@ fn perform_write_read_test(h_device: HANDLE, test_length: u32) -> Result<(), Box return Err(format!( "PerformWriteReadTest: ReadFile failed: Error {}", // SAFETY: - // - FFI contract: Called immediately after ReadFile failure before any intervening - // Win32/CRT calls that would overwrite thread-local error slot + // - FFI contract: Called immediately after ReadFile failure before + // any intervening Win32/CRT calls that would overwrite + // thread-local error slot // - Concurrency: Reads thread-local storage only (no data races) // - Memory safety: Returns u32 value (no pointer dereferences) unsafe { GetLastError() } @@ -264,8 +267,8 @@ fn perform_write_read_test(h_device: HANDLE, test_length: u32) -> Result<(), Box } // SAFETY: - // Call set_len on the Vec that contains the buffer used in ReadFile to tell the - // Vec how many bytes were actually put into the Vec + // Call set_len on the Vec that contains the buffer used in ReadFile to tell + // the Vec how many bytes were actually put into the Vec unsafe { read_buffer.set_len(usize::try_from(bytes_returned).unwrap()); } @@ -334,8 +337,9 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { "Cannot open {} error {}", globals.device_path, // SAFETY: - // - FFI contract: Called immediately after CreateFileW failure before any intervening - // Win32/CRT calls that would overwrite thread-local error slot + // - FFI contract: Called immediately after CreateFileW failure + // before any intervening Win32/CRT calls that would overwrite + // thread-local error slot // - Concurrency: Reads thread-local storage only (no data races) // - Memory safety: Returns u32 value (no pointer dereferences) unsafe { GetLastError() } @@ -344,8 +348,8 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { } // SAFETY: - // Call Win32 API FFI CreateIoCompletionPort to get handle for completing async - // requests + // Call Win32 API FFI CreateIoCompletionPort to get handle for completing + // async requests unsafe { h_completion_port = CreateIoCompletionPort( h_device, @@ -359,8 +363,9 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { return Err(format!( "Cannot open completion port {}", // SAFETY: - // - FFI contract: Called immediately after CreateIoCompletionPort failure before any - // intervening Win32/CRT calls that would overwrite thread-local error slot + // - FFI contract: Called immediately after CreateIoCompletionPort + // failure before any intervening Win32/CRT calls that would + // overwrite thread-local error slot // - Concurrency: Reads thread-local storage only (no data races) // - Memory safety: Returns u32 value (no pointer dereferences) unsafe { GetLastError() } @@ -397,7 +402,8 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { for i in 0..max_pending_requests { // SAFETY: - // Get the offset into the buffer for sending data at offset for request 'i' + // Get the offset into the buffer for sending data at offset for request + // 'i' let buffer_offset = unsafe { (buf.as_mut_ptr() .offset(isize::try_from(i * BUFFER_SIZE).unwrap())) @@ -405,14 +411,15 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { }; // SAFETY: - // Get the pointer for the list of Overlapped array for ReadFile at the offset - // for request 'i' + // Get the pointer for the list of Overlapped array for ReadFile at the + // offset for request 'i' let overlap_struct_offset = unsafe { ov_list.as_mut_ptr().offset(isize::try_from(i).unwrap()) }; if io_type == READER_TYPE { // SAFETY: - // Call Win32 API FFI ReadFile to read from driver with an overlap option + // Call Win32 API FFI ReadFile to read from driver with an overlap + // option unsafe { r = ReadFile( h_device, @@ -425,9 +432,11 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { if r == FALSE { // SAFETY: - // - FFI contract: Called immediately after ReadFile failure before any - // intervening Win32/CRT calls that would overwrite thread-local error slot - // - Concurrency: Reads thread-local storage only (no data races) + // - FFI contract: Called immediately after ReadFile failure + // before any intervening Win32/CRT calls that would overwrite + // thread-local error slot + // - Concurrency: Reads thread-local storage only (no data + // races) // - Memory safety: Returns u32 value (no pointer dereferences) let error = unsafe { GetLastError() }; if error != ERROR_IO_PENDING { @@ -436,7 +445,8 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { } } else { // SAFETY: - // Call Win32 API FFI WriteFile to write to driver with an overlap option + // Call Win32 API FFI WriteFile to write to driver with an overlap + // option unsafe { let mut number_of_bytes_written: u32 = 0; @@ -451,9 +461,11 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { if r == FALSE { // SAFETY: - // - FFI contract: Called immediately after WriteFile failure before any - // intervening Win32/CRT calls that would overwrite thread-local error slot - // - Concurrency: Reads thread-local storage only (no data races) + // - FFI contract: Called immediately after WriteFile failure + // before any intervening Win32/CRT calls that would overwrite + // thread-local error slot + // - Concurrency: Reads thread-local storage only (no data + // races) // - Memory safety: Returns u32 value (no pointer dereferences) let error = unsafe { GetLastError() }; if error != ERROR_IO_PENDING { @@ -469,8 +481,8 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { let mut completed_ov_ptr: *mut OVERLAPPED = std::ptr::null_mut(); // SAFETY: - // Call Win32 API FFI GetQueuedCompletionStatus to access the status of the - // completion request + // Call Win32 API FFI GetQueuedCompletionStatus to access the status of + // the completion request unsafe { r = GetQueuedCompletionStatus( h_completion_port, @@ -485,10 +497,12 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { return Err(format!( "GetQueuedCompletionStatus failed {}", // SAFETY: - // - FFI contract: Called immediately after GetQueuedCompletionStatus failure - // before any intervening Win32/CRT calls that would overwrite thread-local error + // - FFI contract: Called immediately after + // GetQueuedCompletionStatus failure before any intervening + // Win32/CRT calls that would overwrite thread-local error // slot - // - Concurrency: Reads thread-local storage only (no data races) + // - Concurrency: Reads thread-local storage only (no data + // races) // - Memory safety: Returns u32 value (no pointer dereferences) unsafe { GetLastError() } ) @@ -498,9 +512,9 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { let i; // SAFETY: - // Perform pointer math to determine which index 'i' to use by determining the - // offset of 'completed_ov_ptr' from the start of the array given by - // 'ov_list' + // Perform pointer math to determine which index 'i' to use by + // determining the offset of 'completed_ov_ptr' from the start of the + // array given by 'ov_list' unsafe { i = completed_ov_ptr.offset_from(ov_list.as_ptr()); } @@ -524,7 +538,8 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { let buffer_offset; // SAFETY: - // Get the offset into the buffer for reading data at offset for request 'i' + // Get the offset into the buffer for reading data at offset for + // request 'i' unsafe { buffer_offset = (buf .as_mut_ptr() @@ -546,9 +561,11 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { if r == FALSE { // SAFETY: - // - FFI contract: Called immediately after ReadFile failure before any - // intervening Win32/CRT calls that would overwrite thread-local error slot - // - Concurrency: Reads thread-local storage only (no data races) + // - FFI contract: Called immediately after ReadFile failure + // before any intervening Win32/CRT calls that would overwrite + // thread-local error slot + // - Concurrency: Reads thread-local storage only (no data + // races) // - Memory safety: Returns u32 value (no pointer dereferences) let error = unsafe { GetLastError() }; if error != ERROR_IO_PENDING { @@ -576,7 +593,8 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { let buffer_offset; // SAFETY: - // Get the offset into the buffer for sending data at offset for request 'i' + // Get the offset into the buffer for sending data at offset for + // request 'i' unsafe { buffer_offset = (buf .as_mut_ptr() @@ -598,9 +616,11 @@ fn async_io_work(io_type: u32) -> Result<(), Box> { if r == FALSE { // SAFETY: - // - FFI contract: Called immediately after WriteFile failure before any - // intervening Win32/CRT calls that would overwrite thread-local error slot - // - Concurrency: Reads thread-local storage only (no data races) + // - FFI contract: Called immediately after WriteFile failure + // before any intervening Win32/CRT calls that would overwrite + // thread-local error slot + // - Concurrency: Reads thread-local storage only (no data + // races) // - Memory safety: Returns u32 value (no pointer dereferences) let error = unsafe { GetLastError() }; if error != ERROR_IO_PENDING { @@ -641,8 +661,8 @@ fn get_device_path(interface_guid: &Uuid) -> Result<(), Box> { guid.data4 = *guid_data4; // SAFETY: - // Call Win32 API FFI CM_Get_Device_Interface_List_SizeW to determine size of - // space needed for a subsequent request + // Call Win32 API FFI CM_Get_Device_Interface_List_SizeW to determine size + // of space needed for a subsequent request unsafe { config_ret = DeviceAndDriverInstallation::CM_Get_Device_Interface_List_SizeW( &mut device_interface_list_length, @@ -668,8 +688,8 @@ fn get_device_path(interface_guid: &Uuid) -> Result<(), Box> { let buffer_ptr = buffer.as_mut_ptr(); // SAFETY: - // Call Win32 API FFI CM_Get_Device_Interface_ListW to get the list of Device - // Interfaces that match the Interface GUID for the echo driver + // Call Win32 API FFI CM_Get_Device_Interface_ListW to get the list of + // Device Interfaces that match the Interface GUID for the echo driver unsafe { config_ret = DeviceAndDriverInstallation::CM_Get_Device_Interface_ListW( &guid, diff --git a/tools/dv/kmdf/fail_driver_pool_leak/src/driver.rs b/tools/dv/kmdf/fail_driver_pool_leak/src/driver.rs index 2fcfbb1..9e05f51 100644 --- a/tools/dv/kmdf/fail_driver_pool_leak/src/driver.rs +++ b/tools/dv/kmdf/fail_driver_pool_leak/src/driver.rs @@ -60,8 +60,8 @@ extern "system" fn driver_entry( { const WDF_DRIVER_CONFIG_SIZE: usize = core::mem::size_of::(); - // Manually assert there is not truncation since clippy doesn't work for - // compile-time constants + // Manually assert there is not truncation since clippy doesn't work + // for compile-time constants const { assert!(WDF_DRIVER_CONFIG_SIZE <= ULONG::MAX as usize) } wdf_driver_config_size = WDF_DRIVER_CONFIG_SIZE as ULONG; @@ -187,8 +187,9 @@ extern "C" fn evt_driver_unload(_driver: WDFDRIVER) { println!("Enter: evt_driver_unload"); // Ideally, the memory allocated to the Global buffer in lib.rs L51 should - // be freed here by calling the ExFreePool API. But to demonstrate the Driver - // Verifier's ability to catch pool leaks, the buffer is deliberately not freed. + // be freed here by calling the ExFreePool API. But to demonstrate the + // Driver Verifier's ability to catch pool leaks, the buffer is deliberately + // not freed. // unsafe { wdk_sys::ntddk::ExFreePool(GLOBAL_BUFFER) };