shim_tls.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 _SHIM_TLS_H_
  4. #define _SHIM_TLS_H_
  5. #ifdef __ASSEMBLER__
  6. #define SHIM_TLS_CANARY $xdeadbeef
  7. #else /* !__ASSEMBLER__ */
  8. #define SHIM_TLS_CANARY 0xdeadbeef
  9. struct lock_record {
  10. enum { NO_LOCK, SEM_LOCK, READ_LOCK, WRITE_LOCK } type;
  11. void * lock;
  12. const char * filename;
  13. int lineno;
  14. };
  15. #define NUM_LOCK_RECORD 32
  16. #define NUM_LOCK_RECORD_MASK (NUM_LOCK_RECORD - 1)
  17. struct shim_regs {
  18. unsigned long r15;
  19. unsigned long r14;
  20. unsigned long r13;
  21. unsigned long r12;
  22. unsigned long r11;
  23. unsigned long r10;
  24. unsigned long r9;
  25. unsigned long r8;
  26. unsigned long rcx;
  27. unsigned long rdx;
  28. unsigned long rsi;
  29. unsigned long rdi;
  30. unsigned long rbx;
  31. unsigned long rbp;
  32. unsigned long rflags;
  33. };
  34. struct shim_context {
  35. unsigned long syscall_nr;
  36. void * sp;
  37. void * ret_ip;
  38. struct shim_regs * regs;
  39. struct shim_context * next;
  40. uint64_t enter_time;
  41. uint64_t preempt;
  42. };
  43. #ifdef IN_SHIM
  44. #include <shim_defs.h>
  45. #define SIGNAL_DELAYED (0x80000000UL)
  46. #endif /* IN_SHIM */
  47. struct debug_buf;
  48. typedef struct {
  49. uint64_t canary;
  50. void * self;
  51. void * tp;
  52. struct shim_context context;
  53. unsigned int tid;
  54. int pal_errno;
  55. struct debug_buf * debug_buf;
  56. /* This record is for testing the memory of user inputs.
  57. * If a segfault occurs with the range [start, end],
  58. * the code addr is set to cont_addr to alert the caller. */
  59. struct {
  60. void * start, * end;
  61. void * cont_addr;
  62. } test_range;
  63. } shim_tcb_t;
  64. #ifdef IN_SHIM
  65. typedef struct
  66. {
  67. void * tcb, * dtv, * self;
  68. int mthreads, gscope;
  69. uintptr_t sysinfo, sg, pg;
  70. unsigned long int vgetcpu_cache[2];
  71. int __unused1;
  72. shim_tcb_t shim_tcb;
  73. } __libc_tcb_t;
  74. #include <stddef.h>
  75. static inline bool shim_tls_check_canary(void)
  76. {
  77. uint64_t __canary;
  78. __asm__ ("movq %%fs:%c1,%q0" : "=r" (__canary)
  79. : "i" (offsetof(__libc_tcb_t, shim_tcb.canary)));
  80. return __canary == SHIM_TLS_CANARY;
  81. }
  82. static inline shim_tcb_t * shim_get_tls(void)
  83. {
  84. shim_tcb_t *__self;
  85. __asm__ ("movq %%fs:%c1,%q0" : "=r" (__self)
  86. : "i" (offsetof(__libc_tcb_t, shim_tcb.self)));
  87. return __self;
  88. }
  89. static inline __libc_tcb_t * shim_libc_tcb(void)
  90. {
  91. __libc_tcb_t *__self;
  92. __asm__ ("movq %%fs:%c1,%q0" : "=r" (__self)
  93. : "i" (offsetof(__libc_tcb_t, tcb)));
  94. return __self;
  95. }
  96. #endif /* IN_SHIM */
  97. #endif /* !__ASSEMBLER__ */
  98. #endif /* _SHIM_H_ */