endpoint_sec/event/event_mmap.rs
1//! [`EventMmap`]
2
3use endpoint_sec_sys::es_event_mmap_t;
4
5use crate::File;
6
7/// Memory map a file event.
8#[doc(alias = "es_event_mmap_t")]
9pub struct EventMmap<'a> {
10 /// Raw event
11 pub(crate) raw: &'a es_event_mmap_t,
12}
13
14impl<'a> EventMmap<'a> {
15 /// The protection (region accessibility) value.
16 #[inline(always)]
17 pub fn protection(&self) -> i32 {
18 self.raw.protection
19 }
20
21 /// The maximum allowed protection value the operating system will respect.
22 #[inline(always)]
23 pub fn max_protection(&self) -> i32 {
24 self.raw.max_protection
25 }
26
27 /// The type and attributes of the mapped file.
28 #[inline(always)]
29 pub fn flags(&self) -> i32 {
30 self.raw.flags
31 }
32
33 /// The offset into the source file that will be mapped.
34 #[inline(always)]
35 pub fn file_pos(&self) -> u64 {
36 self.raw.file_pos
37 }
38
39 /// The file system object being mapped.
40 #[inline(always)]
41 pub fn source(&self) -> File<'a> {
42 // Safety: 'a tied to self, object obtained through ES
43 File::new(unsafe { self.raw.source() })
44 }
45}
46
47// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
48unsafe impl Send for EventMmap<'_> {}
49// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
50unsafe impl Sync for EventMmap<'_> {}
51
52impl_debug_eq_hash_with_functions!(EventMmap<'a>; protection, max_protection, flags, file_pos, source);