blob: cec5e125f7e466fceb8680f029de9ad040b9c4a3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070012
David Daney0926bf92008-09-23 00:11:26 -070013#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/linkage.h>
Yoichi Yuasaf6a31762008-10-25 17:30:35 +090015#include <linux/types.h>
Atsushi Nemoto8f9a2b32006-09-07 01:00:22 +090016#include <asm/isadep.h>
David Howells61730c52012-10-09 09:47:14 +010017#include <uapi/asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
David Daney0926bf92008-09-23 00:11:26 -070019struct task_struct;
20
Ralf Baechled302d052008-10-11 16:18:57 +010021extern int ptrace_getregs(struct task_struct *child, __s64 __user *data);
22extern int ptrace_setregs(struct task_struct *child, __s64 __user *data);
23
24extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
25extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
26
David Daney0926bf92008-09-23 00:11:26 -070027extern int ptrace_get_watch_regs(struct task_struct *child,
28 struct pt_watch_regs __user *addr);
29extern int ptrace_set_watch_regs(struct task_struct *child,
30 struct pt_watch_regs __user *addr);
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * Does the process account for user or for system time?
34 */
35#define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
36
Eric Parisd7e75282012-01-03 14:23:06 -050037static inline int is_syscall_success(struct pt_regs *regs)
38{
39 return !regs->regs[7];
40}
41
42static inline long regs_return_value(struct pt_regs *regs)
43{
44 if (is_syscall_success(regs))
45 return regs->regs[2];
46 else
47 return -regs->regs[2];
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define instruction_pointer(regs) ((regs)->cp0_epc)
51#define profile_pc(regs) instruction_pointer(regs)
52
Ralf Baechle8b659a32011-05-19 09:21:29 +010053extern asmlinkage void syscall_trace_enter(struct pt_regs *regs);
54extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Joe Perchesff2d8b12012-01-12 17:17:21 -080056extern void die(const char *, struct pt_regs *) __noreturn;
Ralf Baechle2d911e92006-12-10 15:02:17 +000057
Yury Polyanskiyce384d82010-04-26 00:53:10 -040058static inline void die_if_kernel(const char *str, struct pt_regs *regs)
Ralf Baechle2d911e92006-12-10 15:02:17 +000059{
60 if (unlikely(!user_mode(regs)))
61 die(str, regs);
62}
63
Ralf Baechlebaf9ff72012-10-09 21:16:07 +020064#define current_pt_regs() \
65({ \
66 unsigned long sp = (unsigned long)__builtin_frame_address(0); \
67 (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
68})
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#endif /* _ASM_PTRACE_H */