urts_com.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #ifndef _URTS_COM_H_
  32. #define _URTS_COM_H_
  33. #include "arch.h"
  34. #include "sgx_error.h"
  35. #include "se_error_internal.h"
  36. #include "se_trace.h"
  37. #include "file.h"
  38. #include "sgx_eid.h"
  39. #include "se_map.h"
  40. #include "launch_checker.h"
  41. #include "debugger_support.h"
  42. #include "loader.h"
  43. #include "binparser.h"
  44. #include "cpuid.h"
  45. #include "se_macro.h"
  46. #include "prd_css_util.h"
  47. #include "se_detect.h"
  48. #include "rts.h"
  49. #include "enclave_creator_hw.h"
  50. #include "edmm_utility.h"
  51. #include <sys/mman.h>
  52. #ifndef PARSER
  53. #include "elfparser.h"
  54. #define PARSER ElfParser
  55. #endif
  56. #include "xsave.h"
  57. #include "ittnotify.h"
  58. #include "ittnotify_config.h"
  59. #include "ittnotify_types.h"
  60. extern "C" int __itt_init_ittlib(const char*, __itt_group_id);
  61. extern "C" __itt_global* __itt_get_ittapi_global();
  62. #define HSW_C0 0x306c3
  63. #define GPR_A0 0x406e0
  64. #define GPR_B0 0x406e1
  65. #define GPR_P0 0x506e0
  66. #ifndef SE_SIM
  67. static int validate_platform()
  68. {
  69. int cpu_info[4] = {0, 0, 0, 0};
  70. __cpuid(cpu_info, 1);
  71. // The compatibility between SDK and PSW is checked by the metadata version.
  72. // Below check the compatibility between the platform and uRTS only.
  73. // It is HSW users' responsibility to make the uRTS version to consistent with the HSW patch.
  74. if(cpu_info[0] == HSW_C0)
  75. {
  76. return SGX_SUCCESS;
  77. }
  78. // GPR region
  79. else if(cpu_info[0] == GPR_A0 || cpu_info[0] == GPR_B0 || cpu_info[0] == GPR_P0)
  80. {
  81. SE_TRACE(SE_TRACE_ERROR, "ERROR: The enclave cannot be launched on current platform.\n");
  82. return SGX_ERROR_INVALID_VERSION;
  83. }
  84. return SGX_SUCCESS;
  85. }
  86. #endif
  87. static sgx_status_t get_metadata(BinParser *parser, const int debug, metadata_t **metadata, sgx_misc_attribute_t *sgx_misc_attr)
  88. {
  89. assert(parser != NULL && metadata != NULL && sgx_misc_attr != NULL);
  90. uint64_t meta_rva = parser->get_metadata_offset();
  91. const uint8_t *base_addr = parser->get_start_addr();
  92. uint64_t urts_version = META_DATA_MAKE_VERSION(MAJOR_VERSION,MINOR_VERSION);
  93. metadata_t *target_metadata = NULL;
  94. #ifndef SE_SIM
  95. EnclaveCreatorHW *enclave_creator = static_cast<EnclaveCreatorHW *>(get_enclave_creator());
  96. if (!is_cpu_support_edmm() || !(enclave_creator->is_driver_compatible()))
  97. {
  98. // cannot support EDMM, adjust the possibly highest metadata version supported
  99. urts_version = META_DATA_MAKE_VERSION(SGX_1_9_MAJOR_VERSION,SGX_1_9_MINOR_VERSION);
  100. }
  101. #else
  102. //for simulation, use the metadata of 1.9
  103. urts_version = META_DATA_MAKE_VERSION(SGX_1_9_MAJOR_VERSION,SGX_1_9_MINOR_VERSION);
  104. #endif
  105. //scan multiple metadata list in sgx_metadata section
  106. meta_rva = parser->get_metadata_offset();
  107. do {
  108. *metadata = GET_PTR(metadata_t, base_addr, meta_rva);
  109. if(metadata == NULL)
  110. {
  111. return SGX_ERROR_INVALID_METADATA;
  112. }
  113. if((*metadata)->magic_num != METADATA_MAGIC)
  114. {
  115. break;
  116. }
  117. if(0 == (*metadata)->size)
  118. {
  119. SE_TRACE(SE_TRACE_ERROR, "ERROR: metadata's size can't be zero.\n");
  120. return SGX_ERROR_INVALID_METADATA;
  121. }
  122. //check metadata version
  123. if(MAJOR_VERSION_OF_METADATA(urts_version) >=
  124. MAJOR_VERSION_OF_METADATA((*metadata)->version))
  125. {
  126. if(target_metadata == NULL ||
  127. target_metadata->version < (*metadata)->version)
  128. {
  129. target_metadata = *metadata;
  130. }
  131. }
  132. meta_rva += (*metadata)->size; /*goto next metadata offset*/
  133. }while(1);
  134. if(target_metadata == NULL )
  135. {
  136. return SGX_ERROR_INVALID_METADATA;
  137. }
  138. else
  139. {
  140. *metadata = target_metadata;
  141. }
  142. return (sgx_status_t)get_enclave_creator()->get_misc_attr(sgx_misc_attr, *metadata, NULL, debug);
  143. }
  144. #define MAX_LEN 256
  145. static bool is_SGX_DBG_OPTIN_variable_set()
  146. {
  147. const char sgx_dbg_optin[] = "SGX_DBG_OPTIN";
  148. const char sgx_dbg_optin_expect_val[] = "1";
  149. char *sgx_dbg_optin_val = getenv(sgx_dbg_optin);
  150. if(sgx_dbg_optin_val == NULL)
  151. {
  152. return false;
  153. }
  154. size_t expect_len = strnlen_s(sgx_dbg_optin_expect_val, MAX_LEN);
  155. size_t len = strnlen_s(sgx_dbg_optin_val, MAX_LEN);
  156. if(len != expect_len || strncmp(sgx_dbg_optin_expect_val, sgx_dbg_optin_val, expect_len) != 0)
  157. {
  158. return false;
  159. }
  160. return true;
  161. }
  162. static int __create_enclave(BinParser &parser, uint8_t* base_addr, const metadata_t *metadata, se_file_t& file, const bool debug, SGXLaunchToken *lc, le_prd_css_file_t *prd_css_file, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr, uint8_t *sealed_key)
  163. {
  164. // The "parser" will be registered into "loader" and "loader" will be registered into "enclave".
  165. // After enclave is created, "parser" and "loader" are not needed any more.
  166. debug_enclave_info_t *debug_info = NULL;
  167. int ret = SGX_SUCCESS;
  168. CLoader loader(base_addr, parser);
  169. ret = loader.load_enclave_ex(lc, debug, metadata, prd_css_file, misc_attr);
  170. if (ret != SGX_SUCCESS)
  171. {
  172. return ret;
  173. }
  174. CEnclave* enclave = new CEnclave(loader);
  175. uint32_t enclave_version = SDK_VERSION_1_5;
  176. uint64_t urts_version = META_DATA_MAKE_VERSION(MAJOR_VERSION,MINOR_VERSION);
  177. // metadata->version has already been validated during load_encalve_ex()
  178. if (MAJOR_VERSION_OF_METADATA(metadata->version) == MAJOR_VERSION_OF_METADATA(urts_version) &&
  179. MINOR_VERSION_OF_METADATA(metadata->version) >= MINOR_VERSION_OF_METADATA(urts_version))
  180. {
  181. enclave_version = SDK_VERSION_2_2;
  182. }
  183. else if (MAJOR_VERSION_OF_METADATA(metadata->version) == MAJOR_VERSION_OF_METADATA(urts_version) &&
  184. MINOR_VERSION_OF_METADATA(metadata->version) < MINOR_VERSION_OF_METADATA(urts_version))
  185. {
  186. enclave_version = SDK_VERSION_2_0;
  187. }
  188. // initialize the enclave object
  189. ret = enclave->initialize(file,
  190. loader.get_enclave_id(),
  191. const_cast<void*>(loader.get_start_addr()),
  192. metadata->enclave_size,
  193. metadata->tcs_policy,
  194. enclave_version,
  195. metadata->tcs_min_pool);
  196. if (ret != SGX_SUCCESS)
  197. {
  198. loader.destroy_enclave();
  199. delete enclave; // The `enclave' object owns the `loader' object.
  200. return ret;
  201. }
  202. if(sealed_key != NULL)
  203. {
  204. enclave->set_sealed_key(sealed_key);
  205. }
  206. // It is accurate to get debug flag from secs
  207. enclave->set_dbg_flag(!!(loader.get_secs().attributes.flags & SGX_FLAGS_DEBUG));
  208. debug_info = const_cast<debug_enclave_info_t *>(enclave->get_debug_info());
  209. enclave->set_extra_debug_info(const_cast<secs_t &>(loader.get_secs()));
  210. //add enclave to enclave pool before init_enclave because in simualtion
  211. //mode init_enclave will rely on CEnclavePool to get Enclave instance.
  212. if (FALSE == CEnclavePool::instance()->add_enclave(enclave))
  213. {
  214. loader.destroy_enclave();
  215. delete enclave;
  216. return SGX_ERROR_UNEXPECTED;
  217. }
  218. std::vector<std::pair<tcs_t *, bool>> tcs_list = loader.get_tcs_list();
  219. for (unsigned idx = 0; idx < tcs_list.size(); ++idx)
  220. {
  221. enclave->add_thread(tcs_list[idx].first, tcs_list[idx].second);
  222. SE_TRACE(SE_TRACE_DEBUG, "add tcs %p\n", tcs_list[idx].first);
  223. }
  224. if(debug)
  225. debug_info->enclave_type |= ET_DEBUG;
  226. if (!(get_enclave_creator()->use_se_hw()))
  227. debug_info->enclave_type |= ET_SIM;
  228. if(debug || !(get_enclave_creator()->use_se_hw()))
  229. {
  230. SE_TRACE(SE_TRACE_DEBUG, "Debug enclave. Checking if VTune is profiling or SGX_DBG_OPTIN is set\n");
  231. __itt_init_ittlib(NULL, __itt_group_none);
  232. bool isVTuneProfiling;
  233. if(__itt_get_ittapi_global()->api_initialized && __itt_get_ittapi_global()->lib)
  234. isVTuneProfiling = true;
  235. else
  236. isVTuneProfiling = false;
  237. bool is_SGX_DBG_OPTIN_set = false;
  238. is_SGX_DBG_OPTIN_set = is_SGX_DBG_OPTIN_variable_set();
  239. if (isVTuneProfiling || is_SGX_DBG_OPTIN_set)
  240. {
  241. SE_TRACE(SE_TRACE_DEBUG, "VTune is profiling or SGX_DBG_OPTIN is set\n");
  242. bool thread_updated;
  243. thread_updated = enclave->update_debug_flag(1);
  244. if(thread_updated == false)
  245. {
  246. SE_TRACE(SE_TRACE_DEBUG, "Failed to update debug OPTIN bit\n");
  247. }
  248. else
  249. {
  250. SE_TRACE(SE_TRACE_DEBUG, "Updated debug OPTIN bit\n");
  251. }
  252. if (isVTuneProfiling)
  253. {
  254. uint64_t enclave_start_addr;
  255. uint64_t enclave_end_addr;
  256. const char* enclave_path;
  257. enclave_start_addr = (uint64_t) loader.get_start_addr();
  258. enclave_end_addr = enclave_start_addr + (uint64_t) metadata->enclave_size -1;
  259. SE_TRACE(SE_TRACE_DEBUG, "Invoking VTune's module mapping API __itt_module_load \n");
  260. SE_TRACE(SE_TRACE_DEBUG, "Enclave_start_addr==0x%llx\n", enclave_start_addr);
  261. SE_TRACE(SE_TRACE_DEBUG, "Enclave_end_addr==0x%llx\n", enclave_end_addr);
  262. enclave_path = (const char*)file.name;
  263. SE_TRACE(SE_TRACE_DEBUG, "Enclave_path==%s\n", enclave_path);
  264. __itt_module_load((void*)enclave_start_addr, (void*) enclave_end_addr, enclave_path);
  265. }
  266. }
  267. else
  268. {
  269. SE_TRACE(SE_TRACE_DEBUG, "VTune is not profiling and SGX_DBG_OPTIN is not set. TCS Debug OPTIN bit not set and API to do module mapping not invoked\n");
  270. }
  271. }
  272. //send debug event to debugger when enclave is debug mode or release mode
  273. //set struct version
  274. debug_info->struct_version = enclave->get_debug_info()->struct_version;
  275. //generate load debug event after EINIT
  276. generate_enclave_debug_event(URTS_EXCEPTION_POSTINITENCLAVE, debug_info);
  277. if (get_enclave_creator()->is_EDMM_supported(loader.get_enclave_id()))
  278. {
  279. layout_t *layout_start = GET_PTR(layout_t, metadata, metadata->dirs[DIR_LAYOUT].offset);
  280. layout_t *layout_end = GET_PTR(layout_t, metadata, metadata->dirs[DIR_LAYOUT].offset + metadata->dirs[DIR_LAYOUT].size);
  281. if (SGX_SUCCESS != (ret = loader.post_init_action(layout_start, layout_end, 0)))
  282. {
  283. SE_TRACE(SE_TRACE_ERROR, "trim range error.\n");
  284. sgx_status_t status = SGX_SUCCESS;
  285. generate_enclave_debug_event(URTS_EXCEPTION_PREREMOVEENCLAVE, debug_info);
  286. CEnclavePool::instance()->remove_enclave(loader.get_enclave_id(), status);
  287. goto fail;
  288. }
  289. }
  290. //call trts to do some intialization
  291. if(SGX_SUCCESS != (ret = get_enclave_creator()->initialize(loader.get_enclave_id())))
  292. {
  293. sgx_status_t status = SGX_SUCCESS;
  294. generate_enclave_debug_event(URTS_EXCEPTION_PREREMOVEENCLAVE, debug_info);
  295. CEnclavePool::instance()->remove_enclave(loader.get_enclave_id(), status);
  296. goto fail;
  297. }
  298. if (get_enclave_creator()->is_EDMM_supported(loader.get_enclave_id()))
  299. {
  300. layout_t *layout_start = GET_PTR(layout_t, metadata, metadata->dirs[DIR_LAYOUT].offset);
  301. layout_t *layout_end = GET_PTR(layout_t, metadata, metadata->dirs[DIR_LAYOUT].offset + metadata->dirs[DIR_LAYOUT].size);
  302. if (SGX_SUCCESS != (ret = loader.post_init_action_commit(layout_start, layout_end, 0)))
  303. {
  304. SE_TRACE(SE_TRACE_ERROR, "trim page commit error.\n");
  305. sgx_status_t status = SGX_SUCCESS;
  306. generate_enclave_debug_event(URTS_EXCEPTION_PREREMOVEENCLAVE, debug_info);
  307. CEnclavePool::instance()->remove_enclave(loader.get_enclave_id(), status);
  308. goto fail;
  309. }
  310. }
  311. //fill tcs mini pool
  312. if (get_enclave_creator()->is_EDMM_supported(loader.get_enclave_id()))
  313. {
  314. ret = enclave->fill_tcs_mini_pool_fn();
  315. if (ret != SGX_SUCCESS)
  316. {
  317. SE_TRACE(SE_TRACE_ERROR, "fill_tcs_mini_pool error.\n");
  318. sgx_status_t status = SGX_SUCCESS;
  319. generate_enclave_debug_event(URTS_EXCEPTION_PREREMOVEENCLAVE, debug_info);
  320. CEnclavePool::instance()->remove_enclave(loader.get_enclave_id(), status);
  321. goto fail;
  322. }
  323. }
  324. if(SGX_SUCCESS != (ret = loader.set_memory_protection(true)))
  325. {
  326. sgx_status_t status = SGX_SUCCESS;
  327. generate_enclave_debug_event(URTS_EXCEPTION_PREREMOVEENCLAVE, debug_info);
  328. CEnclavePool::instance()->remove_enclave(loader.get_enclave_id(), status);
  329. goto fail;
  330. }
  331. *enclave_id = loader.get_enclave_id();
  332. return SGX_SUCCESS;
  333. fail:
  334. loader.destroy_enclave();
  335. delete enclave;
  336. return ret;
  337. }
  338. sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t& file, le_prd_css_file_t *prd_css_file, sgx_launch_token_t *launch, int *launch_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr, uint8_t* sealed_key = NULL)
  339. {
  340. unsigned int ret = SGX_SUCCESS;
  341. sgx_status_t lt_result = SGX_SUCCESS;
  342. uint32_t file_size = 0;
  343. map_handle_t* mh = NULL;
  344. sgx_misc_attribute_t sgx_misc_attr;
  345. metadata_t *metadata = NULL;
  346. SGXLaunchToken *lc = NULL;
  347. memset(&sgx_misc_attr, 0, sizeof(sgx_misc_attribute_t));
  348. if(NULL == launch || NULL == launch_updated || NULL == enclave_id)
  349. return SGX_ERROR_INVALID_PARAMETER;
  350. #ifndef SE_SIM
  351. ret = validate_platform();
  352. if(ret != SGX_SUCCESS)
  353. return (sgx_status_t)ret;
  354. #endif
  355. mh = map_file(pfile, &file_size);
  356. if (!mh)
  357. return SGX_ERROR_OUT_OF_MEMORY;
  358. PARSER parser(const_cast<uint8_t *>(mh->base_addr), (uint64_t)(file_size));
  359. if(SGX_SUCCESS != (ret = parser.run_parser()))
  360. {
  361. goto clean_return;
  362. }
  363. //Make sure HW uRTS won't load simulation enclave and vice verse.
  364. if(get_enclave_creator()->use_se_hw() != (!parser.get_symbol_rva("g_global_data_sim")))
  365. {
  366. SE_TRACE_WARNING("HW and Simulation mode incompatibility detected. The enclave is linked with the incorrect tRTS library.\n");
  367. ret = SGX_ERROR_MODE_INCOMPATIBLE;
  368. goto clean_return;
  369. }
  370. if(NULL != sealed_key && true != parser.is_enclave_encrypted())
  371. {
  372. ret = SGX_ERROR_PCL_NOT_ENCRYPTED;
  373. goto clean_return;
  374. }
  375. if(NULL == sealed_key && false != parser.is_enclave_encrypted())
  376. {
  377. ret = SGX_ERROR_PCL_ENCRYPTED;
  378. goto clean_return;
  379. }
  380. if(SGX_SUCCESS != (ret = get_metadata(&parser, debug, &metadata, &sgx_misc_attr)))
  381. {
  382. goto clean_return;
  383. }
  384. *launch_updated = FALSE;
  385. lc = new SGXLaunchToken(&metadata->enclave_css, &sgx_misc_attr.secs_attr, launch);
  386. lt_result = lc->update_launch_token(false);
  387. if(SGX_SUCCESS != lt_result)
  388. {
  389. ret = lt_result;
  390. goto clean_return;
  391. }
  392. #ifndef SE_SIM
  393. // Only LE allows the prd_css_file
  394. if(is_le(lc, &metadata->enclave_css) == false && prd_css_file != NULL)
  395. {
  396. ret = SGX_ERROR_INVALID_PARAMETER;
  397. goto clean_return;
  398. }
  399. #endif
  400. // init xave global variables for xsave/xrstor
  401. init_xsave_info();
  402. //Need to set the whole misc_attr instead of just secs_attr.
  403. do {
  404. ret = __create_enclave(parser, mh->base_addr, metadata, file, debug, lc, prd_css_file, enclave_id,
  405. misc_attr, sealed_key);
  406. //SGX_ERROR_ENCLAVE_LOST caused by initializing enclave while power transition occurs
  407. } while(SGX_ERROR_ENCLAVE_LOST == ret);
  408. if(SE_ERROR_INVALID_LAUNCH_TOKEN == ret)
  409. ret = SGX_ERROR_INVALID_LAUNCH_TOKEN;
  410. // The launch token is updated, so the SE_INVALID_MEASUREMENT is only caused by signature.
  411. if(SE_ERROR_INVALID_MEASUREMENT == ret)
  412. ret = SGX_ERROR_INVALID_SIGNATURE;
  413. // The launch token is updated, so the SE_ERROR_INVALID_ISVSVNLE means user needs to update the LE image
  414. if (SE_ERROR_INVALID_ISVSVNLE == ret)
  415. ret = SGX_ERROR_UPDATE_NEEDED;
  416. if(SGX_SUCCESS != ret)
  417. goto clean_return;
  418. else if(lc->is_launch_updated())
  419. {
  420. *launch_updated = TRUE;
  421. ret = lc->get_launch_token(launch);
  422. }
  423. clean_return:
  424. if(mh != NULL)
  425. unmap_file(mh);
  426. if(lc != NULL)
  427. delete lc;
  428. return (sgx_status_t)ret;
  429. }
  430. extern "C" sgx_status_t sgx_destroy_enclave(const sgx_enclave_id_t enclave_id)
  431. {
  432. {
  433. CEnclave* enclave = CEnclavePool::instance()->ref_enclave(enclave_id);
  434. if(enclave)
  435. {
  436. debug_enclave_info_t *debug_info = const_cast<debug_enclave_info_t *>(enclave->get_debug_info());
  437. generate_enclave_debug_event(URTS_EXCEPTION_PREREMOVEENCLAVE, debug_info);
  438. enclave->ecall(ECMD_UNINIT_ENCLAVE, NULL, NULL);
  439. CEnclavePool::instance()->unref_enclave(enclave);
  440. }
  441. }
  442. sgx_status_t status = SGX_SUCCESS;
  443. CEnclave* enclave = CEnclavePool::instance()->remove_enclave(enclave_id, status);
  444. if (enclave)
  445. {
  446. delete enclave;
  447. }
  448. return status;
  449. }
  450. #endif