2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
14 * Copied from i386: Ross Biro 1/23/92
17 #include <linux/kernel.h>
18 #include <linux/ptrace.h>
19 #include <linux/kprobes.h>
20 #include <linux/compat.h>
21 #include <linux/uaccess.h>
22 #include <asm/traps.h>
24 void user_enable_single_step(struct task_struct
*child
)
26 set_tsk_thread_flag(child
, TIF_SINGLESTEP
);
29 void user_disable_single_step(struct task_struct
*child
)
31 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
35 * Called by kernel/ptrace.c when detaching..
37 void ptrace_disable(struct task_struct
*child
)
39 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
42 * These two are currently unused, but will be set by arch_ptrace()
43 * and used in the syscall assembly when we do support them.
45 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
48 long arch_ptrace(struct task_struct
*child
, long request
,
49 unsigned long addr
, unsigned long data
)
51 unsigned long __user
*datap
= (long __user __force
*)data
;
55 unsigned long *childregs
;
60 case PTRACE_PEEKUSR
: /* Read register from pt_regs. */
61 if (addr
>= PTREGS_SIZE
)
63 childreg
= (char *)task_pt_regs(child
) + addr
;
65 if (is_compat_task()) {
66 if (addr
& (sizeof(compat_long_t
)-1))
68 ret
= put_user(*(compat_long_t
*)childreg
,
69 (compat_long_t __user
*)datap
);
73 if (addr
& (sizeof(long)-1))
75 ret
= put_user(*(long *)childreg
, datap
);
79 case PTRACE_POKEUSR
: /* Write register in pt_regs. */
80 if (addr
>= PTREGS_SIZE
)
82 childreg
= (char *)task_pt_regs(child
) + addr
;
84 if (is_compat_task()) {
85 if (addr
& (sizeof(compat_long_t
)-1))
87 *(compat_long_t
*)childreg
= data
;
91 if (addr
& (sizeof(long)-1))
93 *(long *)childreg
= data
;
98 case PTRACE_GETREGS
: /* Get all registers from the child. */
99 if (!access_ok(VERIFY_WRITE
, datap
, PTREGS_SIZE
))
101 childregs
= (long *)task_pt_regs(child
);
102 for (i
= 0; i
< sizeof(struct pt_regs
)/sizeof(unsigned long);
104 ret
= __put_user(childregs
[i
], &datap
[i
]);
110 case PTRACE_SETREGS
: /* Set all registers in the child. */
111 if (!access_ok(VERIFY_READ
, datap
, PTREGS_SIZE
))
113 childregs
= (long *)task_pt_regs(child
);
114 for (i
= 0; i
< sizeof(struct pt_regs
)/sizeof(unsigned long);
116 ret
= __get_user(childregs
[i
], &datap
[i
]);
122 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
123 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
126 case PTRACE_SETOPTIONS
:
127 /* Support TILE-specific ptrace options. */
128 child
->ptrace
&= ~PT_TRACE_MASK_TILE
;
129 tmp
= data
& PTRACE_O_MASK_TILE
;
130 data
&= ~PTRACE_O_MASK_TILE
;
131 ret
= ptrace_request(child
, request
, addr
, data
);
132 if (tmp
& PTRACE_O_TRACEMIGRATE
)
133 child
->ptrace
|= PT_TRACE_MIGRATE
;
138 if (task_thread_info(current
)->status
& TS_COMPAT
) {
139 ret
= compat_ptrace_request(child
, request
,
144 ret
= ptrace_request(child
, request
, addr
, data
);
152 /* Not used; we handle compat issues in arch_ptrace() directly. */
153 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
154 compat_ulong_t addr
, compat_ulong_t data
)
160 void do_syscall_trace(void)
162 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
165 if (!(current
->ptrace
& PT_PTRACED
))
169 * The 0x80 provides a way for the tracing parent to distinguish
170 * between a syscall stop and SIGTRAP delivery
172 ptrace_notify(SIGTRAP
|((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
175 * this isn't the same as continuing with a signal, but it will do
176 * for normal use. strace only continues with a signal if the
177 * stopping signal is not SIGTRAP. -brl
179 if (current
->exit_code
) {
180 send_sig(current
->exit_code
, current
, 1);
181 current
->exit_code
= 0;
185 void send_sigtrap(struct task_struct
*tsk
, struct pt_regs
*regs
, int error_code
)
189 memset(&info
, 0, sizeof(info
));
190 info
.si_signo
= SIGTRAP
;
191 info
.si_code
= TRAP_BRKPT
;
192 info
.si_addr
= (void __user
*) regs
->pc
;
194 /* Send us the fakey SIGTRAP */
195 force_sig_info(SIGTRAP
, &info
, tsk
);
198 /* Handle synthetic interrupt delivered only by the simulator. */
199 void __kprobes
do_breakpoint(struct pt_regs
* regs
, int fault_num
)
201 send_sigtrap(current
, regs
, fault_num
);
This page took 0.037362 seconds and 6 git commands to generate.