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