Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime-loader: Remove unused ELF loader, bump clap to 4.0.10 #4969

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
2 changes: 1 addition & 1 deletion tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ anyhow = "1.0"
thiserror = "1.0"
serde = { version = "1.0.137", features = ["derive"] }
toml = "0.5.9"
clap = "3.2.10"
clap = "4.0.10"
ansi_term = "0.12.1"

[[bin]]
Expand Down
3 changes: 2 additions & 1 deletion tools/bin/cargo-elf2sgxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn real_main() -> Result<()> {
clap::Command::new("elf2sgxs").arg(
Arg::new("release")
.long("release")
.action(clap::ArgAction::SetTrue)
.help("Use release build artifacts"),
),
)
Expand All @@ -73,7 +74,7 @@ fn real_main() -> Result<()> {
// Build target directory.
let mut target_path = package_root.target_path();
target_path.push(TARGET_TRIPLE);
if matches.is_present("release") {
if matches.get_flag("release") {
target_path.push("release");
} else {
target_path.push("debug");
Expand Down