0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _ASM_PTRACE_H
0010 #define _ASM_PTRACE_H
0011
0012
0013 #include <linux/compiler.h>
0014 #include <linux/linkage.h>
0015 #include <linux/types.h>
0016 #include <asm/isadep.h>
0017 #include <asm/page.h>
0018 #include <asm/thread_info.h>
0019 #include <uapi/asm/ptrace.h>
0020
0021
0022
0023
0024
0025
0026
0027
0028 struct pt_regs {
0029 #ifdef CONFIG_32BIT
0030
0031 unsigned long pad0[8];
0032 #endif
0033
0034
0035 unsigned long regs[32];
0036
0037
0038 unsigned long cp0_status;
0039 unsigned long hi;
0040 unsigned long lo;
0041 #ifdef CONFIG_CPU_HAS_SMARTMIPS
0042 unsigned long acx;
0043 #endif
0044 unsigned long cp0_badvaddr;
0045 unsigned long cp0_cause;
0046 unsigned long cp0_epc;
0047 #ifdef CONFIG_CPU_CAVIUM_OCTEON
0048 unsigned long long mpl[6];
0049 unsigned long long mtp[6];
0050 #endif
0051 unsigned long __last[0];
0052 } __aligned(8);
0053
0054 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
0055 {
0056 return regs->regs[29];
0057 }
0058
0059 static inline void instruction_pointer_set(struct pt_regs *regs,
0060 unsigned long val)
0061 {
0062 regs->cp0_epc = val;
0063 }
0064
0065
0066 extern int regs_query_register_offset(const char *name);
0067 #define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 static inline unsigned long regs_get_register(struct pt_regs *regs,
0079 unsigned int offset)
0080 {
0081 if (unlikely(offset > MAX_REG_OFFSET))
0082 return 0;
0083
0084 return *(unsigned long *)((unsigned long)regs + offset);
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 static inline int regs_within_kernel_stack(struct pt_regs *regs,
0096 unsigned long addr)
0097 {
0098 return ((addr & ~(THREAD_SIZE - 1)) ==
0099 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
0100 }
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
0112 unsigned int n)
0113 {
0114 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
0115
0116 addr += n;
0117 if (regs_within_kernel_stack(regs, (unsigned long)addr))
0118 return *addr;
0119 else
0120 return 0;
0121 }
0122
0123 struct task_struct;
0124
0125 extern int ptrace_getregs(struct task_struct *child,
0126 struct user_pt_regs __user *data);
0127 extern int ptrace_setregs(struct task_struct *child,
0128 struct user_pt_regs __user *data);
0129
0130 extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
0131 extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
0132
0133 extern int ptrace_get_watch_regs(struct task_struct *child,
0134 struct pt_watch_regs __user *addr);
0135 extern int ptrace_set_watch_regs(struct task_struct *child,
0136 struct pt_watch_regs __user *addr);
0137
0138
0139
0140
0141 #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
0142
0143 static inline int is_syscall_success(struct pt_regs *regs)
0144 {
0145 return !regs->regs[7];
0146 }
0147
0148 static inline long regs_return_value(struct pt_regs *regs)
0149 {
0150 if (is_syscall_success(regs) || !user_mode(regs))
0151 return regs->regs[2];
0152 else
0153 return -regs->regs[2];
0154 }
0155
0156 #define instruction_pointer(regs) ((regs)->cp0_epc)
0157 #define profile_pc(regs) instruction_pointer(regs)
0158
0159 extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall);
0160 extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
0161
0162 extern void die(const char *, struct pt_regs *) __noreturn;
0163
0164 static inline void die_if_kernel(const char *str, struct pt_regs *regs)
0165 {
0166 if (unlikely(!user_mode(regs)))
0167 die(str, regs);
0168 }
0169
0170 #define current_pt_regs() \
0171 ({ \
0172 unsigned long sp = (unsigned long)__builtin_frame_address(0); \
0173 (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
0174 })
0175
0176
0177
0178 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
0179 {
0180 return regs->regs[29];
0181 }
0182
0183 static inline void user_stack_pointer_set(struct pt_regs *regs,
0184 unsigned long val)
0185 {
0186 regs->regs[29] = val;
0187 }
0188
0189 #endif