From 4f96790cf3ef13bb4e7d070e8c0de09f268ca32e Mon Sep 17 00:00:00 2001 From: "Hui, Chunyang" Date: Thu, 16 Jul 2020 09:27:28 +0000 Subject: [PATCH] Fallback to old way for exit process in simulation mode --- src/pal/src/pal_api.c | 11 ++++++++++- src/pal/src/pal_enclave.c | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pal/src/pal_api.c b/src/pal/src/pal_api.c index 3863c87b..faf992ad 100644 --- a/src/pal/src/pal_api.c +++ b/src/pal/src/pal_api.c @@ -29,10 +29,12 @@ int occlum_pal_init(const struct occlum_pal_attr *attr) { errno = EEXIST; return -1; } - +// FIXME +#ifndef SGX_MODE_SIM if (pal_register_sig_handlers() < 0) { return -1; } +#endif if (pal_init_enclave(attr->instance_dir) < 0) { return -1; @@ -53,10 +55,13 @@ int occlum_pal_init(const struct occlum_pal_attr *attr) { goto on_destroy_enclave; } +// FIXME +#ifndef SGX_MODE_SIM if (pal_interrupt_thread_start() < 0) { PAL_ERROR("Failed to start the interrupt thread: %s", errno2str(errno)); goto on_destroy_enclave; } +#endif return 0; on_destroy_enclave: @@ -168,10 +173,14 @@ int occlum_pal_destroy(void) { int ret = 0; +// FIXME +#ifndef SGX_MODE_SIM if (pal_interrupt_thread_stop() < 0) { ret = -1; PAL_WARN("Cannot stop the interrupt thread: %s", errno2str(errno)); } +#endif + if (pal_destroy_enclave() < 0) { ret = -1; PAL_WARN("Cannot destroy the enclave"); diff --git a/src/pal/src/pal_enclave.c b/src/pal/src/pal_enclave.c index b117c1a0..e8246937 100644 --- a/src/pal/src/pal_enclave.c +++ b/src/pal/src/pal_enclave.c @@ -130,8 +130,14 @@ int pal_init_enclave(const char *instance_dir) { } int pal_destroy_enclave(void) { +// FIXME: Due to lack of support for enclave interrupt in simulation mode, some programs +// come across the problem that it can't exit when running in simulation mode. We have to +// fallback to the old way to exit brutely in simulation mode. +#ifndef SGX_MODE_SIM sgx_destroy_enclave(global_eid); global_eid = SGX_INVALID_ENCLAVE_ID; +#endif + return 0; }