Skip to main content

enclave_runner_sgx/
command.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7use std::path::Path;
8
9use anyhow::Error;
10use enclave_runner::platform::CommandConfiguration;
11use enclave_runner::stream_router::StreamRouter;
12use sgxs::loader::Load;
13
14use crate::loader::{EnclaveBuilder, ErasedTcs};
15use crate::usercalls::EnclaveState;
16use std::os::raw::c_void;
17
18pub struct Command {
19    _private: (),
20}
21
22impl Command {
23    /// # Panics
24    /// Panics if the number of TCSs is 0.
25    pub(crate) fn internal_new(
26        mut tcss: Vec<ErasedTcs>,
27        _address: *mut c_void,
28        _size: usize,
29        stream_router: Box<dyn StreamRouter>,
30        forward_panics: bool,
31        force_time_usercalls: bool,
32        cmd_configuration: CommandConfiguration,
33    ) -> enclave_runner::Command {
34        (Box::new(move || {
35            let main = tcss.remove(0);
36
37            EnclaveState::main_entry(
38                main,
39                tcss,
40                stream_router,
41                forward_panics,
42                force_time_usercalls,
43                cmd_configuration,
44            )
45        }) as Box<dyn FnOnce() -> _>)
46            .into()
47    }
48
49    pub fn new<P: AsRef<Path>, L: Load>(
50        enclave_path: P,
51        loader: &mut L,
52    ) -> Result<enclave_runner::Command, Error> {
53        enclave_runner::EnclaveBuilder::new(EnclaveBuilder::new(enclave_path.as_ref()))
54            .build(loader)
55    }
56}