ptrace.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Based on arch/arm/include/asm/ptrace.h
  3. *
  4. * Copyright (C) 1996-2003 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_PTRACE_H
  20. #define __ASM_PTRACE_H
  21. #include <linux/types.h>
  22. #include <asm/hwcap.h>
  23. /* AArch32-specific ptrace requests */
  24. #define COMPAT_PTRACE_GETREGS 12
  25. #define COMPAT_PTRACE_SETREGS 13
  26. #define COMPAT_PTRACE_GET_THREAD_AREA 22
  27. #define COMPAT_PTRACE_SET_SYSCALL 23
  28. #define COMPAT_PTRACE_GETVFPREGS 27
  29. #define COMPAT_PTRACE_SETVFPREGS 28
  30. #define COMPAT_PTRACE_GETHBPREGS 29
  31. #define COMPAT_PTRACE_SETHBPREGS 30
  32. /*
  33. * PSR bits
  34. */
  35. #define PSR_MODE_EL0t 0x00000000
  36. #define PSR_MODE_EL1t 0x00000004
  37. #define PSR_MODE_EL1h 0x00000005
  38. #define PSR_MODE_EL2t 0x00000008
  39. #define PSR_MODE_EL2h 0x00000009
  40. #define PSR_MODE_EL3t 0x0000000c
  41. #define PSR_MODE_EL3h 0x0000000d
  42. #define PSR_MODE_MASK 0x0000000f
  43. /* AArch32 CPSR bits */
  44. #define PSR_MODE32_BIT 0x00000010
  45. #define COMPAT_PSR_MODE_USR 0x00000010
  46. #define COMPAT_PSR_T_BIT 0x00000020
  47. #define COMPAT_PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
  48. /* AArch64 SPSR bits */
  49. #define PSR_F_BIT 0x00000040
  50. #define PSR_I_BIT 0x00000080
  51. #define PSR_A_BIT 0x00000100
  52. #define PSR_D_BIT 0x00000200
  53. #define PSR_Q_BIT 0x08000000
  54. #define PSR_V_BIT 0x10000000
  55. #define PSR_C_BIT 0x20000000
  56. #define PSR_Z_BIT 0x40000000
  57. #define PSR_N_BIT 0x80000000
  58. /*
  59. * Groups of PSR bits
  60. */
  61. #define PSR_f 0xff000000 /* Flags */
  62. #define PSR_s 0x00ff0000 /* Status */
  63. #define PSR_x 0x0000ff00 /* Extension */
  64. #define PSR_c 0x000000ff /* Control */
  65. /*
  66. * These are 'magic' values for PTRACE_PEEKUSR that return info about where a
  67. * process is located in memory.
  68. */
  69. #define PT_TEXT_ADDR 0x10000
  70. #define PT_DATA_ADDR 0x10004
  71. #define PT_TEXT_END_ADDR 0x10008
  72. #ifndef __ASSEMBLY__
  73. /*
  74. * User structures for general purpose, floating point and debug registers.
  75. */
  76. struct user_pt_regs {
  77. __u64 regs[31];
  78. __u64 sp;
  79. __u64 pc;
  80. __u64 pstate;
  81. };
  82. struct user_fpsimd_state {
  83. __uint128_t vregs[32];
  84. __u32 fpsr;
  85. __u32 fpcr;
  86. };
  87. struct user_hwdebug_state {
  88. __u32 dbg_info;
  89. struct {
  90. __u64 addr;
  91. __u32 ctrl;
  92. } dbg_regs[16];
  93. };
  94. #ifdef __KERNEL__
  95. /* sizeof(struct user) for AArch32 */
  96. #define COMPAT_USER_SZ 296
  97. /* AArch32 uses x13 as the stack pointer... */
  98. #define compat_sp regs[13]
  99. /* ... and x14 as the link register. */
  100. #define compat_lr regs[14]
  101. /*
  102. * This struct defines the way the registers are stored on the stack during an
  103. * exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for
  104. * stack alignment). struct user_pt_regs must form a prefix of struct pt_regs.
  105. */
  106. struct pt_regs {
  107. union {
  108. struct user_pt_regs user_regs;
  109. struct {
  110. u64 regs[31];
  111. u64 sp;
  112. u64 pc;
  113. u64 pstate;
  114. };
  115. };
  116. u64 orig_x0;
  117. u64 syscallno;
  118. };
  119. #define arch_has_single_step() (1)
  120. #ifdef CONFIG_COMPAT
  121. #define compat_thumb_mode(regs) \
  122. (((regs)->pstate & COMPAT_PSR_T_BIT))
  123. #else
  124. #define compat_thumb_mode(regs) (0)
  125. #endif
  126. #define user_mode(regs) \
  127. (((regs)->pstate & PSR_MODE_MASK) == PSR_MODE_EL0t)
  128. #define compat_user_mode(regs) \
  129. (((regs)->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) == \
  130. (PSR_MODE32_BIT | PSR_MODE_EL0t))
  131. #define processor_mode(regs) \
  132. ((regs)->pstate & PSR_MODE_MASK)
  133. #define interrupts_enabled(regs) \
  134. (!((regs)->pstate & PSR_I_BIT))
  135. #define fast_interrupts_enabled(regs) \
  136. (!((regs)->pstate & PSR_F_BIT))
  137. #define user_stack_pointer(regs) \
  138. ((regs)->sp)
  139. /*
  140. * Are the current registers suitable for user mode? (used to maintain
  141. * security in signal handlers)
  142. */
  143. static inline int valid_user_regs(struct user_pt_regs *regs)
  144. {
  145. if (user_mode(regs) && (regs->pstate & PSR_I_BIT) == 0) {
  146. regs->pstate &= ~(PSR_F_BIT | PSR_A_BIT);
  147. /* The T bit is reserved for AArch64 */
  148. if (!(regs->pstate & PSR_MODE32_BIT))
  149. regs->pstate &= ~COMPAT_PSR_T_BIT;
  150. return 1;
  151. }
  152. /*
  153. * Force PSR to something logical...
  154. */
  155. regs->pstate &= PSR_f | PSR_s | (PSR_x & ~PSR_A_BIT) | \
  156. COMPAT_PSR_T_BIT | PSR_MODE32_BIT;
  157. if (!(regs->pstate & PSR_MODE32_BIT)) {
  158. regs->pstate &= ~COMPAT_PSR_T_BIT;
  159. regs->pstate |= PSR_MODE_EL0t;
  160. }
  161. return 0;
  162. }
  163. #define instruction_pointer(regs) (regs)->pc
  164. #ifdef CONFIG_SMP
  165. extern unsigned long profile_pc(struct pt_regs *regs);
  166. #else
  167. #define profile_pc(regs) instruction_pointer(regs)
  168. #endif
  169. extern int aarch32_break_trap(struct pt_regs *regs);
  170. #endif /* __KERNEL__ */
  171. #endif /* __ASSEMBLY__ */
  172. #endif