From f8046f7b12106100f2576f912573cf75973e3163 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Jun 2025 00:57:51 +0000 Subject: [PATCH 1/8] Initial plan for issue From a24c5eb12da4c6b81a58573ad5404a1c1c13bfb2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Jun 2025 01:08:52 +0000 Subject: [PATCH 2/8] Migrate PAL main windows.rs from winapi to windows crate Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- support/pal/Cargo.toml | 8 ++++- support/pal/src/windows.rs | 69 +++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/support/pal/Cargo.toml b/support/pal/Cargo.toml index 2fd0a9c01b..9494cad5f6 100644 --- a/support/pal/Cargo.toml +++ b/support/pal/Cargo.toml @@ -54,7 +54,13 @@ workspace = true features = [ "Wdk_Foundation", "Win32_Foundation", - "Win32_Security" + "Win32_Security", + "Win32_System_IO", + "Win32_System_Threading", + "Win32_System_ErrorReporting", + "Win32_System_Memory", + "Win32_Networking_WinSock", + "Win32_Storage_FileSystem" ] [target.'cfg(unix)'.dependencies] diff --git a/support/pal/src/windows.rs b/support/pal/src/windows.rs index 02e7681442..403adb58ab 100644 --- a/support/pal/src/windows.rs +++ b/support/pal/src/windows.rs @@ -17,7 +17,6 @@ pub mod security; pub mod tp; use self::security::SecurityDescriptor; -use handleapi::INVALID_HANDLE_VALUE; use ntapi::ntioapi::FILE_COMPLETION_INFORMATION; use ntapi::ntioapi::FileReplaceCompletionInformation; use ntapi::ntioapi::IO_STATUS_BLOCK; @@ -34,7 +33,6 @@ use ntrtl::RtlAllocateHeap; use ntrtl::RtlDosPathNameToNtPathName_U_WithStatus; use ntrtl::RtlFreeUnicodeString; use ntrtl::RtlNtStatusToDosErrorNoTeb; -use processthreadsapi::GetExitCodeProcess; use std::cell::UnsafeCell; use std::ffi::OsStr; use std::ffi::c_void; @@ -55,32 +53,33 @@ use std::sync::atomic::Ordering; use std::time::Duration; use widestring::U16CString; use widestring::Utf16Str; -use winapi::shared::ntdef; -use winapi::shared::ntdef::NTSTATUS; -use winapi::shared::ntstatus; -use winapi::shared::ntstatus::STATUS_PENDING; -use winapi::shared::winerror::ERROR_BAD_PATHNAME; -use winapi::shared::ws2def; -use winapi::um::errhandlingapi::GetErrorMode; -use winapi::um::errhandlingapi::SetErrorMode; -use winapi::um::handleapi; -use winapi::um::handleapi::CloseHandle; -use winapi::um::heapapi::GetProcessHeap; -use winapi::um::ioapiset::CreateIoCompletionPort; -use winapi::um::ioapiset::GetQueuedCompletionStatusEx; -use winapi::um::ioapiset::PostQueuedCompletionStatus; -use winapi::um::minwinbase::OVERLAPPED; -use winapi::um::minwinbase::OVERLAPPED_ENTRY; -use winapi::um::processenv::SetStdHandle; -use winapi::um::processthreadsapi; -use winapi::um::processthreadsapi::TerminateProcess; -use winapi::um::synchapi; -use winapi::um::winbase::INFINITE; -use winapi::um::winbase::SEM_FAILCRITICALERRORS; -use winapi::um::winbase::STD_OUTPUT_HANDLE; -use winapi::um::winbase::SetFileCompletionNotificationModes; -use winapi::um::winnt; -use winapi::um::winsock2; +use windows::Win32::Foundation::CloseHandle; +use windows::Win32::Foundation::DuplicateHandle; +use windows::Win32::Foundation::DUPLICATE_SAME_ACCESS; +use windows::Win32::Foundation::ERROR_BAD_PATHNAME; +use windows::Win32::Foundation::INVALID_HANDLE_VALUE; +use windows::Win32::Foundation::NTSTATUS; +use windows::Win32::Foundation::STATUS_PENDING; +use windows::Win32::Foundation::INFINITE; +use windows::Win32::System::ErrorReporting::GetErrorMode; +use windows::Win32::System::ErrorReporting::SetErrorMode; +use windows::Win32::System::ErrorReporting::SEM_FAILCRITICALERRORS; +use windows::Win32::System::IO::CreateIoCompletionPort; +use windows::Win32::System::IO::GetQueuedCompletionStatusEx; +use windows::Win32::System::IO::PostQueuedCompletionStatus; +use windows::Win32::System::IO::OVERLAPPED; +use windows::Win32::System::IO::OVERLAPPED_ENTRY; +use windows::Win32::System::Memory::GetProcessHeap; +use windows::Win32::System::Threading::GetCurrentProcess; +use windows::Win32::System::Threading::GetExitCodeProcess; +use windows::Win32::System::Threading::GetProcessId; +use windows::Win32::System::Threading::SetStdHandle; +use windows::Win32::System::Threading::TerminateProcess; +use windows::Win32::System::Threading::STD_OUTPUT_HANDLE; +use windows::Win32::System::Threading::WaitForSingleObject; +use windows::Win32::Storage::FileSystem::SetFileCompletionNotificationModes; +use windows::Win32::Networking::WinSock::IOC_IN; +use windows::Win32::Networking::WinSock::IOC_VENDOR; #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -99,11 +98,11 @@ impl BorrowedHandleExt for BorrowedHandle<'_> { let options = if access.is_some() { 0 } else { - winnt::DUPLICATE_SAME_ACCESS + DUPLICATE_SAME_ACCESS }; unsafe { - let process = processthreadsapi::GetCurrentProcess(); - if handleapi::DuplicateHandle( + let process = GetCurrentProcess(); + if DuplicateHandle( process, self.as_raw_handle(), process, @@ -134,8 +133,8 @@ pub trait OwnedSocketExt: Sized { fn from_handle(handle: OwnedHandle) -> Result; } -const SIO_SOCKET_TRANSFER_BEGIN: u32 = ws2def::IOC_IN | ws2def::IOC_VENDOR | 301; -const SIO_SOCKET_TRANSFER_END: u32 = ws2def::IOC_IN | ws2def::IOC_VENDOR | 302; +const SIO_SOCKET_TRANSFER_BEGIN: u32 = IOC_IN | IOC_VENDOR | 301; +const SIO_SOCKET_TRANSFER_END: u32 = IOC_IN | IOC_VENDOR | 302; /// Ensures WSAStartup has been called for the process. fn init_winsock() { @@ -209,7 +208,7 @@ struct WaitObject(OwnedHandle); impl WaitObject { fn wait(&self) { - assert!(unsafe { synchapi::WaitForSingleObject(self.0.as_raw_handle(), INFINITE) } == 0); + assert!(unsafe { WaitForSingleObject(self.0.as_raw_handle(), INFINITE) } == 0); } } @@ -233,7 +232,7 @@ impl Process { pub fn id(&self) -> u32 { unsafe { - let pid = processthreadsapi::GetProcessId(self.as_handle().as_raw_handle()); + let pid = GetProcessId(self.as_handle().as_raw_handle()); assert_ne!(pid, 0); pid } From 7a389f38e433e6729d6e29743b6aa107caf8e927 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Jun 2025 01:12:59 +0000 Subject: [PATCH 3/8] Migrate PAL security.rs, tp.rs, alpc.rs and disk_vhdmp from winapi to windows Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- Cargo.lock | 2 +- support/pal/Cargo.toml | 4 ++- support/pal/src/windows/alpc.rs | 6 ++-- support/pal/src/windows/security.rs | 40 ++++++++++----------- support/pal/src/windows/tp.rs | 44 ++++++++++++------------ vm/devices/storage/disk_vhdmp/Cargo.toml | 2 +- vm/devices/storage/disk_vhdmp/src/lib.rs | 8 ++--- 7 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd4f79aa93..9f4d99d3ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1374,7 +1374,7 @@ dependencies = [ "tempfile", "thiserror 2.0.12", "vm_resource", - "winapi", + "windows 0.59.0", ] [[package]] diff --git a/support/pal/Cargo.toml b/support/pal/Cargo.toml index 9494cad5f6..595d4a9f60 100644 --- a/support/pal/Cargo.toml +++ b/support/pal/Cargo.toml @@ -55,10 +55,12 @@ features = [ "Wdk_Foundation", "Win32_Foundation", "Win32_Security", + "Win32_Security_Authorization", "Win32_System_IO", "Win32_System_Threading", "Win32_System_ErrorReporting", - "Win32_System_Memory", + "Win32_System_Memory", + "Win32_System_SystemServices", "Win32_Networking_WinSock", "Win32_Storage_FileSystem" ] diff --git a/support/pal/src/windows/alpc.rs b/support/pal/src/windows/alpc.rs index 8b84d43aa7..57d7aba80a 100644 --- a/support/pal/src/windows/alpc.rs +++ b/support/pal/src/windows/alpc.rs @@ -18,14 +18,14 @@ use std::os::windows::prelude::*; use std::ptr::NonNull; use std::ptr::null_mut; use std::time::Duration; -use winapi::shared::ntstatus::STATUS_TIMEOUT; +use windows::Win32::Foundation::STATUS_TIMEOUT; mod ntlpcapi { #![allow(non_snake_case, dead_code, clippy::upper_case_acronyms)] pub use ntapi::ntlpcapi::*; - use winapi::shared::ntdef::HANDLE; - use winapi::shared::ntdef::NTSTATUS; + use windows::Win32::Foundation::HANDLE; + use windows::Win32::Foundation::NTSTATUS; // These constants are not defined in ntapi. pub const LPC_CONNECTION_REPLY: u32 = 11; diff --git a/support/pal/src/windows/security.rs b/support/pal/src/windows/security.rs index e24ade115f..1e246bfd93 100644 --- a/support/pal/src/windows/security.rs +++ b/support/pal/src/windows/security.rs @@ -14,26 +14,26 @@ use std::ptr::null_mut; use std::str::FromStr; use widestring::U16CStr; use widestring::U16CString; -use winapi::shared::minwindef::BOOL; -use winapi::shared::sddl::ConvertSecurityDescriptorToStringSecurityDescriptorW; -use winapi::shared::sddl::ConvertSidToStringSidW; -use winapi::shared::sddl::ConvertStringSecurityDescriptorToSecurityDescriptorW; -use winapi::shared::sddl::SDDL_REVISION_1; -use winapi::um::securitybaseapi::DeriveCapabilitySidsFromName; -use winapi::um::winbase::LocalFree; -use winapi::um::winnt::DACL_SECURITY_INFORMATION; -use winapi::um::winnt::GROUP_SECURITY_INFORMATION; -use winapi::um::winnt::HANDLE; -use winapi::um::winnt::LABEL_SECURITY_INFORMATION; -use winapi::um::winnt::LPSECURITY_CAPABILITIES; -use winapi::um::winnt::OWNER_SECURITY_INFORMATION; -use winapi::um::winnt::PHANDLE; -use winapi::um::winnt::PSECURITY_DESCRIPTOR; -use winapi::um::winnt::PSID; -use winapi::um::winnt::SACL_SECURITY_INFORMATION; -use winapi::um::winnt::SE_GROUP_ENABLED; -use winapi::um::winnt::SECURITY_CAPABILITIES; -use winapi::um::winnt::SID_AND_ATTRIBUTES; +use windows::Win32::Foundation::BOOL; +use windows::Win32::Foundation::HANDLE; +use windows::Win32::Foundation::LocalFree; +use windows::Win32::Security::Authorization::ConvertSecurityDescriptorToStringSecurityDescriptorW; +use windows::Win32::Security::Authorization::ConvertSidToStringSidW; +use windows::Win32::Security::Authorization::ConvertStringSecurityDescriptorToSecurityDescriptorW; +use windows::Win32::Security::DeriveCapabilitySidsFromName; +use windows::Win32::Security::DACL_SECURITY_INFORMATION; +use windows::Win32::Security::GROUP_SECURITY_INFORMATION; +use windows::Win32::Security::LABEL_SECURITY_INFORMATION; +use windows::Win32::Security::LPSECURITY_CAPABILITIES; +use windows::Win32::Security::OWNER_SECURITY_INFORMATION; +use windows::Win32::Security::PHANDLE; +use windows::Win32::Security::PSECURITY_DESCRIPTOR; +use windows::Win32::Security::PSID; +use windows::Win32::Security::SACL_SECURITY_INFORMATION; +use windows::Win32::Security::SE_GROUP_ENABLED; +use windows::Win32::Security::SECURITY_CAPABILITIES; +use windows::Win32::Security::SID_AND_ATTRIBUTES; +use windows::Win32::Security::SDDL_REVISION_1; const MAX_SUBAUTHORITY_COUNT: usize = 15; diff --git a/support/pal/src/windows/tp.rs b/support/pal/src/windows/tp.rs index 730a14e378..77d3b72427 100644 --- a/support/pal/src/windows/tp.rs +++ b/support/pal/src/windows/tp.rs @@ -9,28 +9,28 @@ use std::os::windows::prelude::*; use std::ptr::NonNull; use std::ptr::null_mut; use std::time::Duration; -use winapi::shared::minwindef::FILETIME; -use winapi::um::threadpoolapiset::CancelThreadpoolIo; -use winapi::um::threadpoolapiset::CloseThreadpoolIo; -use winapi::um::threadpoolapiset::CloseThreadpoolTimer; -use winapi::um::threadpoolapiset::CloseThreadpoolWait; -use winapi::um::threadpoolapiset::CloseThreadpoolWork; -use winapi::um::threadpoolapiset::CreateThreadpoolIo; -use winapi::um::threadpoolapiset::CreateThreadpoolTimer; -use winapi::um::threadpoolapiset::CreateThreadpoolWait; -use winapi::um::threadpoolapiset::CreateThreadpoolWork; -use winapi::um::threadpoolapiset::PTP_WIN32_IO_CALLBACK; -use winapi::um::threadpoolapiset::SetThreadpoolTimerEx; -use winapi::um::threadpoolapiset::SetThreadpoolWaitEx; -use winapi::um::threadpoolapiset::StartThreadpoolIo; -use winapi::um::threadpoolapiset::SubmitThreadpoolWork; -use winapi::um::winnt::PTP_TIMER_CALLBACK; -use winapi::um::winnt::PTP_WAIT_CALLBACK; -use winapi::um::winnt::PTP_WORK_CALLBACK; -use winapi::um::winnt::TP_IO; -use winapi::um::winnt::TP_TIMER; -use winapi::um::winnt::TP_WAIT; -use winapi::um::winnt::TP_WORK; +use windows::Win32::Foundation::FILETIME; +use windows::Win32::System::Threading::CancelThreadpoolIo; +use windows::Win32::System::Threading::CloseThreadpoolIo; +use windows::Win32::System::Threading::CloseThreadpoolTimer; +use windows::Win32::System::Threading::CloseThreadpoolWait; +use windows::Win32::System::Threading::CloseThreadpoolWork; +use windows::Win32::System::Threading::CreateThreadpoolIo; +use windows::Win32::System::Threading::CreateThreadpoolTimer; +use windows::Win32::System::Threading::CreateThreadpoolWait; +use windows::Win32::System::Threading::CreateThreadpoolWork; +use windows::Win32::System::Threading::PTP_WIN32_IO_CALLBACK; +use windows::Win32::System::Threading::SetThreadpoolTimerEx; +use windows::Win32::System::Threading::SetThreadpoolWaitEx; +use windows::Win32::System::Threading::StartThreadpoolIo; +use windows::Win32::System::Threading::SubmitThreadpoolWork; +use windows::Win32::System::Threading::PTP_TIMER_CALLBACK; +use windows::Win32::System::Threading::PTP_WAIT_CALLBACK; +use windows::Win32::System::Threading::PTP_WORK_CALLBACK; +use windows::Win32::System::Threading::TP_IO; +use windows::Win32::System::Threading::TP_TIMER; +use windows::Win32::System::Threading::TP_WAIT; +use windows::Win32::System::Threading::TP_WORK; /// Wrapper around a threadpool wait object (TP_WAIT). #[derive(Debug)] diff --git a/vm/devices/storage/disk_vhdmp/Cargo.toml b/vm/devices/storage/disk_vhdmp/Cargo.toml index 3aafe31823..3ea95c1240 100644 --- a/vm/devices/storage/disk_vhdmp/Cargo.toml +++ b/vm/devices/storage/disk_vhdmp/Cargo.toml @@ -18,7 +18,7 @@ mesh.workspace = true futures.workspace = true thiserror.workspace = true -winapi = { workspace = true, features = [ "handleapi", "winbase", "winnt" ] } +windows = { workspace = true, features = [ "Win32_Foundation", "Win32_System_IO" ] } [target.'cfg(windows)'.dev-dependencies] disk_vhd1.workspace = true diff --git a/vm/devices/storage/disk_vhdmp/src/lib.rs b/vm/devices/storage/disk_vhdmp/src/lib.rs index 356cf5e438..9a97aefc5b 100644 --- a/vm/devices/storage/disk_vhdmp/src/lib.rs +++ b/vm/devices/storage/disk_vhdmp/src/lib.rs @@ -34,10 +34,10 @@ mod virtdisk { )] use std::os::windows::prelude::*; - use winapi::shared::guiddef::GUID; - use winapi::shared::minwindef::BOOL; - use winapi::um::minwinbase::OVERLAPPED; - use winapi::um::winnt::SECURITY_DESCRIPTOR; + use windows::core::GUID; + use windows::Win32::Foundation::BOOL; + use windows::Win32::System::IO::OVERLAPPED; + use windows::Win32::Security::SECURITY_DESCRIPTOR; #[repr(C)] #[derive(Copy, Clone)] From 1669145be8ce4922ab99772cc0d1907d9178c277 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Jun 2025 01:17:54 +0000 Subject: [PATCH 4/8] Migrate term and guid crates from winapi to windows, remove winapi dependencies Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- Cargo.lock | 3 +-- support/guid/Cargo.toml | 6 ------ support/guid/src/lib.rs | 22 +++++++++++----------- support/term/Cargo.toml | 18 ++++-------------- support/term/src/lib.rs | 24 +++++++++++++----------- 5 files changed, 29 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f4d99d3ca..205923854f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2694,7 +2694,6 @@ dependencies = [ "inspect", "mesh_protobuf", "thiserror 2.0.12", - "winapi", "windows 0.59.0", "windows-sys 0.59.0", "zerocopy 0.8.24", @@ -6805,7 +6804,7 @@ dependencies = [ "crossterm", "libc", "thiserror 2.0.12", - "winapi", + "windows 0.59.0", ] [[package]] diff --git a/support/guid/Cargo.toml b/support/guid/Cargo.toml index 1c0a3a8503..3b2379a47a 100644 --- a/support/guid/Cargo.toml +++ b/support/guid/Cargo.toml @@ -21,11 +21,5 @@ zerocopy.workspace = true windows-sys.workspace = true windows.workspace = true -[target.'cfg(windows)'.dependencies.winapi] -workspace = true -features = [ - "guiddef", -] - [lints] workspace = true diff --git a/support/guid/src/lib.rs b/support/guid/src/lib.rs index 7204078dd5..a57b1e3c25 100644 --- a/support/guid/src/lib.rs +++ b/support/guid/src/lib.rs @@ -266,24 +266,24 @@ mod windows { #![cfg(windows)] use super::Guid; - impl From for Guid { - fn from(guid: winapi::shared::guiddef::GUID) -> Self { + impl From for Guid { + fn from(guid: windows::core::GUID) -> Self { Self { - data1: guid.Data1, - data2: guid.Data2, - data3: guid.Data3, - data4: guid.Data4, + data1: guid.data1, + data2: guid.data2, + data3: guid.data3, + data4: guid.data4, } } } - impl From for winapi::shared::guiddef::GUID { + impl From for windows::core::GUID { fn from(guid: Guid) -> Self { Self { - Data1: guid.data1, - Data2: guid.data2, - Data3: guid.data3, - Data4: guid.data4, + data1: guid.data1, + data2: guid.data2, + data3: guid.data3, + data4: guid.data4, } } } diff --git a/support/term/Cargo.toml b/support/term/Cargo.toml index df2d9f0abe..b28a4212a3 100644 --- a/support/term/Cargo.toml +++ b/support/term/Cargo.toml @@ -6,22 +6,12 @@ name = "term" edition.workspace = true rust-version.workspace = true -[target.'cfg(windows)'.dependencies.winapi] +[target.'cfg(windows)'.dependencies.windows] +workspace = true features = [ - "consoleapi", - "handleapi", - "memoryapi", - "namedpipeapi", - "processenv", - "realtimeapiset", - "synchapi", - "winbase", - "wincon", - "winnls", - "winnt", - "winsock2", + "Win32_Foundation", + "Win32_System_Console" ] -workspace = true [target.'cfg(unix)'.dependencies] libc.workspace = true diff --git a/support/term/src/lib.rs b/support/term/src/lib.rs index e64c71f95d..622734bbd6 100644 --- a/support/term/src/lib.rs +++ b/support/term/src/lib.rs @@ -19,23 +19,25 @@ pub enum Error { /// Enables VT and UTF-8 output. #[cfg(windows)] pub fn enable_vt_and_utf8() { - use winapi::um::consoleapi; - use winapi::um::processenv; - use winapi::um::winbase; - use winapi::um::wincon; - use winapi::um::winnls; + use windows::Win32::Foundation::GetStdHandle; + use windows::Win32::Foundation::STD_OUTPUT_HANDLE; + use windows::Win32::System::Console::GetConsoleMode; + use windows::Win32::System::Console::SetConsoleMode; + use windows::Win32::System::Console::SetConsoleOutputCP; + use windows::Win32::System::Console::ENABLE_VIRTUAL_TERMINAL_PROCESSING; + use windows::Win32::System::Console::CP_UTF8; // SAFETY: calling Windows APIs as documented. unsafe { - let conout = processenv::GetStdHandle(winbase::STD_OUTPUT_HANDLE); + let conout = GetStdHandle(STD_OUTPUT_HANDLE); let mut mode = 0; - if consoleapi::GetConsoleMode(conout, &mut mode) != 0 { - if mode & wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0 { - consoleapi::SetConsoleMode( + if GetConsoleMode(conout, &mut mode) != 0 { + if mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING.0 == 0 { + SetConsoleMode( conout, - mode | wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING, + mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING.0, ); } - wincon::SetConsoleOutputCP(winnls::CP_UTF8); + SetConsoleOutputCP(CP_UTF8); } } } From 11bf93d74a03d3db2a0e9005d92008fcf989df2d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Jun 2025 03:05:29 +0000 Subject: [PATCH 5/8] Complete PAL migration from winapi to windows - migrate process, fs, pipe, afd, job modules Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- support/pal/Cargo.toml | 2 ++ support/pal/src/windows/afd.rs | 7 +----- support/pal/src/windows/fs.rs | 16 ++++++------- support/pal/src/windows/job.rs | 12 +++++----- support/pal/src/windows/pipe.rs | 14 ++++------- support/pal/src/windows/process.rs | 38 +++++++++++++++--------------- 6 files changed, 41 insertions(+), 48 deletions(-) diff --git a/support/pal/Cargo.toml b/support/pal/Cargo.toml index 595d4a9f60..736f7c95bf 100644 --- a/support/pal/Cargo.toml +++ b/support/pal/Cargo.toml @@ -61,6 +61,8 @@ features = [ "Win32_System_ErrorReporting", "Win32_System_Memory", "Win32_System_SystemServices", + "Win32_System_JobObjects", + "Win32_System_Pipes", "Win32_Networking_WinSock", "Win32_Storage_FileSystem" ] diff --git a/support/pal/src/windows/afd.rs b/support/pal/src/windows/afd.rs index 25f6895dea..c858ec3d67 100644 --- a/support/pal/src/windows/afd.rs +++ b/support/pal/src/windows/afd.rs @@ -16,12 +16,7 @@ use std::fs::File; use std::mem::zeroed; use std::os::windows::prelude::*; use std::ptr::null_mut; -use winapi::shared::ntdef; -use winapi::shared::winerror; -use winapi::um::ioapiset; -use winapi::um::minwinbase; -use winapi::um::winnt; -use winerror::ERROR_IO_PENDING; +use windows::Win32::Foundation::ERROR_IO_PENDING; #[repr(C)] #[derive(Debug, Copy, Clone, Default)] diff --git a/support/pal/src/windows/fs.rs b/support/pal/src/windows/fs.rs index 0adbf7f041..288d2a5315 100644 --- a/support/pal/src/windows/fs.rs +++ b/support/pal/src/windows/fs.rs @@ -12,10 +12,10 @@ use std::os::windows::io::AsRawHandle; use std::path::Path; use std::ptr::null_mut; use widestring::U16CString; -use winapi::shared::ntdef::OBJ_CASE_INSENSITIVE; -use winapi::shared::ntdef::OBJECT_ATTRIBUTES; -use winapi::um::errhandlingapi::GetLastError; -use winapi::um::minwinbase::WIN32_FIND_DATAW; +use windows::Wdk::Foundation::OBJ_CASE_INSENSITIVE; +use windows::Wdk::Foundation::OBJECT_ATTRIBUTES; +use windows::Win32::Foundation::GetLastError; +use windows::Win32::Storage::FileSystem::WIN32_FIND_DATAW; pub fn query_stat_lx_by_name(path: &Path) -> io::Result { let mut pathu = dos_to_nt_path(path)?; @@ -68,13 +68,13 @@ fn find_first_file_data(path: &Path) -> io::Result { unsafe { let mut data = zeroed(); - let handle = winapi::um::fileapi::FindFirstFileW(path.as_ptr(), &mut data); + let handle = windows::Win32::Storage::FileSystem::FindFirstFileW(path.as_ptr(), &mut data); - if handle == winapi::um::handleapi::INVALID_HANDLE_VALUE { + if handle == windows::Win32::Foundation::INVALID_HANDLE_VALUE { Err(io::Error::from_raw_os_error(GetLastError() as i32)) } else { // Close the handle opened by FindFirstfileW. - winapi::um::fileapi::FindClose(handle); + windows::Win32::Storage::FileSystem::FindClose(handle); Ok(data) } } @@ -86,7 +86,7 @@ pub fn is_unix_socket(path: &Path) -> io::Result { let data = find_first_file_data(path)?; Ok( - data.dwFileAttributes & winapi::um::winnt::FILE_ATTRIBUTE_REPARSE_POINT != 0 + data.dwFileAttributes & windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_REPARSE_POINT != 0 && data.dwReserved0 == IO_REPARSE_TAG_AF_UNIX, ) } diff --git a/support/pal/src/windows/job.rs b/support/pal/src/windows/job.rs index d0f41fa832..fae0864fec 100644 --- a/support/pal/src/windows/job.rs +++ b/support/pal/src/windows/job.rs @@ -21,7 +21,7 @@ impl Job { pub fn new() -> io::Result { // SAFETY: `CreateJobObjectW` returns an owned handle or null. unsafe { - let job = winapi::um::jobapi2::CreateJobObjectW(null_mut(), null()); + let job = windows::Win32::System::JobObjects::CreateJobObjectW(null_mut(), null()); if job.is_null() { return Err(io::Error::last_os_error()); } @@ -34,9 +34,9 @@ impl Job { pub fn set_terminate_on_close(&self) -> io::Result<()> { // SAFETY: It is safe to initialize this C structure using `zeroed`. let mut info = unsafe { - winapi::um::winnt::JOBOBJECT_EXTENDED_LIMIT_INFORMATION { - BasicLimitInformation: winapi::um::winnt::JOBOBJECT_BASIC_LIMIT_INFORMATION { - LimitFlags: winapi::um::winnt::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, + windows::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION { + BasicLimitInformation: windows::Win32::System::JobObjects::JOBOBJECT_BASIC_LIMIT_INFORMATION { + LimitFlags: windows::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, ..zeroed() }, ..zeroed() @@ -44,9 +44,9 @@ impl Job { }; // SAFETY: `SetInformationJobObject` is safe to call with a valid handle. let r = unsafe { - winapi::um::jobapi2::SetInformationJobObject( + windows::Win32::System::JobObjects::SetInformationJobObject( self.0.as_raw_handle(), - winapi::um::winnt::JobObjectExtendedLimitInformation, + windows::Win32::System::JobObjects::JobObjectExtendedLimitInformation, std::ptr::from_mut(&mut info).cast(), size_of_val(&info) as u32, ) diff --git a/support/pal/src/windows/pipe.rs b/support/pal/src/windows/pipe.rs index c12dd273ed..29a3ab9dd6 100644 --- a/support/pal/src/windows/pipe.rs +++ b/support/pal/src/windows/pipe.rs @@ -39,14 +39,10 @@ use std::path::Path; use std::ptr::null_mut; use std::sync::atomic::AtomicPtr; use std::sync::atomic::Ordering; -use winapi::shared::ntdef; -use winapi::shared::ntstatus::STATUS_NAME_TOO_LONG; -use winapi::um::namedpipeapi; -use winapi::um::namedpipeapi::DisconnectNamedPipe; -use winapi::um::namedpipeapi::GetNamedPipeInfo; -use winapi::um::winbase::PIPE_SERVER_END; -use winapi::um::winioctl; -use winapi::um::winnt; +use windows::Wdk::Foundation::STATUS_NAME_TOO_LONG; +use windows::Win32::System::Pipes::DisconnectNamedPipe; +use windows::Win32::System::Pipes::GetNamedPipeInfo; +use windows::Win32::System::Pipes::PIPE_SERVER_END; use winnt::FILE_READ_ATTRIBUTES; use winnt::FILE_SHARE_READ; use winnt::FILE_SHARE_WRITE; @@ -333,7 +329,7 @@ impl PipeExt for File { null_mut(), 0, ); - if status != winapi::shared::ntstatus::STATUS_NOT_SUPPORTED { + if status != windows::Win32::Foundation::STATUS_NOT_SUPPORTED { break; } } diff --git a/support/pal/src/windows/process.rs b/support/pal/src/windows/process.rs index b489a8c972..6d86f881a3 100644 --- a/support/pal/src/windows/process.rs +++ b/support/pal/src/windows/process.rs @@ -14,25 +14,25 @@ use std::os::windows::prelude::*; use std::ptr::null; use std::ptr::null_mut; use widestring::U16CString; -use winapi::shared::winerror::ERROR_INVALID_PARAMETER; -use winapi::um::handleapi::SetHandleInformation; -use winapi::um::processenv::GetStdHandle; -use winapi::um::processthreadsapi::CreateProcessAsUserW; -use winapi::um::processthreadsapi::DeleteProcThreadAttributeList; -use winapi::um::processthreadsapi::InitializeProcThreadAttributeList; -use winapi::um::processthreadsapi::LPPROC_THREAD_ATTRIBUTE_LIST; -use winapi::um::processthreadsapi::STARTUPINFOW; -use winapi::um::processthreadsapi::TerminateProcess; -use winapi::um::processthreadsapi::UpdateProcThreadAttribute; -use winapi::um::winbase::CREATE_SUSPENDED; -use winapi::um::winbase::CREATE_UNICODE_ENVIRONMENT; -use winapi::um::winbase::EXTENDED_STARTUPINFO_PRESENT; -use winapi::um::winbase::HANDLE_FLAG_INHERIT; -use winapi::um::winbase::STARTF_USESTDHANDLES; -use winapi::um::winbase::STARTUPINFOEXW; -use winapi::um::winbase::STD_ERROR_HANDLE; -use winapi::um::winbase::STD_INPUT_HANDLE; -use winapi::um::winbase::STD_OUTPUT_HANDLE; +use windows::Win32::Foundation::ERROR_INVALID_PARAMETER; +use windows::Win32::Foundation::SetHandleInformation; +use windows::Win32::Foundation::GetStdHandle; +use windows::Win32::System::Threading::CreateProcessAsUserW; +use windows::Win32::System::Threading::DeleteProcThreadAttributeList; +use windows::Win32::System::Threading::InitializeProcThreadAttributeList; +use windows::Win32::System::Threading::LPPROC_THREAD_ATTRIBUTE_LIST; +use windows::Win32::System::Threading::STARTUPINFOW; +use windows::Win32::System::Threading::TerminateProcess; +use windows::Win32::System::Threading::UpdateProcThreadAttribute; +use windows::Win32::System::Threading::CREATE_SUSPENDED; +use windows::Win32::System::Threading::CREATE_UNICODE_ENVIRONMENT; +use windows::Win32::System::Threading::EXTENDED_STARTUPINFO_PRESENT; +use windows::Win32::Foundation::HANDLE_FLAG_INHERIT; +use windows::Win32::System::Threading::STARTF_USESTDHANDLES; +use windows::Win32::System::Threading::STARTUPINFOEXW; +use windows::Win32::System::Threading::STD_ERROR_HANDLE; +use windows::Win32::System::Threading::STD_INPUT_HANDLE; +use windows::Win32::System::Threading::STD_OUTPUT_HANDLE; const PROC_THREAD_ATTRIBUTE_HANDLE_LIST: u32 = 0x00020002; const PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY: u32 = 0x000020007; From 6d1cccb15e974e3608c44013317f1bde8858431a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Jun 2025 15:26:22 +0000 Subject: [PATCH 6/8] Remove winapi dependency from PAL Cargo.toml - migration complete Co-authored-by: smalis-msft <137308034+smalis-msft@users.noreply.github.com> --- Cargo.lock | 2 +- support/pal/Cargo.toml | 27 +-------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 205923854f..c95e0a56e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5159,7 +5159,7 @@ dependencies = [ "thiserror 2.0.12", "tracing", "widestring", - "winapi", + "win_import_lib", "windows 0.59.0", ] diff --git a/support/pal/Cargo.toml b/support/pal/Cargo.toml index 736f7c95bf..616a4d0eb6 100644 --- a/support/pal/Cargo.toml +++ b/support/pal/Cargo.toml @@ -22,32 +22,7 @@ ntapi = { workspace = true, features = ["impl-default"] } socket2 = { workspace = true, features = ["all"] } widestring.workspace = true -[target.'cfg(windows)'.dependencies.winapi] -workspace = true -features = [ - "errhandlingapi", - "fileapi", - "handleapi", - "heapapi", - "ioapiset", - "impl-default", - "jobapi2", - "memoryapi", - "namedpipeapi", - "ntstatus", - "processenv", - "processthreadsapi", - "sddl", - "securitybaseapi", - "std", - "synchapi", - "threadpoolapiset", - "winbase", - "winerror", - "winioctl", - "winnt", - "winsock2", -] + [target.'cfg(windows)'.dependencies.windows] workspace = true From 5c5deb7fa66c8baf2084a786a1ee8911259d2d1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Jun 2025 15:33:34 +0000 Subject: [PATCH 7/8] Complete winapi migration in delayload macro - fix remaining build issues Co-authored-by: smalis-msft <137308034+smalis-msft@users.noreply.github.com> --- support/pal/src/windows.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/support/pal/src/windows.rs b/support/pal/src/windows.rs index 403adb58ab..7752483798 100644 --- a/support/pal/src/windows.rs +++ b/support/pal/src/windows.rs @@ -994,17 +994,15 @@ unsafe impl Sync for Overlapped {} #[macro_export] macro_rules! delayload { {$dll:literal {$($($idents:ident)+ ($($params:ident : $types:ty),* $(,)?) -> $result:ty;)*}} => { - fn get_module() -> Result<::winapi::shared::minwindef::HINSTANCE, u32> { + fn get_module() -> Result<::windows::Win32::Foundation::HINSTANCE, u32> { use ::std::ptr::null_mut; use ::std::sync::atomic::{AtomicPtr, Ordering}; - use ::winapi::{ - um::{ - errhandlingapi::GetLastError, - libloaderapi::{FreeLibrary, LoadLibraryA}, - }, + use ::windows::Win32::{ + Foundation::GetLastError, + System::LibraryLoader::{FreeLibrary, LoadLibraryA}, }; - static MODULE: AtomicPtr<::winapi::shared::minwindef::HINSTANCE__> = AtomicPtr::new(null_mut()); + static MODULE: AtomicPtr<::windows::Win32::Foundation::HINSTANCE> = AtomicPtr::new(null_mut()); let mut module = MODULE.load(Ordering::Relaxed); if module.is_null() { module = unsafe { LoadLibraryA(concat!($dll, "\0").as_ptr() as *const i8) }; @@ -1040,9 +1038,9 @@ macro_rules! delayload { (@body $name:ident($($params:ident : $types:ty),* $(,)?) -> $result:ty) => { { - use ::winapi::{ - shared::winerror::ERROR_PROC_NOT_FOUND, - um::libloaderapi::GetProcAddress, + use ::windows::Win32::{ + Foundation::ERROR_PROC_NOT_FOUND, + System::LibraryLoader::GetProcAddress, }; use ::std::concat; use ::std::sync::atomic::{AtomicUsize, Ordering}; @@ -1075,10 +1073,10 @@ macro_rules! delayload { } }; - (@result_from_win32((i32), $val:expr)) => { ::winapi::shared::winerror::HRESULT_FROM_WIN32($val) }; + (@result_from_win32((i32), $val:expr)) => { ::windows::Win32::Foundation::HRESULT::from_win32($val) }; (@result_from_win32((u32), $val:expr)) => { $val }; (@result_from_win32((DWORD), $val:expr)) => { $val }; - (@result_from_win32((HRESULT), $val:expr)) => { ::winapi::shared::winerror::HRESULT_FROM_WIN32($val) }; + (@result_from_win32((HRESULT), $val:expr)) => { ::windows::Win32::Foundation::HRESULT::from_win32($val) }; (@result_from_win32(($t:tt), $val:expr)) => { panic!("could not load: {}", $val) }; } From 0c9db5e53be27c48ced60d640150d62630623bf0 Mon Sep 17 00:00:00 2001 From: Ben Hillis Date: Wed, 25 Jun 2025 15:35:50 +0000 Subject: [PATCH 8/8] cargo xtask fmt --fix --- Cargo.lock | 1 - support/guid/src/lib.rs | 22 ------------------- support/pal/src/windows.rs | 28 ++++++++++++------------ support/pal/src/windows/afd.rs | 6 ++--- support/pal/src/windows/fs.rs | 3 ++- support/pal/src/windows/job.rs | 10 +++++---- support/pal/src/windows/pipe.rs | 6 ++--- support/pal/src/windows/process.rs | 16 +++++++------- support/pal/src/windows/security.rs | 4 ++-- support/pal/src/windows/tp.rs | 6 ++--- support/term/src/lib.rs | 9 +++----- vm/devices/storage/disk_vhdmp/src/lib.rs | 4 ++-- 12 files changed, 46 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c95e0a56e3..dfcf59c5c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5159,7 +5159,6 @@ dependencies = [ "thiserror 2.0.12", "tracing", "widestring", - "win_import_lib", "windows 0.59.0", ] diff --git a/support/guid/src/lib.rs b/support/guid/src/lib.rs index a57b1e3c25..cbedfbef5d 100644 --- a/support/guid/src/lib.rs +++ b/support/guid/src/lib.rs @@ -266,28 +266,6 @@ mod windows { #![cfg(windows)] use super::Guid; - impl From for Guid { - fn from(guid: windows::core::GUID) -> Self { - Self { - data1: guid.data1, - data2: guid.data2, - data3: guid.data3, - data4: guid.data4, - } - } - } - - impl From for windows::core::GUID { - fn from(guid: Guid) -> Self { - Self { - data1: guid.data1, - data2: guid.data2, - data3: guid.data3, - data4: guid.data4, - } - } - } - impl From for Guid { fn from(guid: windows_sys::core::GUID) -> Self { Self { diff --git a/support/pal/src/windows.rs b/support/pal/src/windows.rs index 7752483798..bb1c5c25b9 100644 --- a/support/pal/src/windows.rs +++ b/support/pal/src/windows.rs @@ -17,6 +17,8 @@ pub mod security; pub mod tp; use self::security::SecurityDescriptor; +use ntapi::ntdef::ANSI_STRING; +use ntapi::ntdef::UNICODE_STRING; use ntapi::ntioapi::FILE_COMPLETION_INFORMATION; use ntapi::ntioapi::FileReplaceCompletionInformation; use ntapi::ntioapi::IO_STATUS_BLOCK; @@ -27,8 +29,6 @@ use ntapi::ntioapi::NtSetInformationFile; use ntapi::ntobapi::NtCreateDirectoryObject; use ntapi::ntobapi::NtOpenDirectoryObject; use ntapi::ntrtl; -use ntdef::ANSI_STRING; -use ntdef::UNICODE_STRING; use ntrtl::RtlAllocateHeap; use ntrtl::RtlDosPathNameToNtPathName_U_WithStatus; use ntrtl::RtlFreeUnicodeString; @@ -54,32 +54,32 @@ use std::time::Duration; use widestring::U16CString; use widestring::Utf16Str; use windows::Win32::Foundation::CloseHandle; -use windows::Win32::Foundation::DuplicateHandle; use windows::Win32::Foundation::DUPLICATE_SAME_ACCESS; +use windows::Win32::Foundation::DuplicateHandle; use windows::Win32::Foundation::ERROR_BAD_PATHNAME; use windows::Win32::Foundation::INVALID_HANDLE_VALUE; use windows::Win32::Foundation::NTSTATUS; use windows::Win32::Foundation::STATUS_PENDING; -use windows::Win32::Foundation::INFINITE; -use windows::Win32::System::ErrorReporting::GetErrorMode; -use windows::Win32::System::ErrorReporting::SetErrorMode; -use windows::Win32::System::ErrorReporting::SEM_FAILCRITICALERRORS; +use windows::Win32::Networking::WinSock::IOC_IN; +use windows::Win32::Networking::WinSock::IOC_VENDOR; +use windows::Win32::Storage::FileSystem::SetFileCompletionNotificationModes; +use windows::Win32::System::Console::STD_OUTPUT_HANDLE; +use windows::Win32::System::Console::SetStdHandle; use windows::Win32::System::IO::CreateIoCompletionPort; use windows::Win32::System::IO::GetQueuedCompletionStatusEx; -use windows::Win32::System::IO::PostQueuedCompletionStatus; use windows::Win32::System::IO::OVERLAPPED; use windows::Win32::System::IO::OVERLAPPED_ENTRY; +use windows::Win32::System::IO::PostQueuedCompletionStatus; use windows::Win32::System::Memory::GetProcessHeap; +use windows::Win32::System::SystemServices::GetErrorMode; +use windows::Win32::System::SystemServices::SEM_FAILCRITICALERRORS; +use windows::Win32::System::SystemServices::SetErrorMode; use windows::Win32::System::Threading::GetCurrentProcess; use windows::Win32::System::Threading::GetExitCodeProcess; use windows::Win32::System::Threading::GetProcessId; -use windows::Win32::System::Threading::SetStdHandle; +use windows::Win32::System::Threading::INFINITE; use windows::Win32::System::Threading::TerminateProcess; -use windows::Win32::System::Threading::STD_OUTPUT_HANDLE; use windows::Win32::System::Threading::WaitForSingleObject; -use windows::Win32::Storage::FileSystem::SetFileCompletionNotificationModes; -use windows::Win32::Networking::WinSock::IOC_IN; -use windows::Win32::Networking::WinSock::IOC_VENDOR; #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -98,7 +98,7 @@ impl BorrowedHandleExt for BorrowedHandle<'_> { let options = if access.is_some() { 0 } else { - DUPLICATE_SAME_ACCESS + DUPLICATE_SAME_ACCESS.0 }; unsafe { let process = GetCurrentProcess(); diff --git a/support/pal/src/windows/afd.rs b/support/pal/src/windows/afd.rs index c858ec3d67..e96f7d2405 100644 --- a/support/pal/src/windows/afd.rs +++ b/support/pal/src/windows/afd.rs @@ -8,15 +8,15 @@ use super::SendSyncRawHandle; use super::UnicodeString; use super::chk_status; -use ioapiset::DeviceIoControl; -use minwinbase::OVERLAPPED; +use ntapi::ntdef::OBJECT_ATTRIBUTES; use ntapi::ntioapi::NtOpenFile; -use ntdef::OBJECT_ATTRIBUTES; use std::fs::File; use std::mem::zeroed; use std::os::windows::prelude::*; use std::ptr::null_mut; use windows::Win32::Foundation::ERROR_IO_PENDING; +use windows::Win32::System::IO::DeviceIoControl; +use windows::Win32::System::IO::OVERLAPPED; #[repr(C)] #[derive(Debug, Copy, Clone, Default)] diff --git a/support/pal/src/windows/fs.rs b/support/pal/src/windows/fs.rs index 288d2a5315..455fdac876 100644 --- a/support/pal/src/windows/fs.rs +++ b/support/pal/src/windows/fs.rs @@ -86,7 +86,8 @@ pub fn is_unix_socket(path: &Path) -> io::Result { let data = find_first_file_data(path)?; Ok( - data.dwFileAttributes & windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_REPARSE_POINT != 0 + data.dwFileAttributes & windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_REPARSE_POINT + != 0 && data.dwReserved0 == IO_REPARSE_TAG_AF_UNIX, ) } diff --git a/support/pal/src/windows/job.rs b/support/pal/src/windows/job.rs index fae0864fec..8ea4dac951 100644 --- a/support/pal/src/windows/job.rs +++ b/support/pal/src/windows/job.rs @@ -35,10 +35,12 @@ impl Job { // SAFETY: It is safe to initialize this C structure using `zeroed`. let mut info = unsafe { windows::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION { - BasicLimitInformation: windows::Win32::System::JobObjects::JOBOBJECT_BASIC_LIMIT_INFORMATION { - LimitFlags: windows::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, - ..zeroed() - }, + BasicLimitInformation: + windows::Win32::System::JobObjects::JOBOBJECT_BASIC_LIMIT_INFORMATION { + LimitFlags: + windows::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, + ..zeroed() + }, ..zeroed() } }; diff --git a/support/pal/src/windows/pipe.rs b/support/pal/src/windows/pipe.rs index 29a3ab9dd6..ed2be9548c 100644 --- a/support/pal/src/windows/pipe.rs +++ b/support/pal/src/windows/pipe.rs @@ -7,6 +7,9 @@ use super::dos_to_nt_path; use super::status_to_error; use namedpipeapi::GetNamedPipeHandleStateW; use namedpipeapi::SetNamedPipeHandleState; +use ntapi::ntdef::LARGE_INTEGER; +use ntapi::ntdef::OBJ_CASE_INSENSITIVE; +use ntapi::ntdef::OBJECT_ATTRIBUTES; use ntapi::ntioapi; use ntapi::ntioapi::FILE_OPEN; use ntapi::ntioapi::FILE_PIPE_CLOSING_STATE; @@ -16,9 +19,6 @@ use ntapi::ntioapi::FILE_PIPE_LISTENING_STATE; use ntapi::ntioapi::FILE_PIPE_LOCAL_INFORMATION; use ntapi::ntioapi::FilePipeLocalInformation; use ntapi::ntioapi::NtQueryInformationFile; -use ntdef::LARGE_INTEGER; -use ntdef::OBJ_CASE_INSENSITIVE; -use ntdef::OBJECT_ATTRIBUTES; use ntioapi::FILE_CREATE; use ntioapi::FILE_NON_DIRECTORY_FILE; use ntioapi::FILE_PIPE_BYTE_STREAM_MODE; diff --git a/support/pal/src/windows/process.rs b/support/pal/src/windows/process.rs index 6d86f881a3..30270856c7 100644 --- a/support/pal/src/windows/process.rs +++ b/support/pal/src/windows/process.rs @@ -15,24 +15,24 @@ use std::ptr::null; use std::ptr::null_mut; use widestring::U16CString; use windows::Win32::Foundation::ERROR_INVALID_PARAMETER; -use windows::Win32::Foundation::SetHandleInformation; use windows::Win32::Foundation::GetStdHandle; +use windows::Win32::Foundation::HANDLE_FLAG_INHERIT; +use windows::Win32::Foundation::SetHandleInformation; +use windows::Win32::System::Threading::CREATE_SUSPENDED; +use windows::Win32::System::Threading::CREATE_UNICODE_ENVIRONMENT; use windows::Win32::System::Threading::CreateProcessAsUserW; use windows::Win32::System::Threading::DeleteProcThreadAttributeList; +use windows::Win32::System::Threading::EXTENDED_STARTUPINFO_PRESENT; use windows::Win32::System::Threading::InitializeProcThreadAttributeList; use windows::Win32::System::Threading::LPPROC_THREAD_ATTRIBUTE_LIST; -use windows::Win32::System::Threading::STARTUPINFOW; -use windows::Win32::System::Threading::TerminateProcess; -use windows::Win32::System::Threading::UpdateProcThreadAttribute; -use windows::Win32::System::Threading::CREATE_SUSPENDED; -use windows::Win32::System::Threading::CREATE_UNICODE_ENVIRONMENT; -use windows::Win32::System::Threading::EXTENDED_STARTUPINFO_PRESENT; -use windows::Win32::Foundation::HANDLE_FLAG_INHERIT; use windows::Win32::System::Threading::STARTF_USESTDHANDLES; use windows::Win32::System::Threading::STARTUPINFOEXW; +use windows::Win32::System::Threading::STARTUPINFOW; use windows::Win32::System::Threading::STD_ERROR_HANDLE; use windows::Win32::System::Threading::STD_INPUT_HANDLE; use windows::Win32::System::Threading::STD_OUTPUT_HANDLE; +use windows::Win32::System::Threading::TerminateProcess; +use windows::Win32::System::Threading::UpdateProcThreadAttribute; const PROC_THREAD_ATTRIBUTE_HANDLE_LIST: u32 = 0x00020002; const PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY: u32 = 0x000020007; diff --git a/support/pal/src/windows/security.rs b/support/pal/src/windows/security.rs index 1e246bfd93..7c6e2b16d6 100644 --- a/support/pal/src/windows/security.rs +++ b/support/pal/src/windows/security.rs @@ -20,8 +20,8 @@ use windows::Win32::Foundation::LocalFree; use windows::Win32::Security::Authorization::ConvertSecurityDescriptorToStringSecurityDescriptorW; use windows::Win32::Security::Authorization::ConvertSidToStringSidW; use windows::Win32::Security::Authorization::ConvertStringSecurityDescriptorToSecurityDescriptorW; -use windows::Win32::Security::DeriveCapabilitySidsFromName; use windows::Win32::Security::DACL_SECURITY_INFORMATION; +use windows::Win32::Security::DeriveCapabilitySidsFromName; use windows::Win32::Security::GROUP_SECURITY_INFORMATION; use windows::Win32::Security::LABEL_SECURITY_INFORMATION; use windows::Win32::Security::LPSECURITY_CAPABILITIES; @@ -30,10 +30,10 @@ use windows::Win32::Security::PHANDLE; use windows::Win32::Security::PSECURITY_DESCRIPTOR; use windows::Win32::Security::PSID; use windows::Win32::Security::SACL_SECURITY_INFORMATION; +use windows::Win32::Security::SDDL_REVISION_1; use windows::Win32::Security::SE_GROUP_ENABLED; use windows::Win32::Security::SECURITY_CAPABILITIES; use windows::Win32::Security::SID_AND_ATTRIBUTES; -use windows::Win32::Security::SDDL_REVISION_1; const MAX_SUBAUTHORITY_COUNT: usize = 15; diff --git a/support/pal/src/windows/tp.rs b/support/pal/src/windows/tp.rs index 77d3b72427..734819366a 100644 --- a/support/pal/src/windows/tp.rs +++ b/support/pal/src/windows/tp.rs @@ -19,14 +19,14 @@ use windows::Win32::System::Threading::CreateThreadpoolIo; use windows::Win32::System::Threading::CreateThreadpoolTimer; use windows::Win32::System::Threading::CreateThreadpoolWait; use windows::Win32::System::Threading::CreateThreadpoolWork; +use windows::Win32::System::Threading::PTP_TIMER_CALLBACK; +use windows::Win32::System::Threading::PTP_WAIT_CALLBACK; use windows::Win32::System::Threading::PTP_WIN32_IO_CALLBACK; +use windows::Win32::System::Threading::PTP_WORK_CALLBACK; use windows::Win32::System::Threading::SetThreadpoolTimerEx; use windows::Win32::System::Threading::SetThreadpoolWaitEx; use windows::Win32::System::Threading::StartThreadpoolIo; use windows::Win32::System::Threading::SubmitThreadpoolWork; -use windows::Win32::System::Threading::PTP_TIMER_CALLBACK; -use windows::Win32::System::Threading::PTP_WAIT_CALLBACK; -use windows::Win32::System::Threading::PTP_WORK_CALLBACK; use windows::Win32::System::Threading::TP_IO; use windows::Win32::System::Threading::TP_TIMER; use windows::Win32::System::Threading::TP_WAIT; diff --git a/support/term/src/lib.rs b/support/term/src/lib.rs index 622734bbd6..64c5c3b1cc 100644 --- a/support/term/src/lib.rs +++ b/support/term/src/lib.rs @@ -21,21 +21,18 @@ pub enum Error { pub fn enable_vt_and_utf8() { use windows::Win32::Foundation::GetStdHandle; use windows::Win32::Foundation::STD_OUTPUT_HANDLE; + use windows::Win32::System::Console::CP_UTF8; + use windows::Win32::System::Console::ENABLE_VIRTUAL_TERMINAL_PROCESSING; use windows::Win32::System::Console::GetConsoleMode; use windows::Win32::System::Console::SetConsoleMode; use windows::Win32::System::Console::SetConsoleOutputCP; - use windows::Win32::System::Console::ENABLE_VIRTUAL_TERMINAL_PROCESSING; - use windows::Win32::System::Console::CP_UTF8; // SAFETY: calling Windows APIs as documented. unsafe { let conout = GetStdHandle(STD_OUTPUT_HANDLE); let mut mode = 0; if GetConsoleMode(conout, &mut mode) != 0 { if mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING.0 == 0 { - SetConsoleMode( - conout, - mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING.0, - ); + SetConsoleMode(conout, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING.0); } SetConsoleOutputCP(CP_UTF8); } diff --git a/vm/devices/storage/disk_vhdmp/src/lib.rs b/vm/devices/storage/disk_vhdmp/src/lib.rs index 9a97aefc5b..5efae9d8aa 100644 --- a/vm/devices/storage/disk_vhdmp/src/lib.rs +++ b/vm/devices/storage/disk_vhdmp/src/lib.rs @@ -34,10 +34,10 @@ mod virtdisk { )] use std::os::windows::prelude::*; - use windows::core::GUID; use windows::Win32::Foundation::BOOL; - use windows::Win32::System::IO::OVERLAPPED; use windows::Win32::Security::SECURITY_DESCRIPTOR; + use windows::Win32::System::IO::OVERLAPPED; + use windows::core::GUID; #[repr(C)] #[derive(Copy, Clone)]