-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
699621b
commit a835598
Showing
3 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#[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("/home/akash/Workspace/akash-rust-sgx/target/debug/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() { | ||
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 sgxs_append_status = Command::new("sgxs-append") | ||
.arg("-i") | ||
.arg(&bin_with_ext) | ||
.status() | ||
.expect("Unable to execute sgxs-append"); | ||
|
||
if !sgxs_append_status.success() { | ||
process::exit(match sgxs_append_status.code() { | ||
Some(code) => code, | ||
None => 1 | ||
}); | ||
} | ||
|
||
let ftxsgx_runner_status = Command::new("ftxsgx-runner") | ||
.arg(&bin_with_ext) | ||
.status() | ||
.expect("Unable to execute ftxsgx-runner"); | ||
|
||
if !ftxsgx_runner_status.success() { | ||
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); | ||
} | ||
} | ||
} |