123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "arch.h"
- #include "xsave.h"
- #include "trts_inst.h"
- #include "util.h"
- #define SYNTHETIC_STATE_SIZE (512 + 64 + 256)
- se_static_assert(SYNTHETIC_STATE_SIZE <= SE_PAGE_SIZE);
- static SE_DECLSPEC_ALIGN(4096) const uint16_t
- SYNTHETIC_STATE[SYNTHETIC_STATE_SIZE/sizeof(uint16_t)] = {
- 0x037F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1F80, 0, 0xFFFF, 0
- };
- static int g_xsave_enabled;
- uint64_t get_xfeature_state()
- {
-
-
-
- sgx_target_info_t *target_info = (sgx_target_info_t *)SYNTHETIC_STATE;
- sgx_report_data_t *report_data = (sgx_report_data_t *)SYNTHETIC_STATE;
- uint8_t buffer[sizeof(sgx_report_t) + REPORT_ALIGN_SIZE -1] = {0};
- sgx_report_t *report = (sgx_report_t *)ROUND_TO((size_t)buffer, REPORT_ALIGN_SIZE);
- do_ereport(target_info, report_data, report);
- g_xsave_enabled = (report->body.attributes.xfrm == SGX_XFRM_LEGACY) ? 0 : 1;
- uint64_t xfrm = report->body.attributes.xfrm;
-
-
- return xfrm;
- }
- void save_and_clean_xfeature_regs(uint8_t *buffer)
- {
- do_fwait();
- if(buffer != 0)
- {
- uint8_t *buf = (uint8_t*)ROUND_TO((size_t)buffer, FXSAVE_ALIGN_SIZE);
- do_fxsave(buf);
- }
- if(g_xsave_enabled)
- {
- do_xrstor(SYNTHETIC_STATE);
- }
- else
- {
- do_fxrstor(SYNTHETIC_STATE);
- }
- }
- void restore_xfeature_regs(const uint8_t *buffer)
- {
- if(buffer != 0)
- {
- uint8_t *buf = (uint8_t*)ROUND_TO((size_t)buffer, FXSAVE_ALIGN_SIZE);
- do_fxrstor(buf);
- }
- }
|