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);
49 * Get registers from task and ready the result for userspace.
50 * Note that we localize the API issues to getregs() and putregs() at
51 * some cost in performance, e.g. we need a full pt_regs copy for
52 * PEEKUSR, and two copies for POKEUSR. But in general we expect
53 * GETREGS/PUTREGS to be the API of choice anyway.
55 static char *getregs(struct task_struct *child, struct pt_regs *uregs)
57 *uregs = *task_pt_regs(child);
59 /* Set up flags ABI bits. */
62 if (task_thread_info(child)->status & TS_COMPAT)
63 uregs->flags |= PT_FLAGS_COMPAT;
69 /* Put registers back to task. */
70 static void putregs(struct task_struct *child, struct pt_regs *uregs)
72 struct pt_regs *regs = task_pt_regs(child);
74 /* Don't allow overwriting the kernel-internal flags word. */
75 uregs->flags = regs->flags;
77 /* Only allow setting the ICS bit in the ex1 word. */
78 uregs->ex1 = PL_ICS_EX1(USER_PL, EX1_ICS(uregs->ex1));
83 long arch_ptrace(struct task_struct *child, long request,
84 unsigned long addr, unsigned long data)
86 unsigned long __user *datap = (long __user __force *)data;
90 struct pt_regs copyregs;
94 case PTRACE_PEEKUSR: /* Read register from pt_regs. */
95 if (addr >= PTREGS_SIZE)
97 childreg = getregs(child, ©regs) + addr;
99 if (is_compat_task()) {
100 if (addr & (sizeof(compat_long_t)-1))
102 ret = put_user(*(compat_long_t *)childreg,
103 (compat_long_t __user *)datap);
107 if (addr & (sizeof(long)-1))
109 ret = put_user(*(long *)childreg, datap);
113 case PTRACE_POKEUSR: /* Write register in pt_regs. */
114 if (addr >= PTREGS_SIZE)
116 childreg = getregs(child, ©regs) + addr;
118 if (is_compat_task()) {
119 if (addr & (sizeof(compat_long_t)-1))
121 *(compat_long_t *)childreg = data;
125 if (addr & (sizeof(long)-1))
127 *(long *)childreg = data;
129 putregs(child, ©regs);
133 case PTRACE_GETREGS: /* Get all registers from the child. */
134 if (copy_to_user(datap, getregs(child, ©regs),
135 sizeof(struct pt_regs)) == 0) {
140 case PTRACE_SETREGS: /* Set all registers in the child. */
141 if (copy_from_user(©regs, datap,
142 sizeof(struct pt_regs)) == 0) {
143 putregs(child, ©regs);
148 case PTRACE_GETFPREGS: /* Get the child FPU state. */
149 case PTRACE_SETFPREGS: /* Set the child FPU state. */
152 case PTRACE_SETOPTIONS:
153 /* Support TILE-specific ptrace options. */
154 child->ptrace &= ~PT_TRACE_MASK_TILE;
155 tmp = data & PTRACE_O_MASK_TILE;
156 data &= ~PTRACE_O_MASK_TILE;
157 ret = ptrace_request(child, request, addr, data);
158 if (tmp & PTRACE_O_TRACEMIGRATE)
159 child->ptrace |= PT_TRACE_MIGRATE;
164 if (task_thread_info(current)->status & TS_COMPAT) {
165 ret = compat_ptrace_request(child, request,
170 ret = ptrace_request(child, request, addr, data);
178 /* Not used; we handle compat issues in arch_ptrace() directly. */
179 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
180 compat_ulong_t addr, compat_ulong_t data)
186 void do_syscall_trace(void)
188 if (!test_thread_flag(TIF_SYSCALL_TRACE))
191 if (!(current->ptrace & PT_PTRACED))
195 * The 0x80 provides a way for the tracing parent to distinguish
196 * between a syscall stop and SIGTRAP delivery
198 ptrace_notify(SIGTRAP|((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
201 * this isn't the same as continuing with a signal, but it will do
202 * for normal use. strace only continues with a signal if the
203 * stopping signal is not SIGTRAP. -brl
205 if (current->exit_code) {
206 send_sig(current->exit_code, current, 1);
207 current->exit_code = 0;
211 void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
215 memset(&info, 0, sizeof(info));
216 info.si_signo = SIGTRAP;
217 info.si_code = TRAP_BRKPT;
218 info.si_addr = (void __user *) regs->pc;
220 /* Send us the fakey SIGTRAP */
221 force_sig_info(SIGTRAP, &info, tsk);
224 /* Handle synthetic interrupt delivered only by the simulator. */
225 void __kprobes do_breakpoint(struct pt_regs* regs, int fault_num)
227 send_sigtrap(current, regs, fault_num);