Skip to content

Commit

Permalink
runner script
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-fortanix committed Jan 8, 2019
1 parent 699621b commit 03cd031
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions fortanix-sgx-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ sgx-isa = { version = "0.2.0-rc1", path = "../sgx-isa" }
xmas-elf = "0.6.0" # Apache-2.0/MIT
clap = "2.2.5" # MIT
failure = "0.1.1" # MIT/Apache-2.0
serde_derive = "1.0.84"
serde = "1.0.84"
toml = "0.4.10"
123 changes: 123 additions & 0 deletions fortanix-sgx-tools/src/bin/ftxsgx-runner-cargo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#[macro_use]
extern crate serde_derive;

use std::env;
use std::ffi::OsString;
use std::fs::File;
use std::io::Read;
use std::process::{self, Command};

const HEAP_SIZE: u32 = 0x20000;
const SSAFRAMESIZE: u32 = 1;
const STACK_SIZE: u32 = 0x20000;
const THREADS: u32 = 1;
const DEBUG: bool = true;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
struct Target {
heap_size: Option<u32>,
ssaframesize: Option<u32>,
stack_size: Option<u32>,
threads: Option<u32>,
debug: Option<bool>,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
struct Metadata {
fortanix_sgx: Target
}

#[derive(Deserialize, Debug)]
struct Package {
metadata: Metadata
}

#[derive(Deserialize, Debug)]
struct Config {
package: Package
}

fn main() {
let key = "CARGO_MANIFEST_DIR";
match env::var_os(key) {
Some(mut filepath) => {
filepath.push(OsString::from("/Cargo.toml"));
let mut file = File::open(filepath).expect("Unable to open the manifest");
let mut content = String::new();
file.read_to_string(&mut content).expect("Unable to read the manifest");
let config: Config = toml::from_str(&content).expect("Unable to parse the manifest");
let heap_size = config.package.metadata.fortanix_sgx.heap_size.unwrap_or(HEAP_SIZE).to_string();
let ssaframesize = config.package.metadata.fortanix_sgx.ssaframesize.unwrap_or(SSAFRAMESIZE).to_string();
let stack_size = config.package.metadata.fortanix_sgx.stack_size.unwrap_or(STACK_SIZE).to_string();
let threads = config.package.metadata.fortanix_sgx.threads.unwrap_or(THREADS).to_string();
let debug = config.package.metadata.fortanix_sgx.debug.unwrap_or(DEBUG);

let args: Vec<String> = env::args().collect();

let mut ftxsgx_elf2sgxs_command = Command::new("ftxsgx-elf2sgxs");
ftxsgx_elf2sgxs_command.arg(&args[1])
.arg("--heap-size")
.arg(heap_size)
.arg("--ssaframesize")
.arg(ssaframesize)
.arg("--stack-size")
.arg(stack_size)
.arg("--threads")
.arg(threads);
if debug {
ftxsgx_elf2sgxs_command.arg("--debug");
}
let mut ftxsgx_elf2sgxs_status = ftxsgx_elf2sgxs_command.status()
.expect("Unable to execute ftxsgx-elf2sgxs");

if !ftxsgx_elf2sgxs_status.success() {
println!("{:?}", ftxsgx_elf2sgxs_command);
process::exit(match ftxsgx_elf2sgxs_status.code() {
Some(code) => code,
None => 1
});
}

let mut bin_with_ext = String::new();
bin_with_ext.push_str(&args[1]);
bin_with_ext.push_str(".sgxs");

let mut sgxs_append_command = Command::new("sgxs-append");
sgxs_append_command.arg("-i")
.arg(&bin_with_ext);

let sgxs_append_status = sgxs_append_command.status()
.expect("Unable to execute sgxs-append");

if !sgxs_append_status.success() {
println!("{:?}", sgxs_append_command);
process::exit(match sgxs_append_status.code() {
Some(code) => code,
None => 1
});
}

let mut ftxsgx_runner_command = Command::new("ftxsgx-runner");
ftxsgx_runner_command.arg(&bin_with_ext);

let ftxsgx_runner_status = ftxsgx_runner_command.status()
.expect("Unable to execute ftxsgx-runner");

if !ftxsgx_runner_status.success() {
println!("{:?}", ftxsgx_runner_command);
process::exit(match ftxsgx_runner_status.code() {
Some(code) => code,
None => 1
});
}

process::exit(0);
}
None => {
println!("{} is not defined in the environment.", key);
process::exit(1);
}
}
}

0 comments on commit 03cd031

Please sign in to comment.