Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
David Daney | 0926bf9 | 2008-09-23 00:11:26 -0700 | [diff] [blame] | 13 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/linkage.h> |
Yoichi Yuasa | f6a3176 | 2008-10-25 17:30:35 +0900 | [diff] [blame] | 15 | #include <linux/types.h> |
Atsushi Nemoto | 8f9a2b3 | 2006-09-07 01:00:22 +0900 | [diff] [blame] | 16 | #include <asm/isadep.h> |
David Howells | 61730c5 | 2012-10-09 09:47:14 +0100 | [diff] [blame] | 17 | #include <uapi/asm/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
David Daney | 8f65793 | 2013-05-22 22:35:56 +0000 | [diff] [blame] | 19 | /* |
| 20 | * This struct defines the way the registers are stored on the stack during a |
| 21 | * system call/exception. As usual the registers k0/k1 aren't being saved. |
| 22 | */ |
| 23 | struct pt_regs { |
| 24 | #ifdef CONFIG_32BIT |
| 25 | /* Pad bytes for argument save space on the stack. */ |
| 26 | unsigned long pad0[6]; |
| 27 | #endif |
| 28 | |
| 29 | /* Saved main processor registers. */ |
| 30 | unsigned long regs[32]; |
| 31 | |
| 32 | /* Saved special registers. */ |
| 33 | unsigned long cp0_status; |
| 34 | unsigned long hi; |
| 35 | unsigned long lo; |
| 36 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 37 | unsigned long acx; |
| 38 | #endif |
| 39 | unsigned long cp0_badvaddr; |
| 40 | unsigned long cp0_cause; |
| 41 | unsigned long cp0_epc; |
| 42 | #ifdef CONFIG_MIPS_MT_SMTC |
| 43 | unsigned long cp0_tcstatus; |
| 44 | #endif /* CONFIG_MIPS_MT_SMTC */ |
| 45 | #ifdef CONFIG_CPU_CAVIUM_OCTEON |
| 46 | unsigned long long mpl[3]; /* MTM{0,1,2} */ |
| 47 | unsigned long long mtp[3]; /* MTP{0,1,2} */ |
| 48 | #endif |
| 49 | } __aligned(8); |
| 50 | |
David Daney | 0926bf9 | 2008-09-23 00:11:26 -0700 | [diff] [blame] | 51 | struct task_struct; |
| 52 | |
Ralf Baechle | d302d05 | 2008-10-11 16:18:57 +0100 | [diff] [blame] | 53 | extern int ptrace_getregs(struct task_struct *child, __s64 __user *data); |
| 54 | extern int ptrace_setregs(struct task_struct *child, __s64 __user *data); |
| 55 | |
| 56 | extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data); |
| 57 | extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data); |
| 58 | |
David Daney | 0926bf9 | 2008-09-23 00:11:26 -0700 | [diff] [blame] | 59 | extern int ptrace_get_watch_regs(struct task_struct *child, |
| 60 | struct pt_watch_regs __user *addr); |
| 61 | extern int ptrace_set_watch_regs(struct task_struct *child, |
| 62 | struct pt_watch_regs __user *addr); |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* |
| 65 | * Does the process account for user or for system time? |
| 66 | */ |
| 67 | #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER) |
| 68 | |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 69 | static inline int is_syscall_success(struct pt_regs *regs) |
| 70 | { |
| 71 | return !regs->regs[7]; |
| 72 | } |
| 73 | |
| 74 | static inline long regs_return_value(struct pt_regs *regs) |
| 75 | { |
| 76 | if (is_syscall_success(regs)) |
| 77 | return regs->regs[2]; |
| 78 | else |
| 79 | return -regs->regs[2]; |
| 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #define instruction_pointer(regs) ((regs)->cp0_epc) |
| 83 | #define profile_pc(regs) instruction_pointer(regs) |
| 84 | |
Markos Chandras | 4c21b8f | 2014-01-22 14:40:03 +0000 | [diff] [blame] | 85 | extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall); |
Ralf Baechle | 8b659a3 | 2011-05-19 09:21:29 +0100 | [diff] [blame] | 86 | extern asmlinkage void syscall_trace_leave(struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Joe Perches | ff2d8b1 | 2012-01-12 17:17:21 -0800 | [diff] [blame] | 88 | extern void die(const char *, struct pt_regs *) __noreturn; |
Ralf Baechle | 2d911e9 | 2006-12-10 15:02:17 +0000 | [diff] [blame] | 89 | |
Yury Polyanskiy | ce384d8 | 2010-04-26 00:53:10 -0400 | [diff] [blame] | 90 | static inline void die_if_kernel(const char *str, struct pt_regs *regs) |
Ralf Baechle | 2d911e9 | 2006-12-10 15:02:17 +0000 | [diff] [blame] | 91 | { |
| 92 | if (unlikely(!user_mode(regs))) |
| 93 | die(str, regs); |
| 94 | } |
| 95 | |
Ralf Baechle | baf9ff7 | 2012-10-09 21:16:07 +0200 | [diff] [blame] | 96 | #define current_pt_regs() \ |
| 97 | ({ \ |
| 98 | unsigned long sp = (unsigned long)__builtin_frame_address(0); \ |
| 99 | (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \ |
| 100 | }) |
| 101 | |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 102 | /* Helpers for working with the user stack pointer */ |
| 103 | |
| 104 | static inline unsigned long user_stack_pointer(struct pt_regs *regs) |
| 105 | { |
| 106 | return regs->regs[29]; |
| 107 | } |
| 108 | |
| 109 | static inline void user_stack_pointer_set(struct pt_regs *regs, |
| 110 | unsigned long val) |
| 111 | { |
| 112 | regs->regs[29] = val; |
| 113 | } |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #endif /* _ASM_PTRACE_H */ |