From 22454c750050bcc97150b5543d783e036efff3ae Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 12 Jul 2023 14:47:56 +0200 Subject: [PATCH 1/3] Update to windows-sys v0.52 --- Cargo.toml | 5 ++++- src/sys/windows/afd.rs | 34 ++++++++++-------------------- src/sys/windows/io_status_block.rs | 4 ++-- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90a65d695..b8e3b4ce3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,8 +51,11 @@ log = { version = "0.4.8", optional = true } libc = "0.2.149" [target.'cfg(windows)'.dependencies.windows-sys] -version = "0.48" +version = "0.52" features = [ + "Wdk_Foundation", # Required for AFD. + "Wdk_Storage_FileSystem", # Required for AFD. + "Wdk_System_IO", # Required for AFD. "Win32_Foundation", # Basic types eg HANDLE "Win32_Networking_WinSock", # winsock2 types/functions "Win32_Storage_FileSystem", # Enables NtCreateFile diff --git a/src/sys/windows/afd.rs b/src/sys/windows/afd.rs index 3bda4536c..11373cfca 100644 --- a/src/sys/windows/afd.rs +++ b/src/sys/windows/afd.rs @@ -5,28 +5,15 @@ use std::io; use std::mem::size_of; use std::os::windows::io::AsRawHandle; +use windows_sys::Wdk::Storage::FileSystem::NtCancelIoFileEx; +use windows_sys::Wdk::System::IO::NtDeviceIoControlFile; use windows_sys::Win32::Foundation::{ RtlNtStatusToDosError, HANDLE, NTSTATUS, STATUS_NOT_FOUND, STATUS_PENDING, STATUS_SUCCESS, }; -use windows_sys::Win32::System::WindowsProgramming::{ - NtDeviceIoControlFile, IO_STATUS_BLOCK, IO_STATUS_BLOCK_0, -}; +use windows_sys::Win32::System::IO::{IO_STATUS_BLOCK, IO_STATUS_BLOCK_0}; const IOCTL_AFD_POLL: u32 = 0x00012024; -#[link(name = "ntdll")] -extern "system" { - /// See - /// - /// This is an undocumented API and as such not part of - /// from which `windows-sys` is generated, and also unlikely to be added, so - /// we manually declare it here - fn NtCancelIoFileEx( - FileHandle: HANDLE, - IoRequestToCancel: *mut IO_STATUS_BLOCK, - IoStatusBlock: *mut IO_STATUS_BLOCK, - ) -> NTSTATUS; -} /// Winsock2 AFD driver instance. /// /// All operations are unsafe due to IO_STATUS_BLOCK parameter are being used by Afd driver during STATUS_PENDING before I/O Completion Port returns its result. @@ -132,14 +119,15 @@ cfg_io_source! { use std::ptr::null_mut; use std::sync::atomic::{AtomicUsize, Ordering}; - use super::iocp::CompletionPort; - use windows_sys::Win32::{ - Foundation::{UNICODE_STRING, INVALID_HANDLE_VALUE}, - System::WindowsProgramming::{ - OBJECT_ATTRIBUTES, FILE_SKIP_SET_EVENT_ON_HANDLE, - }, - Storage::FileSystem::{FILE_OPEN, NtCreateFile, SetFileCompletionNotificationModes, SYNCHRONIZE, FILE_SHARE_READ, FILE_SHARE_WRITE}, + use windows_sys::Wdk::Foundation::OBJECT_ATTRIBUTES; + use windows_sys::Wdk::Storage::FileSystem::{NtCreateFile, FILE_OPEN}; + use windows_sys::Win32::Foundation::{INVALID_HANDLE_VALUE, UNICODE_STRING}; + use windows_sys::Win32::Storage::FileSystem::{ + SetFileCompletionNotificationModes, FILE_SHARE_READ, FILE_SHARE_WRITE, SYNCHRONIZE, }; + use windows_sys::Win32::System::WindowsProgramming::FILE_SKIP_SET_EVENT_ON_HANDLE; + + use super::iocp::CompletionPort; const AFD_HELPER_ATTRIBUTES: OBJECT_ATTRIBUTES = OBJECT_ATTRIBUTES { Length: size_of::() as u32, diff --git a/src/sys/windows/io_status_block.rs b/src/sys/windows/io_status_block.rs index d7eda6a6d..bd2a6dcfe 100644 --- a/src/sys/windows/io_status_block.rs +++ b/src/sys/windows/io_status_block.rs @@ -1,12 +1,12 @@ use std::fmt; use std::ops::{Deref, DerefMut}; -use windows_sys::Win32::System::WindowsProgramming::IO_STATUS_BLOCK; +use windows_sys::Win32::System::IO::IO_STATUS_BLOCK; pub struct IoStatusBlock(IO_STATUS_BLOCK); cfg_io_source! { - use windows_sys::Win32::System::WindowsProgramming::{IO_STATUS_BLOCK_0}; + use windows_sys::Win32::System::IO::IO_STATUS_BLOCK_0; impl IoStatusBlock { pub fn zeroed() -> Self { From 7585d8c34d1bae49e034e80c53518d45be715969 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 12 Jul 2023 14:49:32 +0200 Subject: [PATCH 2/3] Add x86_64-pc-windows-gnu target --- Cargo.toml | 1 + Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b8e3b4ce3..e283f58c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,7 @@ targets = [ "aarch64-linux-android", "wasm32-wasi", "x86_64-apple-darwin", + "x86_64-pc-windows-gnu", "x86_64-pc-windows-msvc", "x86_64-unknown-dragonfly", "x86_64-unknown-freebsd", diff --git a/Makefile b/Makefile index 77a284475..5562dcff4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Targets available via Rustup that are supported. -TARGETS ?= aarch64-apple-ios aarch64-linux-android arm-linux-androideabi i686-unknown-linux-gnu x86_64-apple-darwin x86_64-apple-ios x86_64-pc-windows-msvc x86_64-unknown-freebsd x86_64-unknown-illumos x86_64-unknown-linux-gnu x86_64-unknown-netbsd x86_64-unknown-redox wasm32-wasi +TARGETS ?= aarch64-apple-ios aarch64-linux-android arm-linux-androideabi i686-unknown-linux-gnu x86_64-apple-darwin x86_64-apple-ios x86_64-pc-windows-gnu x86_64-pc-windows-msvc x86_64-unknown-freebsd x86_64-unknown-illumos x86_64-unknown-linux-gnu x86_64-unknown-netbsd x86_64-unknown-redox wasm32-wasi # Example value: `nightly-x86_64-apple-darwin`. RUSTUP_TOOLCHAIN ?= $(shell rustup show active-toolchain | cut -d' ' -f1) # Architecture target. Example value: `x86_64-apple-darwin`. From d1d282a5e8481b8271343a3b1570bd63ca0754f0 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Fri, 8 Dec 2023 09:31:55 +0100 Subject: [PATCH 3/3] Fix unused import warning --- src/sys/windows/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sys/windows/mod.rs b/src/sys/windows/mod.rs index f8b72fc49..89d74b1a2 100644 --- a/src/sys/windows/mod.rs +++ b/src/sys/windows/mod.rs @@ -13,7 +13,7 @@ mod overlapped; use overlapped::Overlapped; mod selector; -pub use selector::{Selector, SelectorInner, SockState}; +pub use selector::Selector; // Macros must be defined before the modules that use them cfg_net! { @@ -35,6 +35,8 @@ cfg_net! { pub(crate) mod tcp; pub(crate) mod udp; + + pub use selector::{SelectorInner, SockState}; } cfg_os_ext! {