ucontext.h 6.3 KB

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