Skip to content

Commit a51ef95

Browse files
Copilotbenhillis
andcommitted
Migrate PAL main windows.rs from winapi to windows crate
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
1 parent 291751d commit a51ef95

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

support/pal/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ workspace = true
5757
features = [
5858
"Wdk_Foundation",
5959
"Win32_Foundation",
60-
"Win32_Security"
60+
"Win32_Security",
61+
"Win32_System_IO",
62+
"Win32_System_Threading",
63+
"Win32_System_ErrorReporting",
64+
"Win32_System_Memory",
65+
"Win32_Networking_WinSock",
66+
"Win32_Storage_FileSystem"
6167
]
6268

6369
[target.'cfg(unix)'.dependencies]

support/pal/src/windows.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod security;
1717
pub mod tp;
1818

1919
use self::security::SecurityDescriptor;
20-
use handleapi::INVALID_HANDLE_VALUE;
2120
use ntapi::ntioapi::FILE_COMPLETION_INFORMATION;
2221
use ntapi::ntioapi::FileReplaceCompletionInformation;
2322
use ntapi::ntioapi::IO_STATUS_BLOCK;
@@ -34,7 +33,6 @@ use ntrtl::RtlAllocateHeap;
3433
use ntrtl::RtlDosPathNameToNtPathName_U_WithStatus;
3534
use ntrtl::RtlFreeUnicodeString;
3635
use ntrtl::RtlNtStatusToDosErrorNoTeb;
37-
use processthreadsapi::GetExitCodeProcess;
3836
use std::cell::UnsafeCell;
3937
use std::ffi::OsStr;
4038
use std::ffi::c_void;
@@ -55,32 +53,33 @@ use std::sync::atomic::Ordering;
5553
use std::time::Duration;
5654
use widestring::U16CString;
5755
use widestring::Utf16Str;
58-
use winapi::shared::ntdef;
59-
use winapi::shared::ntdef::NTSTATUS;
60-
use winapi::shared::ntstatus;
61-
use winapi::shared::ntstatus::STATUS_PENDING;
62-
use winapi::shared::winerror::ERROR_BAD_PATHNAME;
63-
use winapi::shared::ws2def;
64-
use winapi::um::errhandlingapi::GetErrorMode;
65-
use winapi::um::errhandlingapi::SetErrorMode;
66-
use winapi::um::handleapi;
67-
use winapi::um::handleapi::CloseHandle;
68-
use winapi::um::heapapi::GetProcessHeap;
69-
use winapi::um::ioapiset::CreateIoCompletionPort;
70-
use winapi::um::ioapiset::GetQueuedCompletionStatusEx;
71-
use winapi::um::ioapiset::PostQueuedCompletionStatus;
72-
use winapi::um::minwinbase::OVERLAPPED;
73-
use winapi::um::minwinbase::OVERLAPPED_ENTRY;
74-
use winapi::um::processenv::SetStdHandle;
75-
use winapi::um::processthreadsapi;
76-
use winapi::um::processthreadsapi::TerminateProcess;
77-
use winapi::um::synchapi;
78-
use winapi::um::winbase::INFINITE;
79-
use winapi::um::winbase::SEM_FAILCRITICALERRORS;
80-
use winapi::um::winbase::STD_OUTPUT_HANDLE;
81-
use winapi::um::winbase::SetFileCompletionNotificationModes;
82-
use winapi::um::winnt;
83-
use winapi::um::winsock2;
56+
use windows::Win32::Foundation::CloseHandle;
57+
use windows::Win32::Foundation::DuplicateHandle;
58+
use windows::Win32::Foundation::DUPLICATE_SAME_ACCESS;
59+
use windows::Win32::Foundation::ERROR_BAD_PATHNAME;
60+
use windows::Win32::Foundation::INVALID_HANDLE_VALUE;
61+
use windows::Win32::Foundation::NTSTATUS;
62+
use windows::Win32::Foundation::STATUS_PENDING;
63+
use windows::Win32::Foundation::INFINITE;
64+
use windows::Win32::System::ErrorReporting::GetErrorMode;
65+
use windows::Win32::System::ErrorReporting::SetErrorMode;
66+
use windows::Win32::System::ErrorReporting::SEM_FAILCRITICALERRORS;
67+
use windows::Win32::System::IO::CreateIoCompletionPort;
68+
use windows::Win32::System::IO::GetQueuedCompletionStatusEx;
69+
use windows::Win32::System::IO::PostQueuedCompletionStatus;
70+
use windows::Win32::System::IO::OVERLAPPED;
71+
use windows::Win32::System::IO::OVERLAPPED_ENTRY;
72+
use windows::Win32::System::Memory::GetProcessHeap;
73+
use windows::Win32::System::Threading::GetCurrentProcess;
74+
use windows::Win32::System::Threading::GetExitCodeProcess;
75+
use windows::Win32::System::Threading::GetProcessId;
76+
use windows::Win32::System::Threading::SetStdHandle;
77+
use windows::Win32::System::Threading::TerminateProcess;
78+
use windows::Win32::System::Threading::STD_OUTPUT_HANDLE;
79+
use windows::Win32::System::Threading::WaitForSingleObject;
80+
use windows::Win32::Storage::FileSystem::SetFileCompletionNotificationModes;
81+
use windows::Win32::Networking::WinSock::IOC_IN;
82+
use windows::Win32::Networking::WinSock::IOC_VENDOR;
8483

8584
#[repr(transparent)]
8685
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -99,11 +98,11 @@ impl BorrowedHandleExt for BorrowedHandle<'_> {
9998
let options = if access.is_some() {
10099
0
101100
} else {
102-
winnt::DUPLICATE_SAME_ACCESS
101+
DUPLICATE_SAME_ACCESS
103102
};
104103
unsafe {
105-
let process = processthreadsapi::GetCurrentProcess();
106-
if handleapi::DuplicateHandle(
104+
let process = GetCurrentProcess();
105+
if DuplicateHandle(
107106
process,
108107
self.as_raw_handle(),
109108
process,
@@ -134,8 +133,8 @@ pub trait OwnedSocketExt: Sized {
134133
fn from_handle(handle: OwnedHandle) -> Result<Self>;
135134
}
136135

137-
const SIO_SOCKET_TRANSFER_BEGIN: u32 = ws2def::IOC_IN | ws2def::IOC_VENDOR | 301;
138-
const SIO_SOCKET_TRANSFER_END: u32 = ws2def::IOC_IN | ws2def::IOC_VENDOR | 302;
136+
const SIO_SOCKET_TRANSFER_BEGIN: u32 = IOC_IN | IOC_VENDOR | 301;
137+
const SIO_SOCKET_TRANSFER_END: u32 = IOC_IN | IOC_VENDOR | 302;
139138

140139
/// Ensures WSAStartup has been called for the process.
141140
fn init_winsock() {
@@ -209,7 +208,7 @@ struct WaitObject(OwnedHandle);
209208

210209
impl WaitObject {
211210
fn wait(&self) {
212-
assert!(unsafe { synchapi::WaitForSingleObject(self.0.as_raw_handle(), INFINITE) } == 0);
211+
assert!(unsafe { WaitForSingleObject(self.0.as_raw_handle(), INFINITE) } == 0);
213212
}
214213
}
215214

@@ -233,7 +232,7 @@ impl Process {
233232

234233
pub fn id(&self) -> u32 {
235234
unsafe {
236-
let pid = processthreadsapi::GetProcessId(self.as_handle().as_raw_handle());
235+
let pid = GetProcessId(self.as_handle().as_raw_handle());
237236
assert_ne!(pid, 0);
238237
pid
239238
}

0 commit comments

Comments
 (0)