1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use linux_api::syscall::SyscallNum;

use crate::cshadow as c;
use crate::host::descriptor::{File, FileState};

pub mod condition;
pub mod formatter;
pub mod handler;
pub mod io;
pub mod type_formatting;
pub mod types;

/// Is the syscall a Shadow-specific syscall?
fn is_shadow_syscall(n: SyscallNum) -> bool {
    n.val() >= c::ShadowSyscallNum_SYS_shadow_min && n.val() <= c::ShadowSyscallNum_SYS_shadow_max
}

// The helpers defined here are syscall-related but not handler-specific.

pub struct Trigger(c::Trigger);

impl From<c::Trigger> for Trigger {
    fn from(trigger: c::Trigger) -> Self {
        Self(trigger)
    }
}

impl From<Trigger> for c::Trigger {
    fn from(trigger: Trigger) -> Self {
        trigger.0
    }
}

impl Trigger {
    pub fn from_file(file: File, state: FileState) -> Self {
        let file_ptr = Box::into_raw(Box::new(file));

        Self(c::Trigger {
            type_: c::_TriggerType_TRIGGER_FILE,
            object: c::TriggerObject { as_file: file_ptr },
            state,
        })
    }

    pub fn child() -> Self {
        Self(c::Trigger {
            type_: c::_TriggerType_TRIGGER_CHILD,
            object: c::TriggerObject {
                as_pointer: core::ptr::null_mut(),
            },
            state: FileState::CHILD_EVENT,
        })
    }
}