Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
0007  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
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  * This struct defines the way the registers are stored on the stack during a
0023  * system call/exception. As usual the registers k0/k1 aren't being saved.
0024  *
0025  * If you add a register here, also add it to regoffset_table[] in
0026  * arch/mips/kernel/ptrace.c.
0027  */
0028 struct pt_regs {
0029 #ifdef CONFIG_32BIT
0030     /* Pad bytes for argument save space on the stack. */
0031     unsigned long pad0[8];
0032 #endif
0033 
0034     /* Saved main processor registers. */
0035     unsigned long regs[32];
0036 
0037     /* Saved special registers. */
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];        /* MTM{0-5} */
0049     unsigned long long mtp[6];        /* MTP{0-5} */
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 /* Query offset/name of register from its name/offset */
0066 extern int regs_query_register_offset(const char *name);
0067 #define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
0068 
0069 /**
0070  * regs_get_register() - get register value from its offset
0071  * @regs:       pt_regs from which register value is gotten.
0072  * @offset:     offset number of the register.
0073  *
0074  * regs_get_register returns the value of a register. The @offset is the
0075  * offset of the register in struct pt_regs address which specified by @regs.
0076  * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
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  * regs_within_kernel_stack() - check the address in the stack
0089  * @regs:       pt_regs which contains kernel stack pointer.
0090  * @addr:       address which is checked.
0091  *
0092  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
0093  * If @addr is within the kernel stack, it returns true. If not, returns false.
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  * regs_get_kernel_stack_nth() - get Nth entry of the stack
0104  * @regs:       pt_regs which contains kernel stack pointer.
0105  * @n:          stack entry number.
0106  *
0107  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
0108  * is specified by @regs. If the @n th entry is NOT in the kernel stack,
0109  * this returns 0.
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  * Does the process account for user or for system time?
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 /* Helpers for working with the user stack pointer */
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 /* _ASM_PTRACE_H */