ptrace.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_PTRACE_H
  10. #define _ASM_PTRACE_H
  11. #include <linux/compiler.h>
  12. #include <linux/linkage.h>
  13. #include <linux/types.h>
  14. #include <asm/isadep.h>
  15. #include <uapi/asm/ptrace.h>
  16. /*
  17. * This struct defines the way the registers are stored on the stack during a
  18. * system call/exception. As usual the registers k0/k1 aren't being saved.
  19. */
  20. struct pt_regs {
  21. #ifdef CONFIG_32BIT
  22. /* Pad bytes for argument save space on the stack. */
  23. unsigned long pad0[6];
  24. #endif
  25. /* Saved main processor registers. */
  26. unsigned long regs[32];
  27. /* Saved special registers. */
  28. unsigned long cp0_status;
  29. unsigned long hi;
  30. unsigned long lo;
  31. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  32. unsigned long acx;
  33. #endif
  34. unsigned long cp0_badvaddr;
  35. unsigned long cp0_cause;
  36. unsigned long cp0_epc;
  37. #ifdef CONFIG_MIPS_MT_SMTC
  38. unsigned long cp0_tcstatus;
  39. #endif /* CONFIG_MIPS_MT_SMTC */
  40. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  41. unsigned long long mpl[3]; /* MTM{0,1,2} */
  42. unsigned long long mtp[3]; /* MTP{0,1,2} */
  43. #endif
  44. } __aligned(8);
  45. struct task_struct;
  46. extern int ptrace_getregs(struct task_struct *child, __s64 __user *data);
  47. extern int ptrace_setregs(struct task_struct *child, __s64 __user *data);
  48. extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
  49. extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
  50. extern int ptrace_get_watch_regs(struct task_struct *child,
  51. struct pt_watch_regs __user *addr);
  52. extern int ptrace_set_watch_regs(struct task_struct *child,
  53. struct pt_watch_regs __user *addr);
  54. /*
  55. * Does the process account for user or for system time?
  56. */
  57. #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
  58. static inline int is_syscall_success(struct pt_regs *regs)
  59. {
  60. return !regs->regs[7];
  61. }
  62. static inline long regs_return_value(struct pt_regs *regs)
  63. {
  64. if (is_syscall_success(regs))
  65. return regs->regs[2];
  66. else
  67. return -regs->regs[2];
  68. }
  69. #define instruction_pointer(regs) ((regs)->cp0_epc)
  70. #define profile_pc(regs) instruction_pointer(regs)
  71. #define user_stack_pointer(r) ((r)->regs[29])
  72. extern asmlinkage void syscall_trace_enter(struct pt_regs *regs);
  73. extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
  74. extern void die(const char *, struct pt_regs *) __noreturn;
  75. static inline void die_if_kernel(const char *str, struct pt_regs *regs)
  76. {
  77. if (unlikely(!user_mode(regs)))
  78. die(str, regs);
  79. }
  80. #define current_pt_regs() \
  81. ({ \
  82. unsigned long sp = (unsigned long)__builtin_frame_address(0); \
  83. (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
  84. })
  85. #endif /* _ASM_PTRACE_H */