Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust close_handles pointer offsets to match distlib cleanup_fds #6955

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions crates/uv-trampoline/src/bounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,23 @@ fn close_handles(si: &STARTUPINFOA) {
if si.cbReserved2 == 0 || si.lpReserved2.is_null() {
return;
}

let crt_magic = si.lpReserved2 as *const u32;
let handle_count = unsafe { crt_magic.read_unaligned() } as isize;
let handle_start = unsafe { crt_magic.offset(1 + handle_count) };
for i in 0..handle_count {
let handle = HANDLE(unsafe { handle_start.offset(i).read_unaligned() as _ });
// Close all fds inherited from the parent, except for the standard I/O fds.
if !handle.is_invalid() {
unsafe { CloseHandle(handle) }.unwrap_or_else(|_| {
eprintln!("Failed to close child file descriptors at {}", i);
});
let handle_start =
unsafe { (crt_magic.offset(1) as *const u8).offset(handle_count) as *const HANDLE };

// Close all fds inherited from the parent, except for the standard I/O fds (skip first 3).
for i in 3..handle_count {
let handle = unsafe { handle_start.offset(i).read_unaligned() };
// Ignore invalid handles, as that means this fd was not inherited.
// -2 is a special value (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle)
if handle.is_invalid() || handle.0 == -2 as _ {
continue;
}
unsafe { CloseHandle(handle) }.unwrap_or_else(|_| {
eprintln!("Failed to close child file descriptors at {}", i);
});
}
}

Expand Down
Binary file not shown.
Binary file modified crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe
Binary file not shown.
Binary file modified crates/uv-trampoline/trampolines/uv-trampoline-i686-console.exe
Binary file not shown.
Binary file modified crates/uv-trampoline/trampolines/uv-trampoline-i686-gui.exe
Binary file not shown.
Binary file not shown.
Binary file modified crates/uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe
Binary file not shown.
Loading