sgx_tls.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. struct enclave_tls {
  6. uint64_t enclave_size;
  7. uint64_t tcs_offset;
  8. uint64_t initial_stack_offset;
  9. void * aep;
  10. void * ssa;
  11. sgx_arch_gpr_t * gpr;
  12. void * exit_target;
  13. void * fsbase;
  14. void * stack;
  15. void * ustack_top;
  16. void * ustack;
  17. struct pal_handle_thread * thread;
  18. uint64_t ocall_prepared;
  19. uint64_t ecall_called;
  20. uint64_t ready_for_exceptions;
  21. uint64_t manifest_size;
  22. };
  23. #ifndef DEBUG
  24. extern uint64_t dummy_debug_variable;
  25. #endif
  26. # ifdef IN_ENCLAVE
  27. # define GET_ENCLAVE_TLS(member) \
  28. ({ \
  29. struct enclave_tls * tmp; \
  30. uint64_t val; \
  31. __asm__ ("movq %%gs:%c1, %q0": "=r" (val) \
  32. : "i" (offsetof(struct enclave_tls, member))); \
  33. (__typeof(tmp->member)) val; \
  34. })
  35. # define SET_ENCLAVE_TLS(member, value) \
  36. do { \
  37. __asm__ ("movq %q0, %%gs:%c1":: "r" (value), \
  38. "i" (offsetof(struct enclave_tls, member))); \
  39. } while (0)
  40. # endif
  41. #endif /* __SGX_TLS_H__ */