crabpot 0.5.10

Native Rust sandbox runtime for AI agents, rewritten from Anthropic's sandbox-runtime
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! The Windows call crabpot makes to find a process's session.
//! srt-win's equivalent is private to `winsta.rs`.

#![allow(unsafe_code)]

use windows_sys::Win32::System::RemoteDesktop::ProcessIdToSessionId;

/// The session `pid` runs in, or `None` when the call fails.
pub(super) fn session_of(pid: u32) -> Option<u32> {
    let mut session = 0u32;
    // SAFETY: `session` is a live `u32` the call writes through for its
    // duration, and `pid` is a plain value the call only reads.
    let found = unsafe { ProcessIdToSessionId(pid, &mut session) };
    (found != 0).then_some(session)
}