2 * Copyright (C) 2000-2003, Axis Communications AB.
5 #include <linux/kernel.h>
6 #include <linux/sched.h>
7 #include <linux/sched/task_stack.h>
10 #include <linux/errno.h>
11 #include <linux/ptrace.h>
12 #include <linux/user.h>
13 #include <linux/signal.h>
14 #include <linux/security.h>
16 #include <linux/uaccess.h>
18 #include <asm/pgtable.h>
19 #include <asm/processor.h>
22 * Determines which bits in DCCR the user has access to.
23 * 1 = access, 0 = no access.
25 #define DCCR_MASK 0x0000001f /* XNZVC */
28 * Get contents of register REGNO in task TASK.
30 inline long get_reg(struct task_struct
*task
, unsigned int regno
)
32 /* USP is a special case, it's not in the pt_regs struct but
33 * in the tasks thread struct
37 return task
->thread
.usp
;
38 else if (regno
< PT_MAX
)
39 return ((unsigned long *)task_pt_regs(task
))[regno
];
45 * Write contents of register REGNO in task TASK.
47 inline int put_reg(struct task_struct
*task
, unsigned int regno
,
51 task
->thread
.usp
= data
;
52 else if (regno
< PT_MAX
)
53 ((unsigned long *)task_pt_regs(task
))[regno
] = data
;
60 * Called by kernel/ptrace.c when detaching.
62 * Make sure the single step bit is not set.
65 ptrace_disable(struct task_struct
*child
)
67 /* Todo - pending singlesteps? */
68 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
72 * Note that this implementation of ptrace behaves differently from vanilla
73 * ptrace. Contrary to what the man page says, in the PTRACE_PEEKTEXT,
74 * PTRACE_PEEKDATA, and PTRACE_PEEKUSER requests the data variable is not
75 * ignored. Instead, the data variable is expected to point at a location
76 * (in user space) where the result of the ptrace call is written (instead of
79 long arch_ptrace(struct task_struct
*child
, long request
,
80 unsigned long addr
, unsigned long data
)
83 unsigned int regno
= addr
>> 2;
84 unsigned long __user
*datap
= (unsigned long __user
*)data
;
87 /* Read word at location address. */
90 ret
= generic_ptrace_peekdata(child
, addr
, data
);
93 /* Read the word at location address in the USER area. */
94 case PTRACE_PEEKUSR
: {
98 if ((addr
& 3) || regno
> PT_MAX
)
101 tmp
= get_reg(child
, regno
);
102 ret
= put_user(tmp
, datap
);
106 /* Write the word at location address. */
107 case PTRACE_POKETEXT
:
108 case PTRACE_POKEDATA
:
109 ret
= generic_ptrace_pokedata(child
, addr
, data
);
112 /* Write the word at location address in the USER area. */
115 if ((addr
& 3) || regno
> PT_MAX
)
118 if (regno
== PT_DCCR
) {
119 /* don't allow the tracing process to change stuff like
120 * interrupt enable, kernel/user bit, dma enables etc.
123 data
|= get_reg(child
, PT_DCCR
) & ~DCCR_MASK
;
125 if (put_reg(child
, regno
, data
))
130 /* Get all GP registers from the child. */
131 case PTRACE_GETREGS
: {
136 for (i
= 0; i
<= PT_MAX
; i
++) {
137 tmp
= get_reg(child
, i
);
139 if (put_user(tmp
, datap
)) {
150 /* Set all GP registers in the child. */
151 case PTRACE_SETREGS
: {
156 for (i
= 0; i
<= PT_MAX
; i
++) {
157 if (get_user(tmp
, datap
)) {
164 tmp
|= get_reg(child
, PT_DCCR
) & ~DCCR_MASK
;
167 put_reg(child
, i
, tmp
);
175 ret
= ptrace_request(child
, request
, addr
, data
);
182 void do_syscall_trace(void)
184 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
187 if (!(current
->ptrace
& PT_PTRACED
))
190 /* the 0x80 provides a way for the tracing parent to distinguish
191 between a syscall stop and SIGTRAP delivery */
192 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
196 * This isn't the same as continuing with a signal, but it will do for
199 if (current
->exit_code
) {
200 send_sig(current
->exit_code
, current
, 1);
201 current
->exit_code
= 0;