1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2000-2003, Axis Communications AB.
6 #include <linux/kernel.h>
7 #include <linux/sched.h>
8 #include <linux/sched/task_stack.h>
10 #include <linux/smp.h>
11 #include <linux/errno.h>
12 #include <linux/ptrace.h>
13 #include <linux/user.h>
14 #include <linux/signal.h>
15 #include <linux/security.h>
17 #include <linux/uaccess.h>
19 #include <asm/pgtable.h>
20 #include <asm/processor.h>
23 * Determines which bits in DCCR the user has access to.
24 * 1 = access, 0 = no access.
26 #define DCCR_MASK 0x0000001f /* XNZVC */
29 * Get contents of register REGNO in task TASK.
31 inline long get_reg(struct task_struct
*task
, unsigned int regno
)
33 /* USP is a special case, it's not in the pt_regs struct but
34 * in the tasks thread struct
38 return task
->thread
.usp
;
39 else if (regno
< PT_MAX
)
40 return ((unsigned long *)task_pt_regs(task
))[regno
];
46 * Write contents of register REGNO in task TASK.
48 inline int put_reg(struct task_struct
*task
, unsigned int regno
,
52 task
->thread
.usp
= data
;
53 else if (regno
< PT_MAX
)
54 ((unsigned long *)task_pt_regs(task
))[regno
] = data
;
61 * Called by kernel/ptrace.c when detaching.
63 * Make sure the single step bit is not set.
66 ptrace_disable(struct task_struct
*child
)
68 /* Todo - pending singlesteps? */
69 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
73 * Note that this implementation of ptrace behaves differently from vanilla
74 * ptrace. Contrary to what the man page says, in the PTRACE_PEEKTEXT,
75 * PTRACE_PEEKDATA, and PTRACE_PEEKUSER requests the data variable is not
76 * ignored. Instead, the data variable is expected to point at a location
77 * (in user space) where the result of the ptrace call is written (instead of
80 long arch_ptrace(struct task_struct
*child
, long request
,
81 unsigned long addr
, unsigned long data
)
84 unsigned int regno
= addr
>> 2;
85 unsigned long __user
*datap
= (unsigned long __user
*)data
;
88 /* Read word at location address. */
91 ret
= generic_ptrace_peekdata(child
, addr
, data
);
94 /* Read the word at location address in the USER area. */
95 case PTRACE_PEEKUSR
: {
99 if ((addr
& 3) || regno
> PT_MAX
)
102 tmp
= get_reg(child
, regno
);
103 ret
= put_user(tmp
, datap
);
107 /* Write the word at location address. */
108 case PTRACE_POKETEXT
:
109 case PTRACE_POKEDATA
:
110 ret
= generic_ptrace_pokedata(child
, addr
, data
);
113 /* Write the word at location address in the USER area. */
116 if ((addr
& 3) || regno
> PT_MAX
)
119 if (regno
== PT_DCCR
) {
120 /* don't allow the tracing process to change stuff like
121 * interrupt enable, kernel/user bit, dma enables etc.
124 data
|= get_reg(child
, PT_DCCR
) & ~DCCR_MASK
;
126 if (put_reg(child
, regno
, data
))
131 /* Get all GP registers from the child. */
132 case PTRACE_GETREGS
: {
137 for (i
= 0; i
<= PT_MAX
; i
++) {
138 tmp
= get_reg(child
, i
);
140 if (put_user(tmp
, datap
)) {
151 /* Set all GP registers in the child. */
152 case PTRACE_SETREGS
: {
157 for (i
= 0; i
<= PT_MAX
; i
++) {
158 if (get_user(tmp
, datap
)) {
165 tmp
|= get_reg(child
, PT_DCCR
) & ~DCCR_MASK
;
168 put_reg(child
, i
, tmp
);
176 ret
= ptrace_request(child
, request
, addr
, data
);
183 void do_syscall_trace(void)
185 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
188 if (!(current
->ptrace
& PT_PTRACED
))
191 /* the 0x80 provides a way for the tracing parent to distinguish
192 between a syscall stop and SIGTRAP delivery */
193 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
197 * This isn't the same as continuing with a signal, but it will do for
200 if (current
->exit_code
) {
201 send_sig(current
->exit_code
, current
, 1);
202 current
->exit_code
= 0;