| 2461 | #[cfg(windows)] |
| 2462 | #[pymethod] |
| 2463 | fn share(&self, process_id: u32, _vm: &VirtualMachine) -> Result<Vec<u8>, IoOrPyException> { |
| 2464 | let sock = self.sock()?; |
| 2465 | let fd = sock_fileno(&sock); |
| 2466 | |
| 2467 | let mut info: MaybeUninit<c::WSAPROTOCOL_INFOW> = MaybeUninit::uninit(); |
| 2468 | |
| 2469 | let ret = unsafe { c::WSADuplicateSocketW(fd as _, process_id, info.as_mut_ptr()) }; |
| 2470 | |
| 2471 | if ret == c::SOCKET_ERROR { |
| 2472 | return Err(Self::wsa_error().into()); |
| 2473 | } |
| 2474 | |
| 2475 | let info = unsafe { info.assume_init() }; |
| 2476 | let bytes = unsafe { |
| 2477 | core::slice::from_raw_parts( |
| 2478 | &info as *const c::WSAPROTOCOL_INFOW as *const u8, |
| 2479 | core::mem::size_of::<c::WSAPROTOCOL_INFOW>(), |
| 2480 | ) |
| 2481 | }; |
| 2482 | |
| 2483 | Ok(bytes.to_vec()) |
| 2484 | } |
| 2485 | |
| 2486 | #[pygetset(name = "type")] |
| 2487 | fn kind(&self) -> i32 { |