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};
6use crate::host::futex_table::FutexRef;
7
8pub mod condition;
9pub mod formatter;
10pub mod handler;
11pub mod io;
12pub mod type_formatting;
13pub mod types;
14
15/// Is the syscall a Shadow-specific syscall?
16fn is_shadow_syscall(n: SyscallNum) -> bool {
17    ShadowSyscallNum::try_from(n).is_ok()
18}
19
20// The helpers defined here are syscall-related but not handler-specific.
21
22pub struct Trigger(c::Trigger);
23
24impl From<c::Trigger> for Trigger {
25    fn from(trigger: c::Trigger) -> Self {
26        Self(trigger)
27    }
28}
29
30impl From<Trigger> for c::Trigger {
31    fn from(trigger: Trigger) -> Self {
32        trigger.0
33    }
34}
35
36impl Trigger {
37    pub fn from_file(file: File, state: FileState) -> Self {
38        let file_ptr = Box::into_raw(Box::new(file));
39
40        Self(c::Trigger {
41            type_: c::_TriggerType_TRIGGER_FILE,
42            object: c::TriggerObject { as_file: file_ptr },
43            state,
44        })
45    }
46
47    pub fn from_futex(futex: FutexRef) -> Self {
48        let futex = futex.into_c_ptr();
49
50        Self(c::Trigger {
51            type_: c::_TriggerType_TRIGGER_FUTEX,
52            object: c::TriggerObject { as_futex: futex },
53            state: FileState::FUTEX_WAKEUP,
54        })
55    }
56
57    pub fn child() -> Self {
58        Self(c::Trigger {
59            type_: c::_TriggerType_TRIGGER_CHILD,
60            object: c::TriggerObject {
61                as_pointer: core::ptr::null_mut(),
62            },
63            state: FileState::CHILD_EVENT,
64        })
65    }
66}