shadow_shim_helper_rs/
ipc.rs

1use vasi::VirtualAddressSpaceIndependent;
2use vasi_sync::scchannel::SelfContainedChannel;
3
4use crate::shim_event::{ShimEventToShadow, ShimEventToShim};
5
6/// Manages communication between the Shadow process and the shim library
7/// running inside Shadow managed threads.
8#[derive(VirtualAddressSpaceIndependent)]
9#[repr(C)]
10// In the microbenchmarks introduced in
11// https://github.com/shadow/shadow/pull/2791, adding a large alignment to
12// the mock IPC helped make some measurement artifacts go away by ensuring
13// the two channels are on the same cache line.
14pub struct IPCData {
15    shadow_to_plugin: SelfContainedChannel<ShimEventToShim>,
16    plugin_to_shadow: SelfContainedChannel<ShimEventToShadow>,
17}
18
19impl IPCData {
20    pub fn new() -> Self {
21        Self {
22            shadow_to_plugin: SelfContainedChannel::new(),
23            plugin_to_shadow: SelfContainedChannel::new(),
24        }
25    }
26
27    /// Returns a reference to the "Shadow to Plugin" channel.
28    pub fn to_plugin(&self) -> &SelfContainedChannel<ShimEventToShim> {
29        &self.shadow_to_plugin
30    }
31
32    /// Returns a reference to the "Plugin to Shadow" channel.
33    pub fn to_shadow(&self) -> &SelfContainedChannel<ShimEventToShadow> {
34        &self.plugin_to_shadow
35    }
36
37    /// Returns a reference to the "Plugin to Shadow" channel.
38    pub fn from_plugin(&self) -> &SelfContainedChannel<ShimEventToShadow> {
39        &self.plugin_to_shadow
40    }
41
42    /// Returns a reference to the "Shadow to Plugin" channel.
43    pub fn from_shadow(&self) -> &SelfContainedChannel<ShimEventToShim> {
44        &self.shadow_to_plugin
45    }
46}
47
48impl Default for IPCData {
49    fn default() -> Self {
50        Self::new()
51    }
52}