thread_data.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #ifndef _THREAD_DATA_H_
  32. #define _THREAD_DATA_H_
  33. #include "se_types.h"
  34. #include "se_cdefs.h"
  35. #ifdef TD_SUPPORT_MULTI_PLATFORM
  36. /* To enable the SignTool to sign both 32/64-bit Enclave for ELF,
  37. * we need to make the struct `thread_data_t' have a consistent
  38. * definition for 32/64-bit compiler.
  39. *
  40. * We achieve it by forcing the compiler to check pre-defined macros
  41. * `RTS_SYSTEM_WORDSIZE'
  42. *
  43. * |--------------------------+-------|
  44. * | RTS_SYSTEM_WORDSIZE = 32 | ELF32 |
  45. * |--------------------------+-------|
  46. * | RTS_SYSTEM_WORDSIZE = 64 | ELF64 |
  47. *
  48. */
  49. # ifndef RTS_SYSTEM_WORDSIZE
  50. # error RTS_SYSTEM_WORDSIZE should be pre-defined.
  51. # endif
  52. /* Avoid to use `uintptr_t' in the struct `thread_data_t' and its members. */
  53. # if RTS_SYSTEM_WORDSIZE == 32
  54. typedef uint32_t sys_word_t;
  55. # elif RTS_SYSTEM_WORDSIZE == 64
  56. typedef uint64_t sys_word_t;
  57. # else
  58. # error Invalid value for 'RTS_SYSTEM_WORDSIZE'.
  59. # endif
  60. #else
  61. /* For uRTS, there is no need to define the macro 'TD_SUPPORT_MULTI_PLATFORM' */
  62. typedef size_t sys_word_t;
  63. /* SE_32 and SE_64 are defined in "se_cdefs.h" */
  64. # ifdef SE_32
  65. # define RTS_SYSTEM_WORDSIZE 32
  66. # elif defined(SE_64)
  67. # define RTS_SYSTEM_WORDSIZE 64
  68. # else
  69. # error Unknown system word size.
  70. # endif
  71. #endif /* ! TD_SUPPORT_MULTI_PLATFORM */
  72. /* The data structure currently is naturally aligned regardless of the value of
  73. * RTS_SYSTEM_WORDSIZE.
  74. *
  75. * However, we need to take care when modifying the data structure in future.
  76. */
  77. typedef struct _thread_data_t
  78. {
  79. sys_word_t self_addr;
  80. sys_word_t last_sp; /* set by urts, relative to TCS */
  81. sys_word_t stack_base_addr; /* set by urts, relative to TCS */
  82. sys_word_t stack_limit_addr; /* set by urts, relative to TCS */
  83. sys_word_t first_ssa_gpr; /* set by urts, relative to TCS */
  84. sys_word_t stack_guard; /* GCC expects start_guard at 0x14 on x86 and 0x28 on x64 */
  85. sys_word_t reserved;
  86. sys_word_t ssa_frame_size; /* set by urts, in pages (se_ptrace.c needs to know its offset). */
  87. sys_word_t last_error; /* init to be 0. Used by trts. */
  88. #ifdef TD_SUPPORT_MULTI_PLATFORM
  89. sys_word_t m_next; /* next TD used by trusted thread library (of type "struct _thread_data *") */
  90. #else
  91. struct _thread_data_t *m_next;
  92. #endif
  93. sys_word_t tls_addr; /* points to TLS pages */
  94. sys_word_t tls_array; /* points to TD.tls_addr relative to TCS */
  95. #ifdef TD_SUPPORT_MULTI_PLATFORM
  96. sys_word_t exception_flag; /* mark how many exceptions are being handled */
  97. #else
  98. intptr_t exception_flag;
  99. #endif
  100. sys_word_t cxx_thread_info[6];
  101. } thread_data_t;
  102. #ifdef __cplusplus
  103. extern "C" {
  104. #endif
  105. thread_data_t *get_thread_data(void);
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif