Commit | Line | Data |
---|---|---|
867e359b CM |
1 | /* |
2 | * Copyright 2010 Tilera Corporation. All Rights Reserved. | |
3 | * | |
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. | |
7 | * | |
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 | |
12 | * more details. | |
13 | * | |
14 | * Copied from i386: Ross Biro 1/23/92 | |
15 | */ | |
16 | ||
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> | |
0707ad30 | 22 | #include <asm/traps.h> |
867e359b CM |
23 | |
24 | void user_enable_single_step(struct task_struct *child) | |
25 | { | |
26 | set_tsk_thread_flag(child, TIF_SINGLESTEP); | |
27 | } | |
28 | ||
29 | void user_disable_single_step(struct task_struct *child) | |
30 | { | |
31 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | |
32 | } | |
33 | ||
867e359b CM |
34 | /* |
35 | * Called by kernel/ptrace.c when detaching.. | |
36 | */ | |
37 | void ptrace_disable(struct task_struct *child) | |
38 | { | |
39 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | |
40 | ||
41 | /* | |
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. | |
44 | */ | |
45 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
46 | } | |
47 | ||
9b05a69e NK |
48 | long arch_ptrace(struct task_struct *child, long request, |
49 | unsigned long addr, unsigned long data) | |
867e359b | 50 | { |
ce7f2a39 | 51 | unsigned long __user *datap = (long __user __force *)data; |
867e359b CM |
52 | unsigned long tmp; |
53 | int i; | |
54 | long ret = -EIO; | |
ce7f2a39 CM |
55 | unsigned long *childregs; |
56 | char *childreg; | |
867e359b CM |
57 | |
58 | switch (request) { | |
59 | ||
60 | case PTRACE_PEEKUSR: /* Read register from pt_regs. */ | |
867e359b CM |
61 | if (addr < 0 || addr >= PTREGS_SIZE) |
62 | break; | |
ce7f2a39 CM |
63 | childreg = (char *)task_pt_regs(child) + addr; |
64 | #ifdef CONFIG_COMPAT | |
65 | if (is_compat_task()) { | |
66 | if (addr & (sizeof(compat_long_t)-1)) | |
67 | break; | |
68 | ret = put_user(*(compat_long_t *)childreg, | |
69 | (compat_long_t __user *)datap); | |
70 | } else | |
71 | #endif | |
72 | { | |
73 | if (addr & (sizeof(long)-1)) | |
74 | break; | |
75 | ret = put_user(*(long *)childreg, datap); | |
76 | } | |
867e359b CM |
77 | break; |
78 | ||
79 | case PTRACE_POKEUSR: /* Write register in pt_regs. */ | |
867e359b CM |
80 | if (addr < 0 || addr >= PTREGS_SIZE) |
81 | break; | |
ce7f2a39 CM |
82 | childreg = (char *)task_pt_regs(child) + addr; |
83 | #ifdef CONFIG_COMPAT | |
84 | if (is_compat_task()) { | |
85 | if (addr & (sizeof(compat_long_t)-1)) | |
86 | break; | |
87 | *(compat_long_t *)childreg = data; | |
88 | } else | |
89 | #endif | |
90 | { | |
91 | if (addr & (sizeof(long)-1)) | |
92 | break; | |
93 | *(long *)childreg = data; | |
94 | } | |
bcd97c3f | 95 | ret = 0; |
867e359b CM |
96 | break; |
97 | ||
98 | case PTRACE_GETREGS: /* Get all registers from the child. */ | |
99 | if (!access_ok(VERIFY_WRITE, datap, PTREGS_SIZE)) | |
100 | break; | |
ce7f2a39 | 101 | childregs = (long *)task_pt_regs(child); |
9b05a69e NK |
102 | for (i = 0; i < sizeof(struct pt_regs)/sizeof(unsigned long); |
103 | ++i) { | |
ce7f2a39 | 104 | ret = __put_user(childregs[i], &datap[i]); |
867e359b CM |
105 | if (ret != 0) |
106 | break; | |
867e359b CM |
107 | } |
108 | break; | |
109 | ||
110 | case PTRACE_SETREGS: /* Set all registers in the child. */ | |
111 | if (!access_ok(VERIFY_READ, datap, PTREGS_SIZE)) | |
112 | break; | |
ce7f2a39 | 113 | childregs = (long *)task_pt_regs(child); |
9b05a69e NK |
114 | for (i = 0; i < sizeof(struct pt_regs)/sizeof(unsigned long); |
115 | ++i) { | |
ce7f2a39 | 116 | ret = __get_user(childregs[i], &datap[i]); |
867e359b CM |
117 | if (ret != 0) |
118 | break; | |
867e359b CM |
119 | } |
120 | break; | |
121 | ||
122 | case PTRACE_GETFPREGS: /* Get the child FPU state. */ | |
123 | case PTRACE_SETFPREGS: /* Set the child FPU state. */ | |
124 | break; | |
125 | ||
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; | |
134 | break; | |
135 | ||
136 | default: | |
137 | #ifdef CONFIG_COMPAT | |
138 | if (task_thread_info(current)->status & TS_COMPAT) { | |
139 | ret = compat_ptrace_request(child, request, | |
140 | addr, data); | |
141 | break; | |
142 | } | |
143 | #endif | |
144 | ret = ptrace_request(child, request, addr, data); | |
145 | break; | |
146 | } | |
147 | ||
148 | return ret; | |
149 | } | |
150 | ||
151 | #ifdef CONFIG_COMPAT | |
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) | |
155 | { | |
156 | BUG(); | |
157 | } | |
158 | #endif | |
159 | ||
160 | void do_syscall_trace(void) | |
161 | { | |
162 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) | |
163 | return; | |
164 | ||
165 | if (!(current->ptrace & PT_PTRACED)) | |
166 | return; | |
167 | ||
168 | /* | |
169 | * The 0x80 provides a way for the tracing parent to distinguish | |
170 | * between a syscall stop and SIGTRAP delivery | |
171 | */ | |
172 | ptrace_notify(SIGTRAP|((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0)); | |
173 | ||
174 | /* | |
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 | |
178 | */ | |
179 | if (current->exit_code) { | |
180 | send_sig(current->exit_code, current, 1); | |
181 | current->exit_code = 0; | |
182 | } | |
183 | } | |
184 | ||
185 | void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) | |
186 | { | |
187 | struct siginfo info; | |
188 | ||
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; | |
193 | ||
194 | /* Send us the fakey SIGTRAP */ | |
195 | force_sig_info(SIGTRAP, &info, tsk); | |
196 | } | |
197 | ||
198 | /* Handle synthetic interrupt delivered only by the simulator. */ | |
199 | void __kprobes do_breakpoint(struct pt_regs* regs, int fault_num) | |
200 | { | |
201 | send_sigtrap(current, regs, fault_num); | |
202 | } |