sgx_tls.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #ifndef __SGX_TLS_H__
  4. #define __SGX_TLS_H__
  5. #ifndef __ASSEMBLER__
  6. struct enclave_tls {
  7. uint64_t enclave_size;
  8. uint64_t tcs_offset;
  9. uint64_t initial_stack_offset;
  10. void * aep;
  11. void * ssa;
  12. void * gpr;
  13. void * exit_target;
  14. void * fsbase;
  15. void * stack;
  16. void * ustack_top;
  17. void * ustack;
  18. void * thread;
  19. };
  20. #ifndef DEBUG
  21. extern uint64_t dummy_debug_variable;
  22. #endif
  23. # ifdef IN_ENCLAVE
  24. # define GET_ENCLAVE_TLS(member) \
  25. ({ \
  26. struct enclave_tls * tmp; \
  27. uint64_t val; \
  28. asm ("movq %%gs:%c1, %q0": "=r" (val) \
  29. : "i" (offsetof(struct enclave_tls, member))); \
  30. (typeof(tmp->member)) val; \
  31. })
  32. # define SET_ENCLAVE_TLS(member, value) \
  33. do { \
  34. asm ("movq %q0, %%gs:%c1":: "r" (value), \
  35. "i" (offsetof(struct enclave_tls, member))); \
  36. } while (0)
  37. # endif
  38. #else /* !__ASSEMBLER__ */
  39. /* update these constant according to struct enclave_tls */
  40. #define SGX_ENCLAVE_SIZE 0x00
  41. #define SGX_TCS_OFFSET 0x08
  42. #define SGX_INITIAL_STACK_OFFSET 0x10
  43. #define SGX_AEP 0x18
  44. #define SGX_SSA 0x20
  45. #define SGX_GPR 0x28
  46. #define SGX_EXIT_TARGET 0x30
  47. #define SGX_FSBASE 0x38
  48. #define SGX_STACK 0x40
  49. #define SGX_USTACK_TOP 0x48
  50. #define SGX_USTACK 0x50
  51. #define SGX_THREAD 0x58
  52. #endif
  53. #endif /* __SGX_TLS_H__ */