(vm: &VirtualMachine)
| 2018 | |
| 2019 | #[pyfunction] |
| 2020 | fn pipe(vm: &VirtualMachine) -> PyResult<(i32, i32)> { |
| 2021 | use windows_sys::Win32::Security::SECURITY_ATTRIBUTES; |
| 2022 | use windows_sys::Win32::System::Pipes::CreatePipe; |
| 2023 | |
| 2024 | let mut attr = SECURITY_ATTRIBUTES { |
| 2025 | nLength: core::mem::size_of::<SECURITY_ATTRIBUTES>() as u32, |
| 2026 | lpSecurityDescriptor: core::ptr::null_mut(), |
| 2027 | bInheritHandle: 0, |
| 2028 | }; |
| 2029 | |
| 2030 | let (read_handle, write_handle) = unsafe { |
| 2031 | let mut read = MaybeUninit::<isize>::uninit(); |
| 2032 | let mut write = MaybeUninit::<isize>::uninit(); |
| 2033 | let res = CreatePipe( |
| 2034 | read.as_mut_ptr() as *mut _, |
| 2035 | write.as_mut_ptr() as *mut _, |
| 2036 | &mut attr as *mut _, |
| 2037 | 0, |
| 2038 | ); |
| 2039 | if res == 0 { |
| 2040 | return Err(vm.new_last_os_error()); |
| 2041 | } |
| 2042 | (read.assume_init(), write.assume_init()) |
| 2043 | }; |
| 2044 | |
| 2045 | // Convert handles to file descriptors |
| 2046 | // O_NOINHERIT = 0x80 (MSVC CRT) |
| 2047 | const O_NOINHERIT: i32 = 0x80; |
| 2048 | let read_fd = unsafe { libc::open_osfhandle(read_handle, O_NOINHERIT) }; |
| 2049 | let write_fd = unsafe { libc::open_osfhandle(write_handle, libc::O_WRONLY | O_NOINHERIT) }; |
| 2050 | |
| 2051 | if read_fd == -1 || write_fd == -1 { |
| 2052 | unsafe { |
| 2053 | Foundation::CloseHandle(read_handle as _); |
| 2054 | Foundation::CloseHandle(write_handle as _); |
| 2055 | } |
| 2056 | return Err(vm.new_last_os_error()); |
| 2057 | } |
| 2058 | |
| 2059 | Ok((read_fd, write_fd)) |
| 2060 | } |
| 2061 | |
| 2062 | #[pyfunction] |
| 2063 | fn getppid() -> u32 { |
nothing calls this directly
no test coverage detected