1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/mm.h>
23#include <linux/smp.h>
24#include <linux/errno.h>
25#include <linux/ptrace.h>
26#include <linux/regset.h>
27#include <linux/user.h>
28#include <linux/security.h>
29#include <linux/signal.h>
30#include <linux/compat.h>
31
32#include <linux/uaccess.h>
33#include <asm/page.h>
34#include <asm/pgtable.h>
35#include <asm/switch_to.h>
36
37
38
39
40
41
42
43#define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
44#define FPRHALF(i) (((i) - PT_FPR0) & 1)
45#define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
46
47long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
48 compat_ulong_t caddr, compat_ulong_t cdata)
49{
50 unsigned long addr = caddr;
51 unsigned long data = cdata;
52 int ret;
53
54 switch (request) {
55
56
57
58
59
60
61
62
63
64 case PPC_PTRACE_PEEKTEXT_3264:
65 case PPC_PTRACE_PEEKDATA_3264: {
66 u32 tmp;
67 int copied;
68 u32 __user * addrOthers;
69
70 ret = -EIO;
71
72
73 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
74 break;
75
76 copied = ptrace_access_vm(child, (u64)addrOthers, &tmp,
77 sizeof(tmp), FOLL_FORCE);
78 if (copied != sizeof(tmp))
79 break;
80 ret = put_user(tmp, (u32 __user *)data);
81 break;
82 }
83
84
85 case PTRACE_PEEKUSR: {
86 int index;
87 unsigned long tmp;
88
89 ret = -EIO;
90
91 index = (unsigned long) addr >> 2;
92 if ((addr & 3) || (index > PT_FPSCR32))
93 break;
94
95 CHECK_FULL_REGS(child->thread.regs);
96 if (index < PT_FPR0) {
97 ret = ptrace_get_reg(child, index, &tmp);
98 if (ret)
99 break;
100 } else {
101 flush_fp_to_thread(child);
102
103
104
105
106
107 tmp = ((unsigned int *)child->thread.fp_state.fpr)
108 [FPRINDEX(index)];
109 }
110 ret = put_user((unsigned int)tmp, (u32 __user *)data);
111 break;
112 }
113
114
115
116
117
118
119
120
121
122 case PPC_PTRACE_PEEKUSR_3264: {
123 u32 index;
124 u32 reg32bits;
125 u64 tmp;
126 u32 numReg;
127 u32 part;
128
129 ret = -EIO;
130
131 index = (u64)addr >> 2;
132 numReg = index / 2;
133
134 if (index % 2)
135 part = 1;
136 else
137 part = 0;
138
139
140
141
142 if ((addr & 3) || numReg > PT_FPSCR)
143 break;
144
145 CHECK_FULL_REGS(child->thread.regs);
146 if (numReg >= PT_FPR0) {
147 flush_fp_to_thread(child);
148
149 tmp = child->thread.fp_state.fpr[numReg - PT_FPR0][0];
150 } else {
151 unsigned long tmp2;
152 ret = ptrace_get_reg(child, numReg, &tmp2);
153 if (ret)
154 break;
155 tmp = tmp2;
156 }
157 reg32bits = ((u32*)&tmp)[part];
158 ret = put_user(reg32bits, (u32 __user *)data);
159 break;
160 }
161
162
163
164
165
166
167
168
169
170
171 case PPC_PTRACE_POKETEXT_3264:
172 case PPC_PTRACE_POKEDATA_3264: {
173 u32 tmp = data;
174 u32 __user * addrOthers;
175
176
177 ret = -EIO;
178 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
179 break;
180 ret = 0;
181 if (ptrace_access_vm(child, (u64)addrOthers, &tmp,
182 sizeof(tmp),
183 FOLL_FORCE | FOLL_WRITE) == sizeof(tmp))
184 break;
185 ret = -EIO;
186 break;
187 }
188
189
190 case PTRACE_POKEUSR: {
191 unsigned long index;
192
193 ret = -EIO;
194
195 index = (unsigned long) addr >> 2;
196 if ((addr & 3) || (index > PT_FPSCR32))
197 break;
198
199 CHECK_FULL_REGS(child->thread.regs);
200 if (index < PT_FPR0) {
201 ret = ptrace_put_reg(child, index, data);
202 } else {
203 flush_fp_to_thread(child);
204
205
206
207
208
209 ((unsigned int *)child->thread.fp_state.fpr)
210 [FPRINDEX(index)] = data;
211 ret = 0;
212 }
213 break;
214 }
215
216
217
218
219
220
221
222
223 case PPC_PTRACE_POKEUSR_3264: {
224 u32 index;
225 u32 numReg;
226
227 ret = -EIO;
228
229 index = (u64)addr >> 2;
230 numReg = index / 2;
231
232
233
234
235
236 if ((addr & 3) || (numReg > PT_FPSCR))
237 break;
238 CHECK_FULL_REGS(child->thread.regs);
239 if (numReg < PT_FPR0) {
240 unsigned long freg;
241 ret = ptrace_get_reg(child, numReg, &freg);
242 if (ret)
243 break;
244 if (index % 2)
245 freg = (freg & ~0xfffffffful) | (data & 0xfffffffful);
246 else
247 freg = (freg & 0xfffffffful) | (data << 32);
248 ret = ptrace_put_reg(child, numReg, freg);
249 } else {
250 u64 *tmp;
251 flush_fp_to_thread(child);
252
253 tmp = &child->thread.fp_state.fpr[numReg - PT_FPR0][0];
254
255 ((u32 *)tmp)[index % 2] = data;
256 ret = 0;
257 }
258 break;
259 }
260
261 case PTRACE_GET_DEBUGREG: {
262#ifndef CONFIG_PPC_ADV_DEBUG_REGS
263 unsigned long dabr_fake;
264#endif
265 ret = -EINVAL;
266
267 if (addr > 0)
268 break;
269#ifdef CONFIG_PPC_ADV_DEBUG_REGS
270 ret = put_user(child->thread.debug.dac1, (u32 __user *)data);
271#else
272 dabr_fake = (
273 (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
274 (child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
275 ret = put_user(dabr_fake, (u32 __user *)data);
276#endif
277 break;
278 }
279
280 case PTRACE_GETREGS:
281 return copy_regset_to_user(
282 child, task_user_regset_view(current), 0,
283 0, PT_REGS_COUNT * sizeof(compat_long_t),
284 compat_ptr(data));
285
286 case PTRACE_SETREGS:
287 return copy_regset_from_user(
288 child, task_user_regset_view(current), 0,
289 0, PT_REGS_COUNT * sizeof(compat_long_t),
290 compat_ptr(data));
291
292 case PTRACE_GETFPREGS:
293 case PTRACE_SETFPREGS:
294 case PTRACE_GETVRREGS:
295 case PTRACE_SETVRREGS:
296 case PTRACE_GETVSRREGS:
297 case PTRACE_SETVSRREGS:
298 case PTRACE_GETREGS64:
299 case PTRACE_SETREGS64:
300 case PTRACE_KILL:
301 case PTRACE_SINGLESTEP:
302 case PTRACE_DETACH:
303 case PTRACE_SET_DEBUGREG:
304 case PTRACE_SYSCALL:
305 case PTRACE_CONT:
306 case PPC_PTRACE_GETHWDBGINFO:
307 case PPC_PTRACE_SETHWDEBUG:
308 case PPC_PTRACE_DELHWDEBUG:
309 ret = arch_ptrace(child, request, addr, data);
310 break;
311
312 default:
313 ret = compat_ptrace_request(child, request, addr, data);
314 break;
315 }
316
317 return ret;
318}
319