shim_tcb.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef _SHIM_TCB_H_
  2. #define _SHIM_TCB_H_
  3. #include <atomic.h>
  4. #define SHIM_TCB_CANARY 0xdeadbeef
  5. struct shim_regs {
  6. unsigned long orig_rax;
  7. unsigned long rsp;
  8. unsigned long r15;
  9. unsigned long r14;
  10. unsigned long r13;
  11. unsigned long r12;
  12. unsigned long r11;
  13. unsigned long r10;
  14. unsigned long r9;
  15. unsigned long r8;
  16. unsigned long rcx;
  17. unsigned long rdx;
  18. unsigned long rsi;
  19. unsigned long rdi;
  20. unsigned long rbx;
  21. unsigned long rbp;
  22. unsigned long rflags;
  23. unsigned long rip;
  24. };
  25. struct shim_context {
  26. struct shim_regs * regs;
  27. unsigned long fs_base;
  28. struct shim_context * next;
  29. uint64_t enter_time;
  30. struct atomic_int preempt;
  31. };
  32. struct debug_buf;
  33. typedef struct shim_tcb shim_tcb_t;
  34. struct shim_tcb {
  35. uint64_t canary;
  36. shim_tcb_t * self;
  37. struct shim_thread * tp;
  38. struct shim_context context;
  39. unsigned int tid;
  40. int pal_errno;
  41. struct debug_buf * debug_buf;
  42. /* This record is for testing the memory of user inputs.
  43. * If a segfault occurs with the range [start, end],
  44. * the code addr is set to cont_addr to alert the caller. */
  45. struct {
  46. void * start, * end;
  47. void * cont_addr;
  48. bool has_fault;
  49. } test_range;
  50. };
  51. void init_tcb (shim_tcb_t * tcb);
  52. static inline shim_tcb_t * shim_get_tcb(void)
  53. {
  54. /* TODO: optimize to use single movq %gs:<offset> */
  55. PAL_TCB * tcb = pal_get_tcb();
  56. return (shim_tcb_t*)tcb->libos_tcb;
  57. }
  58. static inline bool shim_tcb_check_canary(void)
  59. {
  60. /* TODO: optimize to use single movq %gs:<offset> */
  61. shim_tcb_t * shim_tcb = shim_get_tcb();
  62. return shim_tcb->canary == SHIM_TCB_CANARY;
  63. }
  64. #endif /* _SHIM_H_ */