ucontext.h 6.2 KB

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