Skip to content

Commit f29f4e7

Browse files
committed
Make t_global_init_ecall works only once.
Thanks to Sanchuan Chen <chen.4825@osu.edu>, Yinqian Zhang <yinqian@cse.ohio-state.edu> and Zhiqiang Lin <zlin@cse.ohio-state.edu> for reporting this issue
1 parent 1d8a9f8 commit f29f4e7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

sgx_tstd/src/rt.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,24 @@ use core::str;
3636
pub use crate::panicking::{begin_panic, begin_panic_fmt, update_panic_count};
3737
pub use crate::sys_common::at_exit;
3838
use crate::sys_common::cleanup;
39+
use crate::sync::Once;
40+
41+
static INIT: Once = Once::new();
3942

4043
#[no_mangle]
4144
pub extern "C" fn t_global_exit_ecall() {
4245
}
4346

4447
#[no_mangle]
4548
pub extern "C" fn t_global_init_ecall(id: u64, path: * const u8, len: usize) {
46-
47-
enclave::set_enclave_id(id as sgx_enclave_id_t);
48-
let s = unsafe {
49-
let str_slice = slice::from_raw_parts(path, len);
50-
str::from_utf8_unchecked(str_slice)
51-
};
52-
enclave::set_enclave_path(s);
49+
INIT.call_once(|| {
50+
enclave::set_enclave_id(id as sgx_enclave_id_t);
51+
let s = unsafe {
52+
let str_slice = slice::from_raw_parts(path, len);
53+
str::from_utf8_unchecked(str_slice)
54+
};
55+
enclave::set_enclave_path(s);
56+
});
5357
}
5458

5559
global_dtors_object! {

0 commit comments

Comments
 (0)