endpoint_sec/event/event_get_task_inspect.rs
1//! [`EventGetTaskInspect`]
2
3use endpoint_sec_sys::{es_event_get_task_inspect_t, es_get_task_type_t};
4
5use crate::Process;
6
7/// Get a process's task inspect port.
8///
9/// This event is fired when a process obtains a send right to a task inspect
10/// port (e.g. `task_inspect_for_pid()`, `task_identity_token_get_task_port()`).
11#[doc(alias = "es_event_get_task_inspect_t")]
12pub struct EventGetTaskInspect<'a> {
13 /// Raw reference
14 pub(crate) raw: &'a es_event_get_task_inspect_t,
15 /// Message version
16 pub(crate) version: u32,
17}
18
19impl<'a> EventGetTaskInspect<'a> {
20 /// Process for which the task inspect port will be retrieved.
21 #[inline(always)]
22 pub fn target(&self) -> Process<'a> {
23 // Safety: 'a tied to self, object obtained through ES
24 Process::new(unsafe { self.raw.target() }, self.version)
25 }
26
27 /// Indicates how the process is obtaining the task for the target process.
28 ///
29 /// Note: only available if message version >= 5.
30 #[inline(always)]
31 pub fn type_(&self) -> Option<es_get_task_type_t> {
32 if self.version < 5 {
33 None
34 } else {
35 Some(self.raw.type_)
36 }
37 }
38}
39
40// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
41unsafe impl Send for EventGetTaskInspect<'_> {}
42// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
43unsafe impl Sync for EventGetTaskInspect<'_> {}
44
45impl_debug_eq_hash_with_functions!(EventGetTaskInspect<'a> with version; target, type_);