File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 4444#include " sgx_trts.h"
4545#include " trts_inst.h"
4646#include " se_cdefs.h"
47+ #include " sgx_spinlock.h"
4748
4849// add a version to tservice.
4950SGX_ACCESS_VERSION (tservice, 1 )
@@ -131,11 +132,18 @@ const sgx_report_t *sgx_self_report(void)
131132 .key_id = {0 },
132133 .mac = {0 }
133134 };
135+ static sgx_spinlock_t report_lock = SGX_SPINLOCK_INITIALIZER;
134136
135- // Below sgx_create_report() will be called only once during the enclave initialization,
136- // so there is no potential race conditional.
137137 if (0 == _report.body .attributes .flags )
138- sgx_create_report (nullptr , nullptr , &_report);
138+ {
139+ // sgx_create_report() only needs to be called once to get self report.
140+ sgx_spin_lock (&report_lock);
141+ if (0 == _report.body .attributes .flags )
142+ {
143+ sgx_create_report (nullptr , nullptr , &_report);
144+ }
145+ sgx_spin_unlock (&report_lock);
146+ }
139147
140148 return &_report;
141149}
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ typedef struct _global_data_sim_t
6767 uint64_t seed ; /* to initialize the PRNG */
6868} global_data_sim_t ;
6969
70+ extern global_data_sim_t g_global_data_sim ;
71+
7072#ifdef __cplusplus
7173}
7274#endif
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ int g_xsave_enabled __attribute__((section(".nipd"))) = 0; // flag to in
5858#ifdef SE_SIM
5959uint32_t g_xsave_mask_high __attribute__ ((section(" .nipd" ))) = 0xFFFFFFFF;
6060uint32_t g_xsave_mask_low __attribute__ ((section(" .nipd" ))) = 0xFFFFFFFF;
61+ #include " rts_sim.h"
6162#endif
6263
6364// EENTER will set xcr0 with secs.attr.xfrm,
@@ -71,10 +72,13 @@ uint32_t g_xsave_mask_low __attribute__((section(".nipd"))) = 0xFFFFFFFF;
7172SE_OPTIMIZE_OFF
7273uint64_t get_xfeature_state ()
7374{
75+ #ifndef SE_SIM
7476 auto *report = sgx_self_report ();
7577 g_xsave_enabled = (report->body .attributes .xfrm == SGX_XFRM_LEGACY) ? 0 : 1 ;
7678 uint64_t xfrm = report->body .attributes .xfrm ;
77- #ifdef SE_SIM
79+ #else
80+ uint64_t xfrm = g_global_data_sim.secs_ptr ->attributes .xfrm ;
81+ g_xsave_enabled = (xfrm == SGX_XFRM_LEGACY) ? 0 : 1 ;
7882 g_xsave_mask_high = (uint32_t )(xfrm >> 32 );
7983 g_xsave_mask_low = (uint32_t )(xfrm & 0xFFFFFFFF );
8084#endif
You can’t perform that action at this time.
0 commit comments