From 3d80233b42936430563604c52f543efd8ebd4585 Mon Sep 17 00:00:00 2001 From: Dionna Glaze Date: Fri, 23 Feb 2018 09:59:44 -0800 Subject: [PATCH] Adds an API function to check if the enclave has crashed. Signed-off-by: Dionna Glaze --- common/inc/sgx_trts.h | 7 +++++++ sdk/trts/trts.cpp | 6 +++++- sdk/trts/trts_nsp.cpp | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common/inc/sgx_trts.h b/common/inc/sgx_trts.h index 95a4d5e8..774efded 100644 --- a/common/inc/sgx_trts.h +++ b/common/inc/sgx_trts.h @@ -74,6 +74,13 @@ int SGXAPI sgx_is_outside_enclave(const void *addr, size_t size); */ sgx_status_t SGXAPI sgx_read_rand(unsigned char *rand, size_t length_in_bytes); +/* sgx_is_enclave_crashed() + * Return Value: + * 1 - The global enclave state is crashed. + * 0 - The global enclave state is not crashed. + */ +int SGXAPI sgx_is_enclave_crashed(void); + #ifdef __cplusplus } #endif diff --git a/sdk/trts/trts.cpp b/sdk/trts/trts.cpp index bc01d700..d49717c7 100644 --- a/sdk/trts/trts.cpp +++ b/sdk/trts/trts.cpp @@ -291,6 +291,11 @@ sgx_status_t sgx_read_rand(unsigned char *rand, size_t length_in_bytes) return SGX_SUCCESS; } +int sgx_is_enclave_crashed() +{ + return get_enclave_state() == ENCLAVE_CRASHED; +} + extern uintptr_t __stack_chk_guard; int check_static_stack_canary(void *tcs) { @@ -301,4 +306,3 @@ int check_static_stack_canary(void *tcs) } return 0; } - diff --git a/sdk/trts/trts_nsp.cpp b/sdk/trts/trts_nsp.cpp index 12c62534..b119c96d 100644 --- a/sdk/trts/trts_nsp.cpp +++ b/sdk/trts/trts_nsp.cpp @@ -73,7 +73,7 @@ static void init_stack_guard(void *tcs) extern "C" int enter_enclave(int index, void *ms, void *tcs, int cssa) { - if(get_enclave_state() == ENCLAVE_CRASHED) + if(sgx_is_enclave_crashed()) { return SGX_ERROR_ENCLAVE_CRASHED; }