Add support for user specified instance dir name
The default instance dir of Occlum is ".occlum". User now can specify the name by declaring environment variable "OCCLUM_INSTANCE_DIR"
This commit is contained in:
parent
03bb09abdf
commit
6a17e6292c
@ -15,7 +15,7 @@ enclave {
|
|||||||
*
|
*
|
||||||
* @retval On success, return 0; otherwise, return -1.
|
* @retval On success, return 0; otherwise, return -1.
|
||||||
*/
|
*/
|
||||||
public int occlum_ecall_init([in, string] const char* log_level);
|
public int occlum_ecall_init([in, string] const char* log_level, [in, string] const char* instance_dir);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new LibOS process to do the task specified by the given
|
* Create a new LibOS process to do the task specified by the given
|
||||||
|
@ -33,9 +33,8 @@ lazy_static! {
|
|||||||
.cause_err(|e| errno!(EINVAL, "invalid config JSON"))?;
|
.cause_err(|e| errno!(EINVAL, "invalid config JSON"))?;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
let config_path = unsafe { format!("{}{}", INSTANCE_DIR, "/build/Occlum.json.protected") };
|
||||||
let config_path = "./.occlum/build/Occlum.json.protected";
|
match load_config(&config_path) {
|
||||||
match load_config(config_path) {
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("failed to load config: {}", e.backtrace());
|
error!("failed to load config: {}", e.backtrace());
|
||||||
panic!();
|
panic!();
|
||||||
|
@ -11,7 +11,8 @@ use util::mem_util::from_untrusted::*;
|
|||||||
use util::sgx::allow_debug as sgx_allow_debug;
|
use util::sgx::allow_debug as sgx_allow_debug;
|
||||||
use sgx_tse::*;
|
use sgx_tse::*;
|
||||||
|
|
||||||
const ENCLAVE_PATH: &'static str = ".occlum/build/lib/libocclum-libos.signed.so";
|
pub static mut INSTANCE_DIR: String = String::new();
|
||||||
|
static mut ENCLAVE_PATH: String = String::new();
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref INIT_ONCE: Once = Once::new();
|
static ref INIT_ONCE: Once = Once::new();
|
||||||
@ -19,11 +20,13 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn occlum_ecall_init(log_level: *const c_char) -> i32 {
|
pub extern "C" fn occlum_ecall_init(log_level: *const c_char, instance_dir: *const c_char) -> i32 {
|
||||||
if HAS_INIT.load(Ordering::SeqCst) == true {
|
if HAS_INIT.load(Ordering::SeqCst) == true {
|
||||||
return EXIT_STATUS_INTERNAL_ERROR;
|
return EXIT_STATUS_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(!instance_dir.is_null());
|
||||||
|
|
||||||
let log_level = {
|
let log_level = {
|
||||||
let input_log_level = match parse_log_level(log_level) {
|
let input_log_level = match parse_log_level(log_level) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -52,6 +55,12 @@ pub extern "C" fn occlum_ecall_init(log_level: *const c_char) -> i32 {
|
|||||||
|
|
||||||
// Register exception handlers (support cpuid & rdtsc for now)
|
// Register exception handlers (support cpuid & rdtsc for now)
|
||||||
register_exception_handlers();
|
register_exception_handlers();
|
||||||
|
unsafe {
|
||||||
|
let dir_str: &str = CStr::from_ptr(instance_dir).to_str().unwrap();
|
||||||
|
INSTANCE_DIR.push_str(dir_str);
|
||||||
|
ENCLAVE_PATH.push_str(&INSTANCE_DIR);
|
||||||
|
ENCLAVE_PATH.push_str("/build/lib/libocclum-libos.signed.so");
|
||||||
|
}
|
||||||
|
|
||||||
HAS_INIT.store(true, Ordering::SeqCst);
|
HAS_INIT.store(true, Ordering::SeqCst);
|
||||||
});
|
});
|
||||||
@ -76,7 +85,8 @@ pub extern "C" fn occlum_ecall_new_process(
|
|||||||
return EXIT_STATUS_INTERNAL_ERROR;
|
return EXIT_STATUS_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let _ = backtrace::enable_backtrace(ENCLAVE_PATH, PrintFormat::Short);
|
|
||||||
|
let _ = unsafe { backtrace::enable_backtrace(&ENCLAVE_PATH, PrintFormat::Short) };
|
||||||
panic::catch_unwind(|| {
|
panic::catch_unwind(|| {
|
||||||
backtrace::__rust_begin_short_backtrace(|| {
|
backtrace::__rust_begin_short_backtrace(|| {
|
||||||
match do_new_process(&path, &args, &host_stdio_fds) {
|
match do_new_process(&path, &args, &host_stdio_fds) {
|
||||||
@ -97,7 +107,7 @@ pub extern "C" fn occlum_ecall_exec_thread(libos_pid: i32, host_tid: i32) -> i32
|
|||||||
return EXIT_STATUS_INTERNAL_ERROR;
|
return EXIT_STATUS_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = backtrace::enable_backtrace(ENCLAVE_PATH, PrintFormat::Short);
|
let _ = unsafe { backtrace::enable_backtrace(&ENCLAVE_PATH, PrintFormat::Short) };
|
||||||
panic::catch_unwind(|| {
|
panic::catch_unwind(|| {
|
||||||
backtrace::__rust_begin_short_backtrace(|| {
|
backtrace::__rust_begin_short_backtrace(|| {
|
||||||
match do_exec_thread(libos_pid as pid_t, host_tid as pid_t) {
|
match do_exec_thread(libos_pid as pid_t, host_tid as pid_t) {
|
||||||
|
@ -34,7 +34,7 @@ int occlum_pal_init(const struct occlum_pal_attr* attr) {
|
|||||||
// automatically done by Intel SGX SDK).
|
// automatically done by Intel SGX SDK).
|
||||||
eid = pal_get_enclave_id();
|
eid = pal_get_enclave_id();
|
||||||
int ret;
|
int ret;
|
||||||
sgx_status_t ecall_status = occlum_ecall_init(eid, &ret, attr->log_level);
|
sgx_status_t ecall_status = occlum_ecall_init(eid, &ret, attr->log_level, attr->instance_dir);
|
||||||
if (ecall_status != SGX_SUCCESS) {
|
if (ecall_status != SGX_SUCCESS) {
|
||||||
const char* sgx_err = pal_get_sgx_error_msg(ecall_status);
|
const char* sgx_err = pal_get_sgx_error_msg(ecall_status);
|
||||||
PAL_ERROR("Failed to do ECall: %s", sgx_err);
|
PAL_ERROR("Failed to do ECall: %s", sgx_err);
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
occlum_dir="$( cd "$( dirname "$this_dir/../../../" )" >/dev/null 2>&1 && pwd )"
|
occlum_dir="$( cd "$( dirname "$this_dir/../../../" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
|
||||||
|
if [ -z $OCCLUM_INSTANCE_DIR ];then
|
||||||
|
OCCLUM_INSTANCE_DIR=".occlum"
|
||||||
|
fi
|
||||||
working_dir=`pwd`
|
working_dir=`pwd`
|
||||||
context_dir="$working_dir/.occlum"
|
context_dir="$working_dir/$OCCLUM_INSTANCE_DIR"
|
||||||
|
|
||||||
SGX_SDK="${SGX_SDK:-/opt/intel/sgxsdk}"
|
SGX_SDK="${SGX_SDK:-/opt/intel/sgxsdk}"
|
||||||
SGX_GDB="$SGX_SDK/bin/sgx-gdb"
|
SGX_GDB="$SGX_SDK/bin/sgx-gdb"
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ -z $OCCLUM_INSTANCE_DIR ];then
|
||||||
|
OCCLUM_INSTANCE_DIR=".occlum"
|
||||||
|
fi
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
{
|
{
|
||||||
"vm": {
|
"vm": {
|
||||||
@ -13,7 +18,7 @@ cat <<EOF
|
|||||||
{
|
{
|
||||||
"target": "/",
|
"target": "/",
|
||||||
"type": "sefs",
|
"type": "sefs",
|
||||||
"source": ".occlum/build/mount/__ROOT",
|
"source": "$OCCLUM_INSTANCE_DIR/build/mount/__ROOT",
|
||||||
"options": {
|
"options": {
|
||||||
"integrity_only": true,
|
"integrity_only": true,
|
||||||
"MAC": "$OCCLUM_CONF_ROOT_FS_MAC"
|
"MAC": "$OCCLUM_CONF_ROOT_FS_MAC"
|
||||||
@ -22,7 +27,7 @@ cat <<EOF
|
|||||||
{
|
{
|
||||||
"target": "/root",
|
"target": "/root",
|
||||||
"type": "sefs",
|
"type": "sefs",
|
||||||
"source": ".occlum/run/mount/root"
|
"source": "$OCCLUM_INSTANCE_DIR/run/mount/root"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"target": "/host",
|
"target": "/host",
|
||||||
|
Loading…
Reference in New Issue
Block a user