endpoint_sec/event/
event_get_task.rs

1//! [`EventGetTask`]
2
3use endpoint_sec_sys::{es_event_get_task_t, es_get_task_type_t};
4
5use crate::Process;
6
7/// Get a process's task control port event.
8#[doc(alias = "es_event_get_task_t")]
9pub struct EventGetTask<'a> {
10    /// The raw reference.
11    pub(crate) raw: &'a es_event_get_task_t,
12
13    /// The version of the message.
14    pub(crate) version: u32,
15}
16
17impl<'a> EventGetTask<'a> {
18    /// Type indicating how the process is obtaining the task port for the target process on version 5 or later, otherwise None.
19    #[inline(always)]
20    pub fn task_type(&self) -> Option<es_get_task_type_t> {
21        if self.version >= 5 {
22            Some(self.raw.type_)
23        } else {
24            None
25        }
26    }
27
28    /// The process for which the task control port will be retrieved.
29    #[inline(always)]
30    pub fn target(&self) -> Process<'a> {
31        // Safety: 'a tied to self, object obtained through ES
32        Process::new(unsafe { self.raw.target() }, self.version)
33    }
34}
35
36// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
37unsafe impl Send for EventGetTask<'_> {}
38// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
39unsafe impl Sync for EventGetTask<'_> {}
40
41impl_debug_eq_hash_with_functions!(EventGetTask<'a> with version; task_type, target);