shadow_rs/host/syscall/
mod.rs

1use linux_api::syscall::SyscallNum;
2use shadow_shim_helper_rs::shadow_syscalls::ShadowSyscallNum;
3
4use crate::cshadow as c;
5use crate::host::descriptor::{File, FileState};
6
7pub mod condition;
8pub mod formatter;
9pub mod handler;
10pub mod io;
11pub mod type_formatting;
12pub mod types;
13
14/// Is the syscall a Shadow-specific syscall?
15fn is_shadow_syscall(n: SyscallNum) -> bool {
16    ShadowSyscallNum::try_from(n).is_ok()
17}
18
19// The helpers defined here are syscall-related but not handler-specific.
20
21pub struct Trigger(c::Trigger);
22
23impl From<c::Trigger> for Trigger {
24    fn from(trigger: c::Trigger) -> Self {
25        Self(trigger)
26    }
27}
28
29impl From<Trigger> for c::Trigger {
30    fn from(trigger: Trigger) -> Self {
31        trigger.0
32    }
33}
34
35impl Trigger {
36    pub fn from_file(file: File, state: FileState) -> Self {
37        let file_ptr = Box::into_raw(Box::new(file));
38
39        Self(c::Trigger {
40            type_: c::_TriggerType_TRIGGER_FILE,
41            object: c::TriggerObject { as_file: file_ptr },
42            state,
43        })
44    }
45
46    pub fn child() -> Self {
47        Self(c::Trigger {
48            type_: c::_TriggerType_TRIGGER_CHILD,
49            object: c::TriggerObject {
50                as_pointer: core::ptr::null_mut(),
51            },
52            state: FileState::CHILD_EVENT,
53        })
54    }
55}