Skip to content

Commit 82cd9d4

Browse files
authored
Fix simulation mode failure with tcmalloc. (#683)
Signed-off-by: Zhang Lili <lili.z.zhang@intel.com>
1 parent 26c4589 commit 82cd9d4

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

sdk/selib/sgx_create_report.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
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.
4950
SGX_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
}

sdk/simulation/tinst/rts_sim.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

sdk/trts/trts_xsave.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int g_xsave_enabled __attribute__((section(".nipd"))) = 0; // flag to in
5858
#ifdef SE_SIM
5959
uint32_t g_xsave_mask_high __attribute__((section(".nipd"))) = 0xFFFFFFFF;
6060
uint32_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;
7172
SE_OPTIMIZE_OFF
7273
uint64_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

0 commit comments

Comments
 (0)