ucontext.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* Copyright (C) 2001-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #ifndef _SYS_UCONTEXT_H
  15. #define _SYS_UCONTEXT_H 1
  16. #include <features.h>
  17. #include <bits/types.h>
  18. #include <bits/types/sigset_t.h>
  19. #include <bits/types/stack_t.h>
  20. #ifdef __USE_MISC
  21. # define __ctx(fld) fld
  22. #else
  23. # define __ctx(fld) __ ## fld
  24. #endif
  25. #ifdef __x86_64__
  26. /* Type for general register. */
  27. __extension__ typedef long long int greg_t;
  28. /* Number of general registers. */
  29. #define __NGREG 23
  30. #ifdef __USE_MISC
  31. # define NGREG __NGREG
  32. #endif
  33. /* Container for all general registers. */
  34. typedef greg_t gregset_t[__NGREG];
  35. #ifdef __USE_GNU
  36. /* Number of each register in the `gregset_t' array. */
  37. enum
  38. {
  39. REG_R8 = 0,
  40. # define REG_R8 REG_R8
  41. REG_R9,
  42. # define REG_R9 REG_R9
  43. REG_R10,
  44. # define REG_R10 REG_R10
  45. REG_R11,
  46. # define REG_R11 REG_R11
  47. REG_R12,
  48. # define REG_R12 REG_R12
  49. REG_R13,
  50. # define REG_R13 REG_R13
  51. REG_R14,
  52. # define REG_R14 REG_R14
  53. REG_R15,
  54. # define REG_R15 REG_R15
  55. REG_RDI,
  56. # define REG_RDI REG_RDI
  57. REG_RSI,
  58. # define REG_RSI REG_RSI
  59. REG_RBP,
  60. # define REG_RBP REG_RBP
  61. REG_RBX,
  62. # define REG_RBX REG_RBX
  63. REG_RDX,
  64. # define REG_RDX REG_RDX
  65. REG_RAX,
  66. # define REG_RAX REG_RAX
  67. REG_RCX,
  68. # define REG_RCX REG_RCX
  69. REG_RSP,
  70. # define REG_RSP REG_RSP
  71. REG_RIP,
  72. # define REG_RIP REG_RIP
  73. REG_EFL,
  74. # define REG_EFL REG_EFL
  75. REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */
  76. # define REG_CSGSFS REG_CSGSFS
  77. REG_ERR,
  78. # define REG_ERR REG_ERR
  79. REG_TRAPNO,
  80. # define REG_TRAPNO REG_TRAPNO
  81. REG_OLDMASK,
  82. # define REG_OLDMASK REG_OLDMASK
  83. REG_CR2
  84. # define REG_CR2 REG_CR2
  85. };
  86. #endif
  87. struct _libc_fpxreg
  88. {
  89. unsigned short int __ctx(significand)[4];
  90. unsigned short int __ctx(exponent);
  91. unsigned short int __glibc_reserved1[3];
  92. };
  93. struct _libc_xmmreg
  94. {
  95. __uint32_t __ctx(element)[4];
  96. };
  97. struct _libc_fpstate
  98. {
  99. /* 64-bit FXSAVE format. */
  100. __uint16_t __ctx(cwd);
  101. __uint16_t __ctx(swd);
  102. __uint16_t __ctx(ftw);
  103. __uint16_t __ctx(fop);
  104. __uint64_t __ctx(rip);
  105. __uint64_t __ctx(rdp);
  106. __uint32_t __ctx(mxcsr);
  107. __uint32_t __ctx(mxcr_mask);
  108. struct _libc_fpxreg _st[8];
  109. struct _libc_xmmreg _xmm[16];
  110. __uint32_t __glibc_reserved1[24];
  111. };
  112. /* Structure to describe FPU registers. */
  113. typedef struct _libc_fpstate *fpregset_t;
  114. /* Context to describe whole processor state. */
  115. typedef struct
  116. {
  117. gregset_t __ctx(gregs);
  118. /* Note that fpregs is a pointer. */
  119. fpregset_t __ctx(fpregs);
  120. __extension__ unsigned long long __reserved1 [8];
  121. } mcontext_t;
  122. /* Userlevel context. */
  123. typedef struct ucontext_t
  124. {
  125. unsigned long int __ctx(uc_flags);
  126. struct ucontext_t *uc_link;
  127. stack_t uc_stack;
  128. mcontext_t uc_mcontext;
  129. sigset_t uc_sigmask;
  130. struct _libc_fpstate __fpregs_mem;
  131. __extension__ unsigned long long int __ssp[4];
  132. } ucontext_t;
  133. #else /* !__x86_64__ */
  134. /* Type for general register. */
  135. typedef int greg_t;
  136. /* Number of general registers. */
  137. #define __NGREG 19
  138. #ifdef __USE_MISC
  139. # define NGREG __NGREG
  140. #endif
  141. /* Container for all general registers. */
  142. typedef greg_t gregset_t[__NGREG];
  143. #ifdef __USE_GNU
  144. /* Number of each register is the `gregset_t' array. */
  145. enum
  146. {
  147. REG_GS = 0,
  148. # define REG_GS REG_GS
  149. REG_FS,
  150. # define REG_FS REG_FS
  151. REG_ES,
  152. # define REG_ES REG_ES
  153. REG_DS,
  154. # define REG_DS REG_DS
  155. REG_EDI,
  156. # define REG_EDI REG_EDI
  157. REG_ESI,
  158. # define REG_ESI REG_ESI
  159. REG_EBP,
  160. # define REG_EBP REG_EBP
  161. REG_ESP,
  162. # define REG_ESP REG_ESP
  163. REG_EBX,
  164. # define REG_EBX REG_EBX
  165. REG_EDX,
  166. # define REG_EDX REG_EDX
  167. REG_ECX,
  168. # define REG_ECX REG_ECX
  169. REG_EAX,
  170. # define REG_EAX REG_EAX
  171. REG_TRAPNO,
  172. # define REG_TRAPNO REG_TRAPNO
  173. REG_ERR,
  174. # define REG_ERR REG_ERR
  175. REG_EIP,
  176. # define REG_EIP REG_EIP
  177. REG_CS,
  178. # define REG_CS REG_CS
  179. REG_EFL,
  180. # define REG_EFL REG_EFL
  181. REG_UESP,
  182. # define REG_UESP REG_UESP
  183. REG_SS
  184. # define REG_SS REG_SS
  185. };
  186. #endif
  187. /* Definitions taken from the kernel headers. */
  188. struct _libc_fpreg
  189. {
  190. unsigned short int __ctx(significand)[4];
  191. unsigned short int __ctx(exponent);
  192. };
  193. struct _libc_fpstate
  194. {
  195. unsigned long int __ctx(cw);
  196. unsigned long int __ctx(sw);
  197. unsigned long int __ctx(tag);
  198. unsigned long int __ctx(ipoff);
  199. unsigned long int __ctx(cssel);
  200. unsigned long int __ctx(dataoff);
  201. unsigned long int __ctx(datasel);
  202. struct _libc_fpreg _st[8];
  203. unsigned long int __ctx(status);
  204. };
  205. /* Structure to describe FPU registers. */
  206. typedef struct _libc_fpstate *fpregset_t;
  207. /* Context to describe whole processor state. */
  208. typedef struct
  209. {
  210. gregset_t __ctx(gregs);
  211. /* Due to Linux's history we have to use a pointer here. The SysV/i386
  212. ABI requires a struct with the values. */
  213. fpregset_t __ctx(fpregs);
  214. unsigned long int __ctx(oldmask);
  215. unsigned long int __ctx(cr2);
  216. } mcontext_t;
  217. /* Userlevel context. */
  218. typedef struct ucontext_t
  219. {
  220. unsigned long int __ctx(uc_flags);
  221. struct ucontext_t *uc_link;
  222. stack_t uc_stack;
  223. mcontext_t uc_mcontext;
  224. sigset_t uc_sigmask;
  225. struct _libc_fpstate __fpregs_mem;
  226. unsigned long int __ssp[4];
  227. } ucontext_t;
  228. #endif /* !__x86_64__ */
  229. #undef __ctx
  230. #endif /* sys/ucontext.h */