sgx_tls.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. void * self;
  8. void * initial_stack;
  9. void * fsbase;
  10. unsigned long ssaframesize;
  11. void * ssa;
  12. void * gpr;
  13. void * exit_target;
  14. unsigned long * debug_register;
  15. void * urts_initial_stack;
  16. void * urts_stack;
  17. void * aep;
  18. void * last_stack;
  19. unsigned long last_ocall_result;
  20. void * thread;
  21. unsigned long external_event;
  22. };
  23. # ifdef IN_ENCLAVE
  24. # define ENCLAVE_TLS_SELF() \
  25. ({ struct enclave_tls *__self; \
  26. asm ("movq %%gs:%c1, %q0" : "=r" (__self) \
  27. : "i" (offsetof(struct enclave_tls, self))); \
  28. __self; })
  29. # define ENCLAVE_TLS(member) \
  30. (((struct enclave_tls *) ENCLAVE_TLS_SELF())->member)
  31. # define DEBUG_REG (*ENCLAVE_TLS(debug_register))
  32. # endif
  33. #else /* !__ASSEMBLER__ */
  34. # ifdef IN_ENCLAVE
  35. # define DEBUG_REG %gs:SGX_DEBUG_REGISTER
  36. # endif
  37. #endif
  38. /* update these constant according to struct enclave_tls */
  39. #define SGX_INITIAL_STACK 0x08
  40. #define SGX_FSBASE 0x10
  41. #define SGX_SSAFRAMESIZE 0x18
  42. #define SGX_SSA 0x20
  43. #define SGX_GPR 0x28
  44. #define SGX_EXIT_TARGET 0x30
  45. #define SGX_DEBUG_REGISTER 0x38
  46. #define SGX_URTS_INITIAL_STACK 0x40
  47. #define SGX_URTS_STACK 0x48
  48. #define SGX_AEP 0x50
  49. #define SGX_LAST_STACK 0x58
  50. #define SGX_LAST_OCALL_RESULT 0x60
  51. #define SGX_THREAD 0x78
  52. #define SGX_EXTERNAL_EVENT 0x70
  53. #endif /* __SGX_TLS_H__ */