Skip to main content

detcore/
record_or_replay.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9use reverie::Error;
10use reverie::Guest;
11use reverie::Subscription;
12use reverie::Tool;
13use reverie::syscalls::Syscall;
14use serde::Deserialize;
15use serde::Serialize;
16
17use crate::config::Config;
18use crate::tool_global::GlobalState;
19
20/// Helper trait.
21pub trait RecordOrReplay: Tool<GlobalState = GlobalState> {}
22
23impl<T> RecordOrReplay for T where T: Tool<GlobalState = GlobalState> {}
24
25/// A tool that only injects the syscall it receives.
26#[derive(Debug, Default, Serialize, Deserialize)]
27pub struct NoopTool;
28
29#[reverie::tool]
30impl Tool for NoopTool {
31    type GlobalState = GlobalState;
32    type ThreadState = ();
33
34    fn subscriptions(_cfg: &Config) -> Subscription {
35        // Don't subscribe to anything by default. This noop-tool doesn't care
36        // about any syscalls and will be ORed with the detcore subscriptions.
37        Subscription::none()
38    }
39
40    async fn handle_syscall_event<T: Guest<Self>>(
41        &self,
42        guest: &mut T,
43        call: Syscall,
44    ) -> Result<i64, Error> {
45        // NOTE: Cannot use tail_inject here as that would prevent any detcore
46        // post-hook code from running.
47        Ok(guest.inject(call).await?)
48    }
49}