fix: add Win32_Storage_FileSystem feature and improve handle closing logic (#17374)

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

fix https://github.com/astral-sh/uv/issues/17174 mentioned the invalid
issues here:

results of diagnostics:

before:
```
--- TRAMPOLINE DIAGNOSTICS: STARTUP ---
  STDIN: Handle=184
    -> Console Mode: 503
  STDOUT: Handle=536
    -> Console Mode: 7
  STDERR: Handle=540
    -> Console Mode: 7
-------------------------------------------
--- TRAMPOLINE DIAGNOSTICS: AFTER CLOSE_HANDLES ---
  STDIN: INVALID
  STDOUT: INVALID
  STDERR: Handle=540
    -> Console Mode: 7
```

after:
```
--- TRAMPOLINE DIAGNOSTICS: STARTUP ---
  STDIN: Handle=716
    -> Console Mode: 503
  STDOUT: Handle=580
    -> Console Mode: 7
  STDERR: Handle=604
    -> Console Mode: 7
-------------------------------------------
--- TRAMPOLINE DIAGNOSTICS: AFTER CLOSE_HANDLES ---
  STDIN: Handle=716
    -> Console Mode: 503
  STDOUT: Handle=580
    -> Console Mode: 7
  STDERR: Handle=604
    -> Console Mode: 7
```

the problem was we were closing the handlers whatever they were from
pipes (byte streams) or consoles, this will make sure we close only the
handlers from pipes by using `FILE_TYPE_PIPE`

## Test Plan

<!-- How was it tested? -->
completely manual by adding debug statements and running a simple script
to open the pdb.
This commit is contained in:
Denizhan Dakılır
2026-01-10 21:11:13 +03:00
committed by GitHub
parent c10c84a588
commit 7e7f1656ca
2 changed files with 5 additions and 0 deletions
+1
View File
@@ -47,6 +47,7 @@ windows = { version = "0.61.0", features = [
"Win32_System_LibraryLoader",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
"Win32_Storage_FileSystem",
] }
ufmt-write = "0.1.0"
ufmt = { version = "0.2.0", features = ["std"] }
+4
View File
@@ -8,6 +8,7 @@ use windows::Win32::{
Foundation::{
CloseHandle, HANDLE, HANDLE_FLAG_INHERIT, INVALID_HANDLE_VALUE, SetHandleInformation, TRUE,
},
Storage::FileSystem::{FILE_TYPE_PIPE, GetFileType},
System::Console::{
GetStdHandle, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, SetConsoleCtrlHandler, SetStdHandle,
},
@@ -345,6 +346,9 @@ fn close_handles(si: &STARTUPINFOA) {
// Unlike cleanup_standard_io(), we don't close STD_ERROR_HANDLE to retain warn!
for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE] {
if let Ok(handle) = unsafe { GetStdHandle(std_handle) } {
if handle.is_invalid() || unsafe { GetFileType(handle) } != FILE_TYPE_PIPE {
continue;
}
unsafe { CloseHandle(handle) }.unwrap_or_else(|_| {
warn!("Failed to close standard device handle {}", handle.0 as u32);
});