ucontext.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* Copyright (C) 1998, 1999, 2002, 2004, 2005 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. <http://www.gnu.org/licenses/>. */
  14. #ifndef _SYS_UCONTEXT_H
  15. #define _SYS_UCONTEXT_H 1
  16. #include <features.h>
  17. #include <signal.h>
  18. /* We need the signal context definitions even if they are not used
  19. included in <signal.h>. */
  20. #include <bits/sigcontext.h>
  21. #if __WORDSIZE == 32
  22. /* Number of general registers. */
  23. # define NGREG 48
  24. /* Container for all general registers. */
  25. typedef unsigned long gregset_t[NGREG];
  26. /* Container for floating-point registers and status */
  27. typedef struct _libc_fpstate
  28. {
  29. double fpregs[32];
  30. double fpscr;
  31. unsigned int _pad[2];
  32. } fpregset_t;
  33. /* Container for Altivec/VMX registers and status.
  34. Needs to be aligned on a 16-byte boundary. */
  35. typedef struct _libc_vrstate
  36. {
  37. unsigned int vrregs[32][4];
  38. unsigned int vrsave;
  39. unsigned int _pad[2];
  40. unsigned int vscr;
  41. } vrregset_t;
  42. /* Context to describe whole processor state. */
  43. typedef struct
  44. {
  45. gregset_t gregs;
  46. fpregset_t fpregs;
  47. vrregset_t vrregs __attribute__((__aligned__(16)));
  48. } mcontext_t;
  49. #else
  50. /* For 64-bit kernels with Altivec support, a machine context is exactly
  51. * a sigcontext. For older kernel (without Altivec) the sigcontext matches
  52. * the mcontext upto but not including the v_regs field. For kernels that
  53. * don't AT_HWCAP or return AT_HWCAP without PPC_FEATURE_HAS_ALTIVEC the
  54. * v_regs field may not exit and should not be referenced. The v_regd field
  55. * can be refernced safely only after verifying that PPC_FEATURE_HAS_ALTIVEC
  56. * is set in AT_HWCAP. */
  57. /* Number of general registers. */
  58. # define NGREG 48 /* includes r0-r31, nip, msr, lr, etc. */
  59. # define NFPREG 33 /* includes fp0-fp31 &fpscr. */
  60. # define NVRREG 34 /* includes v0-v31, vscr, & vrsave in split vectors */
  61. typedef unsigned long gregset_t[NGREG];
  62. typedef double fpregset_t[NFPREG];
  63. /* Container for Altivec/VMX Vector Status and Control Register. Only 32-bits
  64. but can only be copied to/from a 128-bit vector register. So we allocated
  65. a whole quadword speedup save/restore. */
  66. typedef struct _libc_vscr
  67. {
  68. unsigned int __pad[3];
  69. unsigned int vscr_word;
  70. } vscr_t;
  71. /* Container for Altivec/VMX registers and status.
  72. Must to be aligned on a 16-byte boundary. */
  73. typedef struct _libc_vrstate
  74. {
  75. unsigned int vrregs[32][4];
  76. vscr_t vscr;
  77. unsigned int vrsave;
  78. unsigned int __pad[3];
  79. } vrregset_t __attribute__((__aligned__(16)));
  80. typedef struct {
  81. unsigned long __unused[4];
  82. int signal;
  83. int __pad0;
  84. unsigned long handler;
  85. unsigned long oldmask;
  86. struct pt_regs *regs;
  87. gregset_t gp_regs;
  88. fpregset_t fp_regs;
  89. /*
  90. * To maintain compatibility with current implementations the sigcontext is
  91. * extended by appending a pointer (v_regs) to a quadword type (elf_vrreg_t)
  92. * followed by an unstructured (vmx_reserve) field of 69 doublewords. This
  93. * allows the array of vector registers to be quadword aligned independent of
  94. * the alignment of the containing sigcontext or ucontext. It is the
  95. * responsibility of the code setting the sigcontext to set this pointer to
  96. * either NULL (if this processor does not support the VMX feature) or the
  97. * address of the first quadword within the allocated (vmx_reserve) area.
  98. *
  99. * The pointer (v_regs) of vector type (elf_vrreg_t) is essentually
  100. * an array of 34 quadword entries. The entries with
  101. * indexes 0-31 contain the corresponding vector registers. The entry with
  102. * index 32 contains the vscr as the last word (offset 12) within the
  103. * quadword. This allows the vscr to be stored as either a quadword (since
  104. * it must be copied via a vector register to/from storage) or as a word.
  105. * The entry with index 33 contains the vrsave as the first word (offset 0)
  106. * within the quadword.
  107. */
  108. vrregset_t *v_regs;
  109. long vmx_reserve[NVRREG+NVRREG+1];
  110. } mcontext_t;
  111. #endif
  112. /* Userlevel context. */
  113. typedef struct ucontext
  114. {
  115. unsigned long int uc_flags;
  116. struct ucontext *uc_link;
  117. stack_t uc_stack;
  118. #if __WORDSIZE == 32
  119. /*
  120. * These fields are set up this way to maximize source and
  121. * binary compatibility with code written for the old
  122. * ucontext_t definition, which didn't include space for the
  123. * registers.
  124. *
  125. * Different versions of the kernel have stored the registers on
  126. * signal delivery at different offsets from the ucontext struct.
  127. * Programs should thus use the uc_mcontext.uc_regs pointer to
  128. * find where the registers are actually stored. The registers
  129. * will be stored within the ucontext_t struct but not necessarily
  130. * at a fixed address. As a side-effect, this lets us achieve
  131. * 16-byte alignment for the register storage space if the
  132. * Altivec registers are to be saved, without requiring 16-byte
  133. * alignment on the whole ucontext_t.
  134. *
  135. * The uc_mcontext.regs field is included for source compatibility
  136. * with programs written against the older ucontext_t definition,
  137. * and its name should therefore not change. The uc_pad field
  138. * is for binary compatibility with programs compiled against the
  139. * old ucontext_t; it ensures that uc_mcontext.regs and uc_sigmask
  140. * are at the same offset as previously.
  141. */
  142. int uc_pad[7];
  143. union uc_regs_ptr {
  144. struct pt_regs *regs;
  145. mcontext_t *uc_regs;
  146. } uc_mcontext;
  147. sigset_t uc_sigmask;
  148. char uc_reg_space[sizeof(mcontext_t) + 12]; /* last for extensibility */
  149. #else /* 64-bit */
  150. sigset_t uc_sigmask;
  151. mcontext_t uc_mcontext; /* last for extensibility */
  152. #endif
  153. } ucontext_t;
  154. #endif /* sys/ucontext.h */