Skip to main content

endpoint_sec/event/
event_get_task_read.rs

1//! [`EventGetTaskRead`]
2
3use endpoint_sec_sys::{es_event_get_task_read_t, es_get_task_type_t};
4
5use crate::Process;
6
7/// Get a process's task read port.
8///
9/// This event is fired when a process obtains a send right to a task read
10/// port (e.g. `task_read_for_pid()`, `task_identity_token_get_task_port()`).
11#[doc(alias = "es_event_get_task_read_t")]
12pub struct EventGetTaskRead<'a> {
13    /// Raw reference
14    pub(crate) raw: &'a es_event_get_task_read_t,
15    /// Message version
16    pub(crate) version: u32,
17}
18
19impl<'a> EventGetTaskRead<'a> {
20    /// Process for which the task read 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 EventGetTaskRead<'_> {}
42// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
43unsafe impl Sync for EventGetTaskRead<'_> {}
44
45impl_debug_eq_hash_with_functions!(EventGetTaskRead<'a> with version; target, type_);