Skip to content

Commit 9aa33e5

Browse files
Copilotbenhillis
andcommitted
Complete PAL migration from winapi to windows - migrate process, fs, pipe, afd, job modules
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
1 parent 9e2887b commit 9aa33e5

File tree

6 files changed

+41
-48
lines changed

6 files changed

+41
-48
lines changed

support/pal/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ features = [
6464
"Win32_System_ErrorReporting",
6565
"Win32_System_Memory",
6666
"Win32_System_SystemServices",
67+
"Win32_System_JobObjects",
68+
"Win32_System_Pipes",
6769
"Win32_Networking_WinSock",
6870
"Win32_Storage_FileSystem"
6971
]

support/pal/src/windows/afd.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ use std::fs::File;
1616
use std::mem::zeroed;
1717
use std::os::windows::prelude::*;
1818
use std::ptr::null_mut;
19-
use winapi::shared::ntdef;
20-
use winapi::shared::winerror;
21-
use winapi::um::ioapiset;
22-
use winapi::um::minwinbase;
23-
use winapi::um::winnt;
24-
use winerror::ERROR_IO_PENDING;
19+
use windows::Win32::Foundation::ERROR_IO_PENDING;
2520

2621
#[repr(C)]
2722
#[derive(Debug, Copy, Clone, Default)]

support/pal/src/windows/fs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use std::os::windows::io::AsRawHandle;
1212
use std::path::Path;
1313
use std::ptr::null_mut;
1414
use widestring::U16CString;
15-
use winapi::shared::ntdef::OBJ_CASE_INSENSITIVE;
16-
use winapi::shared::ntdef::OBJECT_ATTRIBUTES;
17-
use winapi::um::errhandlingapi::GetLastError;
18-
use winapi::um::minwinbase::WIN32_FIND_DATAW;
15+
use windows::Wdk::Foundation::OBJ_CASE_INSENSITIVE;
16+
use windows::Wdk::Foundation::OBJECT_ATTRIBUTES;
17+
use windows::Win32::Foundation::GetLastError;
18+
use windows::Win32::Storage::FileSystem::WIN32_FIND_DATAW;
1919

2020
pub fn query_stat_lx_by_name(path: &Path) -> io::Result<ntioapi::FILE_STAT_LX_INFORMATION> {
2121
let mut pathu = dos_to_nt_path(path)?;
@@ -68,13 +68,13 @@ fn find_first_file_data(path: &Path) -> io::Result<WIN32_FIND_DATAW> {
6868

6969
unsafe {
7070
let mut data = zeroed();
71-
let handle = winapi::um::fileapi::FindFirstFileW(path.as_ptr(), &mut data);
71+
let handle = windows::Win32::Storage::FileSystem::FindFirstFileW(path.as_ptr(), &mut data);
7272

73-
if handle == winapi::um::handleapi::INVALID_HANDLE_VALUE {
73+
if handle == windows::Win32::Foundation::INVALID_HANDLE_VALUE {
7474
Err(io::Error::from_raw_os_error(GetLastError() as i32))
7575
} else {
7676
// Close the handle opened by FindFirstfileW.
77-
winapi::um::fileapi::FindClose(handle);
77+
windows::Win32::Storage::FileSystem::FindClose(handle);
7878
Ok(data)
7979
}
8080
}
@@ -86,7 +86,7 @@ pub fn is_unix_socket(path: &Path) -> io::Result<bool> {
8686

8787
let data = find_first_file_data(path)?;
8888
Ok(
89-
data.dwFileAttributes & winapi::um::winnt::FILE_ATTRIBUTE_REPARSE_POINT != 0
89+
data.dwFileAttributes & windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_REPARSE_POINT != 0
9090
&& data.dwReserved0 == IO_REPARSE_TAG_AF_UNIX,
9191
)
9292
}

support/pal/src/windows/job.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Job {
2121
pub fn new() -> io::Result<Self> {
2222
// SAFETY: `CreateJobObjectW` returns an owned handle or null.
2323
unsafe {
24-
let job = winapi::um::jobapi2::CreateJobObjectW(null_mut(), null());
24+
let job = windows::Win32::System::JobObjects::CreateJobObjectW(null_mut(), null());
2525
if job.is_null() {
2626
return Err(io::Error::last_os_error());
2727
}
@@ -34,19 +34,19 @@ impl Job {
3434
pub fn set_terminate_on_close(&self) -> io::Result<()> {
3535
// SAFETY: It is safe to initialize this C structure using `zeroed`.
3636
let mut info = unsafe {
37-
winapi::um::winnt::JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
38-
BasicLimitInformation: winapi::um::winnt::JOBOBJECT_BASIC_LIMIT_INFORMATION {
39-
LimitFlags: winapi::um::winnt::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
37+
windows::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
38+
BasicLimitInformation: windows::Win32::System::JobObjects::JOBOBJECT_BASIC_LIMIT_INFORMATION {
39+
LimitFlags: windows::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
4040
..zeroed()
4141
},
4242
..zeroed()
4343
}
4444
};
4545
// SAFETY: `SetInformationJobObject` is safe to call with a valid handle.
4646
let r = unsafe {
47-
winapi::um::jobapi2::SetInformationJobObject(
47+
windows::Win32::System::JobObjects::SetInformationJobObject(
4848
self.0.as_raw_handle(),
49-
winapi::um::winnt::JobObjectExtendedLimitInformation,
49+
windows::Win32::System::JobObjects::JobObjectExtendedLimitInformation,
5050
std::ptr::from_mut(&mut info).cast(),
5151
size_of_val(&info) as u32,
5252
)

support/pal/src/windows/pipe.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ use std::path::Path;
3939
use std::ptr::null_mut;
4040
use std::sync::atomic::AtomicPtr;
4141
use std::sync::atomic::Ordering;
42-
use winapi::shared::ntdef;
43-
use winapi::shared::ntstatus::STATUS_NAME_TOO_LONG;
44-
use winapi::um::namedpipeapi;
45-
use winapi::um::namedpipeapi::DisconnectNamedPipe;
46-
use winapi::um::namedpipeapi::GetNamedPipeInfo;
47-
use winapi::um::winbase::PIPE_SERVER_END;
48-
use winapi::um::winioctl;
49-
use winapi::um::winnt;
42+
use windows::Wdk::Foundation::STATUS_NAME_TOO_LONG;
43+
use windows::Win32::System::Pipes::DisconnectNamedPipe;
44+
use windows::Win32::System::Pipes::GetNamedPipeInfo;
45+
use windows::Win32::System::Pipes::PIPE_SERVER_END;
5046
use winnt::FILE_READ_ATTRIBUTES;
5147
use winnt::FILE_SHARE_READ;
5248
use winnt::FILE_SHARE_WRITE;
@@ -333,7 +329,7 @@ impl PipeExt for File {
333329
null_mut(),
334330
0,
335331
);
336-
if status != winapi::shared::ntstatus::STATUS_NOT_SUPPORTED {
332+
if status != windows::Win32::Foundation::STATUS_NOT_SUPPORTED {
337333
break;
338334
}
339335
}

support/pal/src/windows/process.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ use std::os::windows::prelude::*;
1414
use std::ptr::null;
1515
use std::ptr::null_mut;
1616
use widestring::U16CString;
17-
use winapi::shared::winerror::ERROR_INVALID_PARAMETER;
18-
use winapi::um::handleapi::SetHandleInformation;
19-
use winapi::um::processenv::GetStdHandle;
20-
use winapi::um::processthreadsapi::CreateProcessAsUserW;
21-
use winapi::um::processthreadsapi::DeleteProcThreadAttributeList;
22-
use winapi::um::processthreadsapi::InitializeProcThreadAttributeList;
23-
use winapi::um::processthreadsapi::LPPROC_THREAD_ATTRIBUTE_LIST;
24-
use winapi::um::processthreadsapi::STARTUPINFOW;
25-
use winapi::um::processthreadsapi::TerminateProcess;
26-
use winapi::um::processthreadsapi::UpdateProcThreadAttribute;
27-
use winapi::um::winbase::CREATE_SUSPENDED;
28-
use winapi::um::winbase::CREATE_UNICODE_ENVIRONMENT;
29-
use winapi::um::winbase::EXTENDED_STARTUPINFO_PRESENT;
30-
use winapi::um::winbase::HANDLE_FLAG_INHERIT;
31-
use winapi::um::winbase::STARTF_USESTDHANDLES;
32-
use winapi::um::winbase::STARTUPINFOEXW;
33-
use winapi::um::winbase::STD_ERROR_HANDLE;
34-
use winapi::um::winbase::STD_INPUT_HANDLE;
35-
use winapi::um::winbase::STD_OUTPUT_HANDLE;
17+
use windows::Win32::Foundation::ERROR_INVALID_PARAMETER;
18+
use windows::Win32::Foundation::SetHandleInformation;
19+
use windows::Win32::Foundation::GetStdHandle;
20+
use windows::Win32::System::Threading::CreateProcessAsUserW;
21+
use windows::Win32::System::Threading::DeleteProcThreadAttributeList;
22+
use windows::Win32::System::Threading::InitializeProcThreadAttributeList;
23+
use windows::Win32::System::Threading::LPPROC_THREAD_ATTRIBUTE_LIST;
24+
use windows::Win32::System::Threading::STARTUPINFOW;
25+
use windows::Win32::System::Threading::TerminateProcess;
26+
use windows::Win32::System::Threading::UpdateProcThreadAttribute;
27+
use windows::Win32::System::Threading::CREATE_SUSPENDED;
28+
use windows::Win32::System::Threading::CREATE_UNICODE_ENVIRONMENT;
29+
use windows::Win32::System::Threading::EXTENDED_STARTUPINFO_PRESENT;
30+
use windows::Win32::Foundation::HANDLE_FLAG_INHERIT;
31+
use windows::Win32::System::Threading::STARTF_USESTDHANDLES;
32+
use windows::Win32::System::Threading::STARTUPINFOEXW;
33+
use windows::Win32::System::Threading::STD_ERROR_HANDLE;
34+
use windows::Win32::System::Threading::STD_INPUT_HANDLE;
35+
use windows::Win32::System::Threading::STD_OUTPUT_HANDLE;
3636

3737
const PROC_THREAD_ATTRIBUTE_HANDLE_LIST: u32 = 0x00020002;
3838
const PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY: u32 = 0x000020007;

0 commit comments

Comments
 (0)