Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix winapi Handle
  • Loading branch information
youknowone committed Dec 7, 2025
commit 98c68c450450bd0faeb40a0b5aa025eb490649c1
19 changes: 15 additions & 4 deletions crates/vm/src/stdlib/winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod _winapi {
Win32::Foundation::{HANDLE, HINSTANCE, MAX_PATH},
core::PCWSTR,
};
use windows_sys::Win32::Foundation::{BOOL, HANDLE as RAW_HANDLE};
use windows_sys::Win32::Foundation::{BOOL, INVALID_HANDLE_VALUE};

#[pyattr]
use windows_sys::Win32::{
Expand Down Expand Up @@ -87,8 +87,18 @@ mod _winapi {
#[pyfunction]
fn GetStdHandle(
std_handle: windows_sys::Win32::System::Console::STD_HANDLE,
) -> WindowsSysResult<RAW_HANDLE> {
WindowsSysResult(unsafe { windows_sys::Win32::System::Console::GetStdHandle(std_handle) })
vm: &VirtualMachine,
) -> PyResult<Option<HANDLE>> {
let handle = unsafe { windows_sys::Win32::System::Console::GetStdHandle(std_handle) };
if handle == INVALID_HANDLE_VALUE {
return Err(errno_err(vm));
}
Ok(if handle.is_null() {
// NULL handle - return None
None
} else {
Some(HANDLE(handle as isize))
})
}

#[pyfunction]
Expand All @@ -114,7 +124,8 @@ mod _winapi {

#[pyfunction]
fn DuplicateHandle(
(src_process, src): (HANDLE, HANDLE),
src_process: HANDLE,
src: HANDLE,
target_process: HANDLE,
access: u32,
inherit: BOOL,
Expand Down