Skip to content

Commit

Permalink
runtime-loader: Remove unused ELF loader, bump clap to 4.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Oct 6, 2022
1 parent 7912195 commit 9a79562
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 101 deletions.
1 change: 1 addition & 0 deletions .changelog/4969.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime-loader: Remove unused ELF loader
34 changes: 8 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions runtime-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["Oasis Protocol Foundation <[email protected]>"]
edition = "2018"

[dependencies]
clap = "3.2.22"
failure = "0.1.5"
clap = "4.0.10"
anyhow = "1.0"
futures = { version = "0.3.17", features = ["compat", "io-compat"] }
# NOTE: The version of tokio is constrained by what the upstream enclave-runner is using.
tokio = { version = "0.2", features = ["full"] }
Expand Down
35 changes: 13 additions & 22 deletions runtime-loader/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,54 @@ use std::path::Path;

use clap::{Arg, Command};

use oasis_core_runtime_loader::Loader;
#[cfg(target_os = "linux")]
use oasis_core_runtime_loader::SgxsLoader;
use oasis_core_runtime_loader::{ElfLoader, Loader};

fn main() {
let matches = Command::new("Oasis runtime loader")
let matches = Command::new("Oasis Core Runtime Loader")
.arg(
Arg::new("type")
.long("type")
.help("Runtime type")
.possible_values(&["sgxs", "elf"])
.takes_value(true)
.value_parser(["sgxs"])
.default_value("sgxs"),
)
.arg(
Arg::new("runtime")
.value_name("RUNTIME")
.help("Runtime filename")
.takes_value(true)
.required(true),
)
.arg(
Arg::new("signature")
.long("signature")
.help("Signature filename")
.takes_value(true),
)
.arg(
Arg::new("host-socket")
.long("host-socket")
.takes_value(true)
.required(true),
.help("Signature filename"),
)
.arg(Arg::new("host-socket").long("host-socket").required(true))
.get_matches();

// Check if passed runtime exists.
let filename = matches.value_of("runtime").unwrap().to_owned();
let filename = matches.get_one::<String>("runtime").unwrap();
assert!(
Path::new(&filename).exists(),
Path::new(filename).exists(),
"Could not find runtime: {}",
filename
);

// Decode arguments.
let host_socket = matches
.value_of_t::<String>("host-socket")
.unwrap_or_else(|e| e.exit());
let mode = matches.value_of("type").unwrap();
let signature = matches.value_of("signature");
let host_socket = matches.get_one::<String>("host-socket").unwrap();
let mode = matches.get_one::<String>("type").unwrap();
let signature = matches
.get_one::<String>("signature")
.map(|sig| sig.as_ref());

// Create appropriate loader and run the runtime.
let loader: Box<dyn Loader> = match mode {
let loader: Box<dyn Loader> = match mode.as_ref() {
#[cfg(target_os = "linux")]
"sgxs" => Box::new(SgxsLoader),
#[cfg(not(target_os = "linux"))]
"sgxs" => panic!("SGXS loader is only supported on Linux"),
"elf" => Box::new(ElfLoader),
_ => panic!("Invalid runtime type specified"),
};
loader
Expand Down
31 changes: 0 additions & 31 deletions runtime-loader/src/elf.rs

This file was deleted.

10 changes: 4 additions & 6 deletions runtime-loader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
//! Oasis runtime loader.
pub mod elf;
#[cfg(target_os = "linux")]
pub mod sgxs;

use failure::Fallible;
use anyhow::Result;

/// Runtime loader.
pub trait Loader {
/// Load and run the specified runtime.
fn run(
&self,
filename: String,
filename: &str,
signature_filename: Option<&str>,
host_socket: String,
) -> Fallible<()>;
host_socket: &str,
) -> Result<()>;
}

// Re-exports.
pub use elf::ElfLoader;
#[cfg(target_os = "linux")]
pub use sgxs::SgxsLoader;
27 changes: 13 additions & 14 deletions runtime-loader/src/sgxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::{
};

use aesm_client::AesmClient;
use anyhow::{anyhow, Result};
use enclave_runner::{
usercalls::{AsyncStream, UsercallExtension},
EnclaveBuilder,
};
use failure::{format_err, Fallible};
use futures::future::FutureExt;
use sgxs_loaders::isgx::Device as IsgxDevice;
use tokio::net::UnixStream;
Expand All @@ -24,8 +24,10 @@ struct HostService {
}

impl HostService {
fn new(host_socket: String) -> HostService {
HostService { host_socket }
fn new(host_socket: &str) -> HostService {
HostService {
host_socket: host_socket.to_owned(),
}
}
}

Expand Down Expand Up @@ -58,16 +60,11 @@ pub struct SgxsLoader;
impl Loader for SgxsLoader {
fn run(
&self,
filename: String,
filename: &str,
signature_filename: Option<&str>,
host_socket: String,
) -> Fallible<()> {
let sig = match signature_filename {
Some(f) => f,
None => {
return Err(format_err!("signature file is required"));
}
};
host_socket: &str,
) -> Result<()> {
let sig = signature_filename.ok_or_else(|| anyhow!("signature file is required"))?;

// Spawn the SGX enclave.
let mut device = IsgxDevice::new()?
Expand All @@ -77,8 +74,10 @@ impl Loader for SgxsLoader {
let mut enclave_builder = EnclaveBuilder::new(filename.as_ref());
enclave_builder.signature(sig)?;
enclave_builder.usercall_extension(HostService::new(host_socket));
let enclave = enclave_builder.build(&mut device)?;
let enclave = enclave_builder
.build(&mut device)
.map_err(|err| anyhow!("{}", err))?;

enclave.run()
enclave.run().map_err(|err| anyhow!("{}", err))
}
}

0 comments on commit 9a79562

Please sign in to comment.