Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | |
3 | * License. See the file "COPYING" in the main directory of this archive | |
4 | * for more details. | |
5 | * | |
6 | * Copyright (C) 1992 Ross Biro | |
7 | * Copyright (C) Linus Torvalds | |
8 | * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle | |
9 | * Copyright (C) 1996 David S. Miller | |
10 | * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com | |
11 | * Copyright (C) 1999 MIPS Technologies, Inc. | |
12 | * Copyright (C) 2000 Ulf Carlsson | |
13 | * | |
14 | * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit | |
15 | * binaries. | |
16 | */ | |
1da177e4 | 17 | #include <linux/compiler.h> |
c3fc5cd5 | 18 | #include <linux/context_tracking.h> |
7aeb753b | 19 | #include <linux/elf.h> |
1da177e4 LT |
20 | #include <linux/kernel.h> |
21 | #include <linux/sched.h> | |
22 | #include <linux/mm.h> | |
23 | #include <linux/errno.h> | |
24 | #include <linux/ptrace.h> | |
7aeb753b | 25 | #include <linux/regset.h> |
1da177e4 | 26 | #include <linux/smp.h> |
1da177e4 LT |
27 | #include <linux/user.h> |
28 | #include <linux/security.h> | |
bc3d22c1 | 29 | #include <linux/tracehook.h> |
293c5bd1 RB |
30 | #include <linux/audit.h> |
31 | #include <linux/seccomp.h> | |
1d7bf993 | 32 | #include <linux/ftrace.h> |
1da177e4 | 33 | |
f8280c8d | 34 | #include <asm/byteorder.h> |
1da177e4 | 35 | #include <asm/cpu.h> |
e50c0a8f | 36 | #include <asm/dsp.h> |
1da177e4 LT |
37 | #include <asm/fpu.h> |
38 | #include <asm/mipsregs.h> | |
101b3531 | 39 | #include <asm/mipsmtregs.h> |
1da177e4 LT |
40 | #include <asm/pgtable.h> |
41 | #include <asm/page.h> | |
bec9b2b2 | 42 | #include <asm/syscall.h> |
1da177e4 LT |
43 | #include <asm/uaccess.h> |
44 | #include <asm/bootinfo.h> | |
ea3d710f | 45 | #include <asm/reg.h> |
1da177e4 | 46 | |
1d7bf993 RB |
47 | #define CREATE_TRACE_POINTS |
48 | #include <trace/events/syscalls.h> | |
49 | ||
1da177e4 LT |
50 | /* |
51 | * Called by kernel/ptrace.c when detaching.. | |
52 | * | |
53 | * Make sure single step bits etc are not set. | |
54 | */ | |
55 | void ptrace_disable(struct task_struct *child) | |
56 | { | |
0926bf95 DD |
57 | /* Don't load the watchpoint registers for the ex-child. */ |
58 | clear_tsk_thread_flag(child, TIF_LOAD_WATCH); | |
1da177e4 LT |
59 | } |
60 | ||
ea3d710f | 61 | /* |
70342287 | 62 | * Read a general register set. We always use the 64-bit format, even |
ea3d710f DJ |
63 | * for 32-bit kernels and for 32-bit processes on a 64-bit kernel. |
64 | * Registers are sign extended to fill the available space. | |
65 | */ | |
49a89efb | 66 | int ptrace_getregs(struct task_struct *child, __s64 __user *data) |
ea3d710f DJ |
67 | { |
68 | struct pt_regs *regs; | |
69 | int i; | |
70 | ||
71 | if (!access_ok(VERIFY_WRITE, data, 38 * 8)) | |
72 | return -EIO; | |
73 | ||
40bc9c67 | 74 | regs = task_pt_regs(child); |
ea3d710f DJ |
75 | |
76 | for (i = 0; i < 32; i++) | |
62b14c24 AN |
77 | __put_user((long)regs->regs[i], data + i); |
78 | __put_user((long)regs->lo, data + EF_LO - EF_R0); | |
79 | __put_user((long)regs->hi, data + EF_HI - EF_R0); | |
80 | __put_user((long)regs->cp0_epc, data + EF_CP0_EPC - EF_R0); | |
81 | __put_user((long)regs->cp0_badvaddr, data + EF_CP0_BADVADDR - EF_R0); | |
82 | __put_user((long)regs->cp0_status, data + EF_CP0_STATUS - EF_R0); | |
83 | __put_user((long)regs->cp0_cause, data + EF_CP0_CAUSE - EF_R0); | |
ea3d710f DJ |
84 | |
85 | return 0; | |
86 | } | |
87 | ||
88 | /* | |
89 | * Write a general register set. As for PTRACE_GETREGS, we always use | |
90 | * the 64-bit format. On a 32-bit kernel only the lower order half | |
91 | * (according to endianness) will be used. | |
92 | */ | |
49a89efb | 93 | int ptrace_setregs(struct task_struct *child, __s64 __user *data) |
ea3d710f DJ |
94 | { |
95 | struct pt_regs *regs; | |
96 | int i; | |
97 | ||
98 | if (!access_ok(VERIFY_READ, data, 38 * 8)) | |
99 | return -EIO; | |
100 | ||
40bc9c67 | 101 | regs = task_pt_regs(child); |
ea3d710f DJ |
102 | |
103 | for (i = 0; i < 32; i++) | |
49a89efb RB |
104 | __get_user(regs->regs[i], data + i); |
105 | __get_user(regs->lo, data + EF_LO - EF_R0); | |
106 | __get_user(regs->hi, data + EF_HI - EF_R0); | |
107 | __get_user(regs->cp0_epc, data + EF_CP0_EPC - EF_R0); | |
ea3d710f DJ |
108 | |
109 | /* badvaddr, status, and cause may not be written. */ | |
110 | ||
111 | return 0; | |
112 | } | |
113 | ||
49a89efb | 114 | int ptrace_getfpregs(struct task_struct *child, __u32 __user *data) |
ea3d710f DJ |
115 | { |
116 | int i; | |
e04582b7 | 117 | unsigned int tmp; |
ea3d710f DJ |
118 | |
119 | if (!access_ok(VERIFY_WRITE, data, 33 * 8)) | |
120 | return -EIO; | |
121 | ||
122 | if (tsk_used_math(child)) { | |
123 | fpureg_t *fregs = get_fpu_regs(child); | |
124 | for (i = 0; i < 32; i++) | |
49a89efb | 125 | __put_user(fregs[i], i + (__u64 __user *) data); |
ea3d710f DJ |
126 | } else { |
127 | for (i = 0; i < 32; i++) | |
49a89efb | 128 | __put_user((__u64) -1, i + (__u64 __user *) data); |
ea3d710f DJ |
129 | } |
130 | ||
49a89efb | 131 | __put_user(child->thread.fpu.fcr31, data + 64); |
eae89076 | 132 | |
e04582b7 | 133 | preempt_disable(); |
ea3d710f | 134 | if (cpu_has_fpu) { |
e04582b7 | 135 | unsigned int flags; |
ea3d710f | 136 | |
101b3531 RB |
137 | if (cpu_has_mipsmt) { |
138 | unsigned int vpflags = dvpe(); | |
139 | flags = read_c0_status(); | |
140 | __enable_fpu(); | |
141 | __asm__ __volatile__("cfc1\t%0,$0" : "=r" (tmp)); | |
142 | write_c0_status(flags); | |
143 | evpe(vpflags); | |
144 | } else { | |
145 | flags = read_c0_status(); | |
146 | __enable_fpu(); | |
147 | __asm__ __volatile__("cfc1\t%0,$0" : "=r" (tmp)); | |
148 | write_c0_status(flags); | |
149 | } | |
ea3d710f | 150 | } else { |
e04582b7 | 151 | tmp = 0; |
ea3d710f | 152 | } |
e04582b7 | 153 | preempt_enable(); |
49a89efb | 154 | __put_user(tmp, data + 65); |
ea3d710f DJ |
155 | |
156 | return 0; | |
157 | } | |
158 | ||
49a89efb | 159 | int ptrace_setfpregs(struct task_struct *child, __u32 __user *data) |
ea3d710f DJ |
160 | { |
161 | fpureg_t *fregs; | |
162 | int i; | |
163 | ||
164 | if (!access_ok(VERIFY_READ, data, 33 * 8)) | |
165 | return -EIO; | |
166 | ||
167 | fregs = get_fpu_regs(child); | |
168 | ||
169 | for (i = 0; i < 32; i++) | |
49a89efb | 170 | __get_user(fregs[i], i + (__u64 __user *) data); |
ea3d710f | 171 | |
49a89efb | 172 | __get_user(child->thread.fpu.fcr31, data + 64); |
ea3d710f DJ |
173 | |
174 | /* FIR may not be written. */ | |
175 | ||
176 | return 0; | |
177 | } | |
178 | ||
0926bf95 DD |
179 | int ptrace_get_watch_regs(struct task_struct *child, |
180 | struct pt_watch_regs __user *addr) | |
181 | { | |
182 | enum pt_watch_style style; | |
183 | int i; | |
184 | ||
185 | if (!cpu_has_watch || current_cpu_data.watch_reg_use_cnt == 0) | |
186 | return -EIO; | |
187 | if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs))) | |
188 | return -EIO; | |
189 | ||
190 | #ifdef CONFIG_32BIT | |
191 | style = pt_watch_style_mips32; | |
192 | #define WATCH_STYLE mips32 | |
193 | #else | |
194 | style = pt_watch_style_mips64; | |
195 | #define WATCH_STYLE mips64 | |
196 | #endif | |
197 | ||
198 | __put_user(style, &addr->style); | |
199 | __put_user(current_cpu_data.watch_reg_use_cnt, | |
200 | &addr->WATCH_STYLE.num_valid); | |
201 | for (i = 0; i < current_cpu_data.watch_reg_use_cnt; i++) { | |
202 | __put_user(child->thread.watch.mips3264.watchlo[i], | |
203 | &addr->WATCH_STYLE.watchlo[i]); | |
204 | __put_user(child->thread.watch.mips3264.watchhi[i] & 0xfff, | |
205 | &addr->WATCH_STYLE.watchhi[i]); | |
206 | __put_user(current_cpu_data.watch_reg_masks[i], | |
207 | &addr->WATCH_STYLE.watch_masks[i]); | |
208 | } | |
209 | for (; i < 8; i++) { | |
210 | __put_user(0, &addr->WATCH_STYLE.watchlo[i]); | |
211 | __put_user(0, &addr->WATCH_STYLE.watchhi[i]); | |
212 | __put_user(0, &addr->WATCH_STYLE.watch_masks[i]); | |
213 | } | |
214 | ||
215 | return 0; | |
216 | } | |
217 | ||
218 | int ptrace_set_watch_regs(struct task_struct *child, | |
219 | struct pt_watch_regs __user *addr) | |
220 | { | |
221 | int i; | |
222 | int watch_active = 0; | |
223 | unsigned long lt[NUM_WATCH_REGS]; | |
224 | u16 ht[NUM_WATCH_REGS]; | |
225 | ||
226 | if (!cpu_has_watch || current_cpu_data.watch_reg_use_cnt == 0) | |
227 | return -EIO; | |
228 | if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs))) | |
229 | return -EIO; | |
230 | /* Check the values. */ | |
231 | for (i = 0; i < current_cpu_data.watch_reg_use_cnt; i++) { | |
232 | __get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]); | |
233 | #ifdef CONFIG_32BIT | |
234 | if (lt[i] & __UA_LIMIT) | |
235 | return -EINVAL; | |
236 | #else | |
237 | if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) { | |
238 | if (lt[i] & 0xffffffff80000000UL) | |
239 | return -EINVAL; | |
240 | } else { | |
241 | if (lt[i] & __UA_LIMIT) | |
242 | return -EINVAL; | |
243 | } | |
244 | #endif | |
245 | __get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]); | |
246 | if (ht[i] & ~0xff8) | |
247 | return -EINVAL; | |
248 | } | |
249 | /* Install them. */ | |
250 | for (i = 0; i < current_cpu_data.watch_reg_use_cnt; i++) { | |
251 | if (lt[i] & 7) | |
252 | watch_active = 1; | |
253 | child->thread.watch.mips3264.watchlo[i] = lt[i]; | |
254 | /* Set the G bit. */ | |
255 | child->thread.watch.mips3264.watchhi[i] = ht[i]; | |
256 | } | |
257 | ||
258 | if (watch_active) | |
259 | set_tsk_thread_flag(child, TIF_LOAD_WATCH); | |
260 | else | |
261 | clear_tsk_thread_flag(child, TIF_LOAD_WATCH); | |
262 | ||
263 | return 0; | |
264 | } | |
265 | ||
7aeb753b RB |
266 | /* regset get/set implementations */ |
267 | ||
268 | static int gpr_get(struct task_struct *target, | |
269 | const struct user_regset *regset, | |
270 | unsigned int pos, unsigned int count, | |
271 | void *kbuf, void __user *ubuf) | |
272 | { | |
273 | struct pt_regs *regs = task_pt_regs(target); | |
274 | ||
275 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
276 | regs, 0, sizeof(*regs)); | |
277 | } | |
278 | ||
279 | static int gpr_set(struct task_struct *target, | |
280 | const struct user_regset *regset, | |
281 | unsigned int pos, unsigned int count, | |
282 | const void *kbuf, const void __user *ubuf) | |
283 | { | |
284 | struct pt_regs newregs; | |
285 | int ret; | |
286 | ||
287 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
288 | &newregs, | |
289 | 0, sizeof(newregs)); | |
290 | if (ret) | |
291 | return ret; | |
292 | ||
293 | *task_pt_regs(target) = newregs; | |
294 | ||
295 | return 0; | |
296 | } | |
297 | ||
298 | static int fpr_get(struct task_struct *target, | |
299 | const struct user_regset *regset, | |
300 | unsigned int pos, unsigned int count, | |
301 | void *kbuf, void __user *ubuf) | |
302 | { | |
303 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
304 | &target->thread.fpu, | |
305 | 0, sizeof(elf_fpregset_t)); | |
306 | /* XXX fcr31 */ | |
307 | } | |
308 | ||
309 | static int fpr_set(struct task_struct *target, | |
310 | const struct user_regset *regset, | |
311 | unsigned int pos, unsigned int count, | |
312 | const void *kbuf, const void __user *ubuf) | |
313 | { | |
314 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
315 | &target->thread.fpu, | |
316 | 0, sizeof(elf_fpregset_t)); | |
317 | /* XXX fcr31 */ | |
318 | } | |
319 | ||
320 | enum mips_regset { | |
321 | REGSET_GPR, | |
322 | REGSET_FPR, | |
323 | }; | |
324 | ||
325 | static const struct user_regset mips_regsets[] = { | |
326 | [REGSET_GPR] = { | |
327 | .core_note_type = NT_PRSTATUS, | |
328 | .n = ELF_NGREG, | |
329 | .size = sizeof(unsigned int), | |
330 | .align = sizeof(unsigned int), | |
331 | .get = gpr_get, | |
332 | .set = gpr_set, | |
333 | }, | |
334 | [REGSET_FPR] = { | |
335 | .core_note_type = NT_PRFPREG, | |
336 | .n = ELF_NFPREG, | |
337 | .size = sizeof(elf_fpreg_t), | |
338 | .align = sizeof(elf_fpreg_t), | |
339 | .get = fpr_get, | |
340 | .set = fpr_set, | |
341 | }, | |
342 | }; | |
343 | ||
344 | static const struct user_regset_view user_mips_view = { | |
345 | .name = "mips", | |
346 | .e_machine = ELF_ARCH, | |
347 | .ei_osabi = ELF_OSABI, | |
348 | .regsets = mips_regsets, | |
349 | .n = ARRAY_SIZE(mips_regsets), | |
350 | }; | |
351 | ||
352 | static const struct user_regset mips64_regsets[] = { | |
353 | [REGSET_GPR] = { | |
354 | .core_note_type = NT_PRSTATUS, | |
355 | .n = ELF_NGREG, | |
356 | .size = sizeof(unsigned long), | |
357 | .align = sizeof(unsigned long), | |
358 | .get = gpr_get, | |
359 | .set = gpr_set, | |
360 | }, | |
361 | [REGSET_FPR] = { | |
362 | .core_note_type = NT_PRFPREG, | |
363 | .n = ELF_NFPREG, | |
364 | .size = sizeof(elf_fpreg_t), | |
365 | .align = sizeof(elf_fpreg_t), | |
366 | .get = fpr_get, | |
367 | .set = fpr_set, | |
368 | }, | |
369 | }; | |
370 | ||
371 | static const struct user_regset_view user_mips64_view = { | |
372 | .name = "mips", | |
373 | .e_machine = ELF_ARCH, | |
374 | .ei_osabi = ELF_OSABI, | |
375 | .regsets = mips64_regsets, | |
376 | .n = ARRAY_SIZE(mips_regsets), | |
377 | }; | |
378 | ||
379 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) | |
380 | { | |
381 | #ifdef CONFIG_32BIT | |
382 | return &user_mips_view; | |
383 | #endif | |
384 | ||
385 | #ifdef CONFIG_MIPS32_O32 | |
386 | if (test_thread_flag(TIF_32BIT_REGS)) | |
387 | return &user_mips_view; | |
388 | #endif | |
389 | ||
390 | return &user_mips64_view; | |
391 | } | |
392 | ||
9b05a69e NK |
393 | long arch_ptrace(struct task_struct *child, long request, |
394 | unsigned long addr, unsigned long data) | |
1da177e4 | 395 | { |
1da177e4 | 396 | int ret; |
fb671139 NK |
397 | void __user *addrp = (void __user *) addr; |
398 | void __user *datavp = (void __user *) data; | |
399 | unsigned long __user *datalp = (void __user *) data; | |
1da177e4 | 400 | |
1da177e4 LT |
401 | switch (request) { |
402 | /* when I and D space are separate, these will need to be fixed. */ | |
403 | case PTRACE_PEEKTEXT: /* read word at location addr. */ | |
76647323 AD |
404 | case PTRACE_PEEKDATA: |
405 | ret = generic_ptrace_peekdata(child, addr, data); | |
1da177e4 | 406 | break; |
1da177e4 LT |
407 | |
408 | /* Read the word at location addr in the USER area. */ | |
409 | case PTRACE_PEEKUSR: { | |
410 | struct pt_regs *regs; | |
411 | unsigned long tmp = 0; | |
412 | ||
40bc9c67 | 413 | regs = task_pt_regs(child); |
1da177e4 LT |
414 | ret = 0; /* Default return value. */ |
415 | ||
416 | switch (addr) { | |
417 | case 0 ... 31: | |
418 | tmp = regs->regs[addr]; | |
419 | break; | |
420 | case FPR_BASE ... FPR_BASE + 31: | |
421 | if (tsk_used_math(child)) { | |
422 | fpureg_t *fregs = get_fpu_regs(child); | |
423 | ||
875d43e7 | 424 | #ifdef CONFIG_32BIT |
1da177e4 LT |
425 | /* |
426 | * The odd registers are actually the high | |
427 | * order bits of the values stored in the even | |
428 | * registers - unless we're using r2k_switch.S. | |
429 | */ | |
430 | if (addr & 1) | |
431 | tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32); | |
432 | else | |
433 | tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff); | |
434 | #endif | |
875d43e7 | 435 | #ifdef CONFIG_64BIT |
1da177e4 LT |
436 | tmp = fregs[addr - FPR_BASE]; |
437 | #endif | |
438 | } else { | |
439 | tmp = -1; /* FP not yet used */ | |
440 | } | |
441 | break; | |
442 | case PC: | |
443 | tmp = regs->cp0_epc; | |
444 | break; | |
445 | case CAUSE: | |
446 | tmp = regs->cp0_cause; | |
447 | break; | |
448 | case BADVADDR: | |
449 | tmp = regs->cp0_badvaddr; | |
450 | break; | |
451 | case MMHI: | |
452 | tmp = regs->hi; | |
453 | break; | |
454 | case MMLO: | |
455 | tmp = regs->lo; | |
456 | break; | |
9693a853 FBH |
457 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
458 | case ACX: | |
459 | tmp = regs->acx; | |
460 | break; | |
461 | #endif | |
1da177e4 | 462 | case FPC_CSR: |
eae89076 | 463 | tmp = child->thread.fpu.fcr31; |
1da177e4 | 464 | break; |
70342287 | 465 | case FPC_EIR: { /* implementation / version register */ |
1da177e4 | 466 | unsigned int flags; |
41c594ab | 467 | #ifdef CONFIG_MIPS_MT_SMTC |
b7e4226e | 468 | unsigned long irqflags; |
41c594ab RB |
469 | unsigned int mtflags; |
470 | #endif /* CONFIG_MIPS_MT_SMTC */ | |
1da177e4 | 471 | |
e04582b7 AN |
472 | preempt_disable(); |
473 | if (!cpu_has_fpu) { | |
474 | preempt_enable(); | |
1da177e4 | 475 | break; |
e04582b7 | 476 | } |
1da177e4 | 477 | |
41c594ab RB |
478 | #ifdef CONFIG_MIPS_MT_SMTC |
479 | /* Read-modify-write of Status must be atomic */ | |
480 | local_irq_save(irqflags); | |
481 | mtflags = dmt(); | |
482 | #endif /* CONFIG_MIPS_MT_SMTC */ | |
101b3531 RB |
483 | if (cpu_has_mipsmt) { |
484 | unsigned int vpflags = dvpe(); | |
485 | flags = read_c0_status(); | |
486 | __enable_fpu(); | |
487 | __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp)); | |
488 | write_c0_status(flags); | |
489 | evpe(vpflags); | |
490 | } else { | |
491 | flags = read_c0_status(); | |
492 | __enable_fpu(); | |
493 | __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp)); | |
494 | write_c0_status(flags); | |
495 | } | |
41c594ab RB |
496 | #ifdef CONFIG_MIPS_MT_SMTC |
497 | emt(mtflags); | |
498 | local_irq_restore(irqflags); | |
499 | #endif /* CONFIG_MIPS_MT_SMTC */ | |
101b3531 | 500 | preempt_enable(); |
1da177e4 LT |
501 | break; |
502 | } | |
c134a5ec RB |
503 | case DSP_BASE ... DSP_BASE + 5: { |
504 | dspreg_t *dregs; | |
505 | ||
e50c0a8f RB |
506 | if (!cpu_has_dsp) { |
507 | tmp = 0; | |
508 | ret = -EIO; | |
481bed45 | 509 | goto out; |
e50c0a8f | 510 | } |
6c355852 RB |
511 | dregs = __get_dsp_regs(child); |
512 | tmp = (unsigned long) (dregs[addr - DSP_BASE]); | |
e50c0a8f | 513 | break; |
c134a5ec | 514 | } |
e50c0a8f RB |
515 | case DSP_CONTROL: |
516 | if (!cpu_has_dsp) { | |
517 | tmp = 0; | |
518 | ret = -EIO; | |
481bed45 | 519 | goto out; |
e50c0a8f RB |
520 | } |
521 | tmp = child->thread.dsp.dspcontrol; | |
522 | break; | |
1da177e4 LT |
523 | default: |
524 | tmp = 0; | |
525 | ret = -EIO; | |
481bed45 | 526 | goto out; |
1da177e4 | 527 | } |
fb671139 | 528 | ret = put_user(tmp, datalp); |
1da177e4 LT |
529 | break; |
530 | } | |
531 | ||
532 | /* when I and D space are separate, this will have to be fixed. */ | |
533 | case PTRACE_POKETEXT: /* write the word at location addr. */ | |
534 | case PTRACE_POKEDATA: | |
f284ce72 | 535 | ret = generic_ptrace_pokedata(child, addr, data); |
1da177e4 LT |
536 | break; |
537 | ||
538 | case PTRACE_POKEUSR: { | |
539 | struct pt_regs *regs; | |
540 | ret = 0; | |
40bc9c67 | 541 | regs = task_pt_regs(child); |
1da177e4 LT |
542 | |
543 | switch (addr) { | |
544 | case 0 ... 31: | |
545 | regs->regs[addr] = data; | |
546 | break; | |
547 | case FPR_BASE ... FPR_BASE + 31: { | |
548 | fpureg_t *fregs = get_fpu_regs(child); | |
549 | ||
550 | if (!tsk_used_math(child)) { | |
551 | /* FP not yet used */ | |
eae89076 AN |
552 | memset(&child->thread.fpu, ~0, |
553 | sizeof(child->thread.fpu)); | |
554 | child->thread.fpu.fcr31 = 0; | |
1da177e4 | 555 | } |
875d43e7 | 556 | #ifdef CONFIG_32BIT |
1da177e4 LT |
557 | /* |
558 | * The odd registers are actually the high order bits | |
559 | * of the values stored in the even registers - unless | |
560 | * we're using r2k_switch.S. | |
561 | */ | |
562 | if (addr & 1) { | |
563 | fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff; | |
564 | fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32; | |
565 | } else { | |
566 | fregs[addr - FPR_BASE] &= ~0xffffffffLL; | |
567 | fregs[addr - FPR_BASE] |= data; | |
568 | } | |
569 | #endif | |
875d43e7 | 570 | #ifdef CONFIG_64BIT |
1da177e4 LT |
571 | fregs[addr - FPR_BASE] = data; |
572 | #endif | |
573 | break; | |
574 | } | |
575 | case PC: | |
576 | regs->cp0_epc = data; | |
577 | break; | |
578 | case MMHI: | |
579 | regs->hi = data; | |
580 | break; | |
581 | case MMLO: | |
582 | regs->lo = data; | |
583 | break; | |
9693a853 FBH |
584 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
585 | case ACX: | |
586 | regs->acx = data; | |
587 | break; | |
588 | #endif | |
1da177e4 | 589 | case FPC_CSR: |
eae89076 | 590 | child->thread.fpu.fcr31 = data; |
1da177e4 | 591 | break; |
c134a5ec RB |
592 | case DSP_BASE ... DSP_BASE + 5: { |
593 | dspreg_t *dregs; | |
594 | ||
e50c0a8f RB |
595 | if (!cpu_has_dsp) { |
596 | ret = -EIO; | |
597 | break; | |
598 | } | |
599 | ||
c134a5ec | 600 | dregs = __get_dsp_regs(child); |
e50c0a8f RB |
601 | dregs[addr - DSP_BASE] = data; |
602 | break; | |
c134a5ec | 603 | } |
e50c0a8f RB |
604 | case DSP_CONTROL: |
605 | if (!cpu_has_dsp) { | |
606 | ret = -EIO; | |
607 | break; | |
608 | } | |
609 | child->thread.dsp.dspcontrol = data; | |
610 | break; | |
1da177e4 LT |
611 | default: |
612 | /* The rest are not allowed. */ | |
613 | ret = -EIO; | |
614 | break; | |
615 | } | |
616 | break; | |
617 | } | |
618 | ||
ea3d710f | 619 | case PTRACE_GETREGS: |
fb671139 | 620 | ret = ptrace_getregs(child, datavp); |
ea3d710f DJ |
621 | break; |
622 | ||
623 | case PTRACE_SETREGS: | |
fb671139 | 624 | ret = ptrace_setregs(child, datavp); |
ea3d710f DJ |
625 | break; |
626 | ||
627 | case PTRACE_GETFPREGS: | |
fb671139 | 628 | ret = ptrace_getfpregs(child, datavp); |
ea3d710f DJ |
629 | break; |
630 | ||
631 | case PTRACE_SETFPREGS: | |
fb671139 | 632 | ret = ptrace_setfpregs(child, datavp); |
ea3d710f DJ |
633 | break; |
634 | ||
3c37026d | 635 | case PTRACE_GET_THREAD_AREA: |
fb671139 | 636 | ret = put_user(task_thread_info(child)->tp_value, datalp); |
3c37026d RB |
637 | break; |
638 | ||
0926bf95 | 639 | case PTRACE_GET_WATCH_REGS: |
fb671139 | 640 | ret = ptrace_get_watch_regs(child, addrp); |
0926bf95 DD |
641 | break; |
642 | ||
643 | case PTRACE_SET_WATCH_REGS: | |
fb671139 | 644 | ret = ptrace_set_watch_regs(child, addrp); |
0926bf95 DD |
645 | break; |
646 | ||
1da177e4 LT |
647 | default: |
648 | ret = ptrace_request(child, request, addr, data); | |
649 | break; | |
650 | } | |
481bed45 | 651 | out: |
1da177e4 LT |
652 | return ret; |
653 | } | |
654 | ||
655 | /* | |
656 | * Notification of system call entry/exit | |
657 | * - triggered by current->work.syscall_trace | |
658 | */ | |
8b659a39 | 659 | asmlinkage void syscall_trace_enter(struct pt_regs *regs) |
1da177e4 | 660 | { |
0dfa95aa | 661 | long ret = 0; |
c3fc5cd5 RB |
662 | user_exit(); |
663 | ||
293c5bd1 | 664 | /* do the secure computing check first */ |
e4da89d0 | 665 | secure_computing_strict(regs->regs[2]); |
1da177e4 | 666 | |
0dfa95aa RB |
667 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
668 | tracehook_report_syscall_entry(regs)) | |
669 | ret = -1; | |
293c5bd1 | 670 | |
1d7bf993 RB |
671 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
672 | trace_sys_enter(regs, regs->regs[2]); | |
673 | ||
bec9b2b2 RB |
674 | audit_syscall_entry(__syscall_get_arch(), |
675 | regs->regs[2], | |
b05d8447 EP |
676 | regs->regs[4], regs->regs[5], |
677 | regs->regs[6], regs->regs[7]); | |
1da177e4 | 678 | } |
8b659a39 RB |
679 | |
680 | /* | |
681 | * Notification of system call entry/exit | |
682 | * - triggered by current->work.syscall_trace | |
683 | */ | |
684 | asmlinkage void syscall_trace_leave(struct pt_regs *regs) | |
685 | { | |
c3fc5cd5 RB |
686 | /* |
687 | * We may come here right after calling schedule_user() | |
688 | * or do_notify_resume(), in which case we can be in RCU | |
689 | * user mode. | |
690 | */ | |
691 | user_exit(); | |
692 | ||
d7e7528b | 693 | audit_syscall_exit(regs); |
8b659a39 | 694 | |
1d7bf993 RB |
695 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
696 | trace_sys_exit(regs, regs->regs[2]); | |
697 | ||
bc3d22c1 RB |
698 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
699 | tracehook_report_syscall_exit(regs, 0); | |
c3fc5cd5 RB |
700 | |
701 | user_enter(); | |
8b659a39 | 702 | } |