Skip to content

Commit

Permalink
Fix simulation mode failure with tcmalloc. (#683)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang Lili <lili.z.zhang@intel.com>
  • Loading branch information
lzha101 committed May 18, 2021
1 parent 26c4589 commit 82cd9d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions sdk/selib/sgx_create_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "sgx_trts.h"
#include "trts_inst.h"
#include "se_cdefs.h"
#include "sgx_spinlock.h"

// add a version to tservice.
SGX_ACCESS_VERSION(tservice, 1)
Expand Down Expand Up @@ -131,11 +132,18 @@ const sgx_report_t *sgx_self_report(void)
.key_id = {0},
.mac = {0}
};
static sgx_spinlock_t report_lock = SGX_SPINLOCK_INITIALIZER;

// Below sgx_create_report() will be called only once during the enclave initialization,
// so there is no potential race conditional.
if (0 == _report.body.attributes.flags)
sgx_create_report(nullptr, nullptr, &_report);
{
// sgx_create_report() only needs to be called once to get self report.
sgx_spin_lock(&report_lock);
if (0 == _report.body.attributes.flags)
{
sgx_create_report(nullptr, nullptr, &_report);
}
sgx_spin_unlock(&report_lock);
}

return &_report;
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/simulation/tinst/rts_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ typedef struct _global_data_sim_t
uint64_t seed; /* to initialize the PRNG */
} global_data_sim_t;

extern global_data_sim_t g_global_data_sim;

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 5 additions & 1 deletion sdk/trts/trts_xsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int g_xsave_enabled __attribute__((section(".nipd"))) = 0; // flag to in
#ifdef SE_SIM
uint32_t g_xsave_mask_high __attribute__((section(".nipd"))) = 0xFFFFFFFF;
uint32_t g_xsave_mask_low __attribute__((section(".nipd"))) = 0xFFFFFFFF;
#include "rts_sim.h"
#endif

// EENTER will set xcr0 with secs.attr.xfrm,
Expand All @@ -71,10 +72,13 @@ uint32_t g_xsave_mask_low __attribute__((section(".nipd"))) = 0xFFFFFFFF;
SE_OPTIMIZE_OFF
uint64_t get_xfeature_state()
{
#ifndef SE_SIM
auto *report = sgx_self_report();
g_xsave_enabled = (report->body.attributes.xfrm == SGX_XFRM_LEGACY) ? 0 : 1;
uint64_t xfrm = report->body.attributes.xfrm;
#ifdef SE_SIM
#else
uint64_t xfrm = g_global_data_sim.secs_ptr->attributes.xfrm;
g_xsave_enabled = (xfrm == SGX_XFRM_LEGACY) ? 0 : 1;
g_xsave_mask_high = (uint32_t)(xfrm >> 32);
g_xsave_mask_low = (uint32_t)(xfrm & 0xFFFFFFFF);
#endif
Expand Down

0 comments on commit 82cd9d4

Please sign in to comment.