cosca 0.10.0

Unified cross-platform subprocess management: spawning, stdio, process trees, stable identity, and elevation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! A Windows handle on which every `WaitForSingleObject` fails.

use std::os::windows::io::{FromRawHandle, OwnedHandle};

use windows::Win32::System::Threading::{GetCurrentProcessId, OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION};

/// A handle to this process opened without `SYNCHRONIZE`, so a wait on it fails with
/// `ERROR_ACCESS_DENIED`. Unlike a closed handle's value, it stays this test's until dropped: no
/// other thread can be handed the same value.
pub(crate) fn unwaitable_handle() -> OwnedHandle {
    // SAFETY: opening this process has no preconditions.
    let opened = unsafe { OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, GetCurrentProcessId()) }
        .expect("open this process without SYNCHRONIZE");
    // SAFETY: `opened` is a fresh owned handle from `OpenProcess`.
    unsafe { OwnedHandle::from_raw_handle(opened.0) }
}