Merge branch 'for-next' of git://gitorious.org/kernel-hsi/kernel-hsi
[deliverable/linux.git] / arch / arm / kernel / ptrace.c
1 /*
2 * linux/arch/arm/kernel/ptrace.c
3 *
4 * By Ross Biro 1/23/92
5 * edited by Linus Torvalds
6 * ARM modifications Copyright (C) 2000 Russell King
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/mm.h>
15 #include <linux/elf.h>
16 #include <linux/smp.h>
17 #include <linux/ptrace.h>
18 #include <linux/user.h>
19 #include <linux/security.h>
20 #include <linux/init.h>
21 #include <linux/signal.h>
22 #include <linux/uaccess.h>
23 #include <linux/perf_event.h>
24 #include <linux/hw_breakpoint.h>
25 #include <linux/regset.h>
26 #include <linux/audit.h>
27
28 #include <asm/pgtable.h>
29 #include <asm/traps.h>
30
31 #define REG_PC 15
32 #define REG_PSR 16
33 /*
34 * does not yet catch signals sent when the child dies.
35 * in exit.c or in signal.c.
36 */
37
38 #if 0
39 /*
40 * Breakpoint SWI instruction: SWI &9F0001
41 */
42 #define BREAKINST_ARM 0xef9f0001
43 #define BREAKINST_THUMB 0xdf00 /* fill this in later */
44 #else
45 /*
46 * New breakpoints - use an undefined instruction. The ARM architecture
47 * reference manual guarantees that the following instruction space
48 * will produce an undefined instruction exception on all CPUs:
49 *
50 * ARM: xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
51 * Thumb: 1101 1110 xxxx xxxx
52 */
53 #define BREAKINST_ARM 0xe7f001f0
54 #define BREAKINST_THUMB 0xde01
55 #endif
56
57 struct pt_regs_offset {
58 const char *name;
59 int offset;
60 };
61
62 #define REG_OFFSET_NAME(r) \
63 {.name = #r, .offset = offsetof(struct pt_regs, ARM_##r)}
64 #define REG_OFFSET_END {.name = NULL, .offset = 0}
65
66 static const struct pt_regs_offset regoffset_table[] = {
67 REG_OFFSET_NAME(r0),
68 REG_OFFSET_NAME(r1),
69 REG_OFFSET_NAME(r2),
70 REG_OFFSET_NAME(r3),
71 REG_OFFSET_NAME(r4),
72 REG_OFFSET_NAME(r5),
73 REG_OFFSET_NAME(r6),
74 REG_OFFSET_NAME(r7),
75 REG_OFFSET_NAME(r8),
76 REG_OFFSET_NAME(r9),
77 REG_OFFSET_NAME(r10),
78 REG_OFFSET_NAME(fp),
79 REG_OFFSET_NAME(ip),
80 REG_OFFSET_NAME(sp),
81 REG_OFFSET_NAME(lr),
82 REG_OFFSET_NAME(pc),
83 REG_OFFSET_NAME(cpsr),
84 REG_OFFSET_NAME(ORIG_r0),
85 REG_OFFSET_END,
86 };
87
88 /**
89 * regs_query_register_offset() - query register offset from its name
90 * @name: the name of a register
91 *
92 * regs_query_register_offset() returns the offset of a register in struct
93 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
94 */
95 int regs_query_register_offset(const char *name)
96 {
97 const struct pt_regs_offset *roff;
98 for (roff = regoffset_table; roff->name != NULL; roff++)
99 if (!strcmp(roff->name, name))
100 return roff->offset;
101 return -EINVAL;
102 }
103
104 /**
105 * regs_query_register_name() - query register name from its offset
106 * @offset: the offset of a register in struct pt_regs.
107 *
108 * regs_query_register_name() returns the name of a register from its
109 * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
110 */
111 const char *regs_query_register_name(unsigned int offset)
112 {
113 const struct pt_regs_offset *roff;
114 for (roff = regoffset_table; roff->name != NULL; roff++)
115 if (roff->offset == offset)
116 return roff->name;
117 return NULL;
118 }
119
120 /**
121 * regs_within_kernel_stack() - check the address in the stack
122 * @regs: pt_regs which contains kernel stack pointer.
123 * @addr: address which is checked.
124 *
125 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
126 * If @addr is within the kernel stack, it returns true. If not, returns false.
127 */
128 bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
129 {
130 return ((addr & ~(THREAD_SIZE - 1)) ==
131 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
132 }
133
134 /**
135 * regs_get_kernel_stack_nth() - get Nth entry of the stack
136 * @regs: pt_regs which contains kernel stack pointer.
137 * @n: stack entry number.
138 *
139 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
140 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
141 * this returns 0.
142 */
143 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
144 {
145 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
146 addr += n;
147 if (regs_within_kernel_stack(regs, (unsigned long)addr))
148 return *addr;
149 else
150 return 0;
151 }
152
153 /*
154 * this routine will get a word off of the processes privileged stack.
155 * the offset is how far from the base addr as stored in the THREAD.
156 * this routine assumes that all the privileged stacks are in our
157 * data space.
158 */
159 static inline long get_user_reg(struct task_struct *task, int offset)
160 {
161 return task_pt_regs(task)->uregs[offset];
162 }
163
164 /*
165 * this routine will put a word on the processes privileged stack.
166 * the offset is how far from the base addr as stored in the THREAD.
167 * this routine assumes that all the privileged stacks are in our
168 * data space.
169 */
170 static inline int
171 put_user_reg(struct task_struct *task, int offset, long data)
172 {
173 struct pt_regs newregs, *regs = task_pt_regs(task);
174 int ret = -EINVAL;
175
176 newregs = *regs;
177 newregs.uregs[offset] = data;
178
179 if (valid_user_regs(&newregs)) {
180 regs->uregs[offset] = data;
181 ret = 0;
182 }
183
184 return ret;
185 }
186
187 /*
188 * Called by kernel/ptrace.c when detaching..
189 */
190 void ptrace_disable(struct task_struct *child)
191 {
192 /* Nothing to do. */
193 }
194
195 /*
196 * Handle hitting a breakpoint.
197 */
198 void ptrace_break(struct task_struct *tsk, struct pt_regs *regs)
199 {
200 siginfo_t info;
201
202 info.si_signo = SIGTRAP;
203 info.si_errno = 0;
204 info.si_code = TRAP_BRKPT;
205 info.si_addr = (void __user *)instruction_pointer(regs);
206
207 force_sig_info(SIGTRAP, &info, tsk);
208 }
209
210 static int break_trap(struct pt_regs *regs, unsigned int instr)
211 {
212 ptrace_break(current, regs);
213 return 0;
214 }
215
216 static struct undef_hook arm_break_hook = {
217 .instr_mask = 0x0fffffff,
218 .instr_val = 0x07f001f0,
219 .cpsr_mask = PSR_T_BIT,
220 .cpsr_val = 0,
221 .fn = break_trap,
222 };
223
224 static struct undef_hook thumb_break_hook = {
225 .instr_mask = 0xffff,
226 .instr_val = 0xde01,
227 .cpsr_mask = PSR_T_BIT,
228 .cpsr_val = PSR_T_BIT,
229 .fn = break_trap,
230 };
231
232 static struct undef_hook thumb2_break_hook = {
233 .instr_mask = 0xffffffff,
234 .instr_val = 0xf7f0a000,
235 .cpsr_mask = PSR_T_BIT,
236 .cpsr_val = PSR_T_BIT,
237 .fn = break_trap,
238 };
239
240 static int __init ptrace_break_init(void)
241 {
242 register_undef_hook(&arm_break_hook);
243 register_undef_hook(&thumb_break_hook);
244 register_undef_hook(&thumb2_break_hook);
245 return 0;
246 }
247
248 core_initcall(ptrace_break_init);
249
250 /*
251 * Read the word at offset "off" into the "struct user". We
252 * actually access the pt_regs stored on the kernel stack.
253 */
254 static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
255 unsigned long __user *ret)
256 {
257 unsigned long tmp;
258
259 if (off & 3 || off >= sizeof(struct user))
260 return -EIO;
261
262 tmp = 0;
263 if (off == PT_TEXT_ADDR)
264 tmp = tsk->mm->start_code;
265 else if (off == PT_DATA_ADDR)
266 tmp = tsk->mm->start_data;
267 else if (off == PT_TEXT_END_ADDR)
268 tmp = tsk->mm->end_code;
269 else if (off < sizeof(struct pt_regs))
270 tmp = get_user_reg(tsk, off >> 2);
271
272 return put_user(tmp, ret);
273 }
274
275 /*
276 * Write the word at offset "off" into "struct user". We
277 * actually access the pt_regs stored on the kernel stack.
278 */
279 static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
280 unsigned long val)
281 {
282 if (off & 3 || off >= sizeof(struct user))
283 return -EIO;
284
285 if (off >= sizeof(struct pt_regs))
286 return 0;
287
288 return put_user_reg(tsk, off >> 2, val);
289 }
290
291 #ifdef CONFIG_IWMMXT
292
293 /*
294 * Get the child iWMMXt state.
295 */
296 static int ptrace_getwmmxregs(struct task_struct *tsk, void __user *ufp)
297 {
298 struct thread_info *thread = task_thread_info(tsk);
299
300 if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
301 return -ENODATA;
302 iwmmxt_task_disable(thread); /* force it to ram */
303 return copy_to_user(ufp, &thread->fpstate.iwmmxt, IWMMXT_SIZE)
304 ? -EFAULT : 0;
305 }
306
307 /*
308 * Set the child iWMMXt state.
309 */
310 static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
311 {
312 struct thread_info *thread = task_thread_info(tsk);
313
314 if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
315 return -EACCES;
316 iwmmxt_task_release(thread); /* force a reload */
317 return copy_from_user(&thread->fpstate.iwmmxt, ufp, IWMMXT_SIZE)
318 ? -EFAULT : 0;
319 }
320
321 #endif
322
323 #ifdef CONFIG_CRUNCH
324 /*
325 * Get the child Crunch state.
326 */
327 static int ptrace_getcrunchregs(struct task_struct *tsk, void __user *ufp)
328 {
329 struct thread_info *thread = task_thread_info(tsk);
330
331 crunch_task_disable(thread); /* force it to ram */
332 return copy_to_user(ufp, &thread->crunchstate, CRUNCH_SIZE)
333 ? -EFAULT : 0;
334 }
335
336 /*
337 * Set the child Crunch state.
338 */
339 static int ptrace_setcrunchregs(struct task_struct *tsk, void __user *ufp)
340 {
341 struct thread_info *thread = task_thread_info(tsk);
342
343 crunch_task_release(thread); /* force a reload */
344 return copy_from_user(&thread->crunchstate, ufp, CRUNCH_SIZE)
345 ? -EFAULT : 0;
346 }
347 #endif
348
349 #ifdef CONFIG_HAVE_HW_BREAKPOINT
350 /*
351 * Convert a virtual register number into an index for a thread_info
352 * breakpoint array. Breakpoints are identified using positive numbers
353 * whilst watchpoints are negative. The registers are laid out as pairs
354 * of (address, control), each pair mapping to a unique hw_breakpoint struct.
355 * Register 0 is reserved for describing resource information.
356 */
357 static int ptrace_hbp_num_to_idx(long num)
358 {
359 if (num < 0)
360 num = (ARM_MAX_BRP << 1) - num;
361 return (num - 1) >> 1;
362 }
363
364 /*
365 * Returns the virtual register number for the address of the
366 * breakpoint at index idx.
367 */
368 static long ptrace_hbp_idx_to_num(int idx)
369 {
370 long mid = ARM_MAX_BRP << 1;
371 long num = (idx << 1) + 1;
372 return num > mid ? mid - num : num;
373 }
374
375 /*
376 * Handle hitting a HW-breakpoint.
377 */
378 static void ptrace_hbptriggered(struct perf_event *bp,
379 struct perf_sample_data *data,
380 struct pt_regs *regs)
381 {
382 struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
383 long num;
384 int i;
385 siginfo_t info;
386
387 for (i = 0; i < ARM_MAX_HBP_SLOTS; ++i)
388 if (current->thread.debug.hbp[i] == bp)
389 break;
390
391 num = (i == ARM_MAX_HBP_SLOTS) ? 0 : ptrace_hbp_idx_to_num(i);
392
393 info.si_signo = SIGTRAP;
394 info.si_errno = (int)num;
395 info.si_code = TRAP_HWBKPT;
396 info.si_addr = (void __user *)(bkpt->trigger);
397
398 force_sig_info(SIGTRAP, &info, current);
399 }
400
401 /*
402 * Set ptrace breakpoint pointers to zero for this task.
403 * This is required in order to prevent child processes from unregistering
404 * breakpoints held by their parent.
405 */
406 void clear_ptrace_hw_breakpoint(struct task_struct *tsk)
407 {
408 memset(tsk->thread.debug.hbp, 0, sizeof(tsk->thread.debug.hbp));
409 }
410
411 /*
412 * Unregister breakpoints from this task and reset the pointers in
413 * the thread_struct.
414 */
415 void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
416 {
417 int i;
418 struct thread_struct *t = &tsk->thread;
419
420 for (i = 0; i < ARM_MAX_HBP_SLOTS; i++) {
421 if (t->debug.hbp[i]) {
422 unregister_hw_breakpoint(t->debug.hbp[i]);
423 t->debug.hbp[i] = NULL;
424 }
425 }
426 }
427
428 static u32 ptrace_get_hbp_resource_info(void)
429 {
430 u8 num_brps, num_wrps, debug_arch, wp_len;
431 u32 reg = 0;
432
433 num_brps = hw_breakpoint_slots(TYPE_INST);
434 num_wrps = hw_breakpoint_slots(TYPE_DATA);
435 debug_arch = arch_get_debug_arch();
436 wp_len = arch_get_max_wp_len();
437
438 reg |= debug_arch;
439 reg <<= 8;
440 reg |= wp_len;
441 reg <<= 8;
442 reg |= num_wrps;
443 reg <<= 8;
444 reg |= num_brps;
445
446 return reg;
447 }
448
449 static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type)
450 {
451 struct perf_event_attr attr;
452
453 ptrace_breakpoint_init(&attr);
454
455 /* Initialise fields to sane defaults. */
456 attr.bp_addr = 0;
457 attr.bp_len = HW_BREAKPOINT_LEN_4;
458 attr.bp_type = type;
459 attr.disabled = 1;
460
461 return register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL,
462 tsk);
463 }
464
465 static int ptrace_gethbpregs(struct task_struct *tsk, long num,
466 unsigned long __user *data)
467 {
468 u32 reg;
469 int idx, ret = 0;
470 struct perf_event *bp;
471 struct arch_hw_breakpoint_ctrl arch_ctrl;
472
473 if (num == 0) {
474 reg = ptrace_get_hbp_resource_info();
475 } else {
476 idx = ptrace_hbp_num_to_idx(num);
477 if (idx < 0 || idx >= ARM_MAX_HBP_SLOTS) {
478 ret = -EINVAL;
479 goto out;
480 }
481
482 bp = tsk->thread.debug.hbp[idx];
483 if (!bp) {
484 reg = 0;
485 goto put;
486 }
487
488 arch_ctrl = counter_arch_bp(bp)->ctrl;
489
490 /*
491 * Fix up the len because we may have adjusted it
492 * to compensate for an unaligned address.
493 */
494 while (!(arch_ctrl.len & 0x1))
495 arch_ctrl.len >>= 1;
496
497 if (num & 0x1)
498 reg = bp->attr.bp_addr;
499 else
500 reg = encode_ctrl_reg(arch_ctrl);
501 }
502
503 put:
504 if (put_user(reg, data))
505 ret = -EFAULT;
506
507 out:
508 return ret;
509 }
510
511 static int ptrace_sethbpregs(struct task_struct *tsk, long num,
512 unsigned long __user *data)
513 {
514 int idx, gen_len, gen_type, implied_type, ret = 0;
515 u32 user_val;
516 struct perf_event *bp;
517 struct arch_hw_breakpoint_ctrl ctrl;
518 struct perf_event_attr attr;
519
520 if (num == 0)
521 goto out;
522 else if (num < 0)
523 implied_type = HW_BREAKPOINT_RW;
524 else
525 implied_type = HW_BREAKPOINT_X;
526
527 idx = ptrace_hbp_num_to_idx(num);
528 if (idx < 0 || idx >= ARM_MAX_HBP_SLOTS) {
529 ret = -EINVAL;
530 goto out;
531 }
532
533 if (get_user(user_val, data)) {
534 ret = -EFAULT;
535 goto out;
536 }
537
538 bp = tsk->thread.debug.hbp[idx];
539 if (!bp) {
540 bp = ptrace_hbp_create(tsk, implied_type);
541 if (IS_ERR(bp)) {
542 ret = PTR_ERR(bp);
543 goto out;
544 }
545 tsk->thread.debug.hbp[idx] = bp;
546 }
547
548 attr = bp->attr;
549
550 if (num & 0x1) {
551 /* Address */
552 attr.bp_addr = user_val;
553 } else {
554 /* Control */
555 decode_ctrl_reg(user_val, &ctrl);
556 ret = arch_bp_generic_fields(ctrl, &gen_len, &gen_type);
557 if (ret)
558 goto out;
559
560 if ((gen_type & implied_type) != gen_type) {
561 ret = -EINVAL;
562 goto out;
563 }
564
565 attr.bp_len = gen_len;
566 attr.bp_type = gen_type;
567 attr.disabled = !ctrl.enabled;
568 }
569
570 ret = modify_user_hw_breakpoint(bp, &attr);
571 out:
572 return ret;
573 }
574 #endif
575
576 /* regset get/set implementations */
577
578 static int gpr_get(struct task_struct *target,
579 const struct user_regset *regset,
580 unsigned int pos, unsigned int count,
581 void *kbuf, void __user *ubuf)
582 {
583 struct pt_regs *regs = task_pt_regs(target);
584
585 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
586 regs,
587 0, sizeof(*regs));
588 }
589
590 static int gpr_set(struct task_struct *target,
591 const struct user_regset *regset,
592 unsigned int pos, unsigned int count,
593 const void *kbuf, const void __user *ubuf)
594 {
595 int ret;
596 struct pt_regs newregs;
597
598 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
599 &newregs,
600 0, sizeof(newregs));
601 if (ret)
602 return ret;
603
604 if (!valid_user_regs(&newregs))
605 return -EINVAL;
606
607 *task_pt_regs(target) = newregs;
608 return 0;
609 }
610
611 static int fpa_get(struct task_struct *target,
612 const struct user_regset *regset,
613 unsigned int pos, unsigned int count,
614 void *kbuf, void __user *ubuf)
615 {
616 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
617 &task_thread_info(target)->fpstate,
618 0, sizeof(struct user_fp));
619 }
620
621 static int fpa_set(struct task_struct *target,
622 const struct user_regset *regset,
623 unsigned int pos, unsigned int count,
624 const void *kbuf, const void __user *ubuf)
625 {
626 struct thread_info *thread = task_thread_info(target);
627
628 thread->used_cp[1] = thread->used_cp[2] = 1;
629
630 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
631 &thread->fpstate,
632 0, sizeof(struct user_fp));
633 }
634
635 #ifdef CONFIG_VFP
636 /*
637 * VFP register get/set implementations.
638 *
639 * With respect to the kernel, struct user_fp is divided into three chunks:
640 * 16 or 32 real VFP registers (d0-d15 or d0-31)
641 * These are transferred to/from the real registers in the task's
642 * vfp_hard_struct. The number of registers depends on the kernel
643 * configuration.
644 *
645 * 16 or 0 fake VFP registers (d16-d31 or empty)
646 * i.e., the user_vfp structure has space for 32 registers even if
647 * the kernel doesn't have them all.
648 *
649 * vfp_get() reads this chunk as zero where applicable
650 * vfp_set() ignores this chunk
651 *
652 * 1 word for the FPSCR
653 *
654 * The bounds-checking logic built into user_regset_copyout and friends
655 * means that we can make a simple sequence of calls to map the relevant data
656 * to/from the specified slice of the user regset structure.
657 */
658 static int vfp_get(struct task_struct *target,
659 const struct user_regset *regset,
660 unsigned int pos, unsigned int count,
661 void *kbuf, void __user *ubuf)
662 {
663 int ret;
664 struct thread_info *thread = task_thread_info(target);
665 struct vfp_hard_struct const *vfp = &thread->vfpstate.hard;
666 const size_t user_fpregs_offset = offsetof(struct user_vfp, fpregs);
667 const size_t user_fpscr_offset = offsetof(struct user_vfp, fpscr);
668
669 vfp_sync_hwstate(thread);
670
671 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
672 &vfp->fpregs,
673 user_fpregs_offset,
674 user_fpregs_offset + sizeof(vfp->fpregs));
675 if (ret)
676 return ret;
677
678 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
679 user_fpregs_offset + sizeof(vfp->fpregs),
680 user_fpscr_offset);
681 if (ret)
682 return ret;
683
684 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
685 &vfp->fpscr,
686 user_fpscr_offset,
687 user_fpscr_offset + sizeof(vfp->fpscr));
688 }
689
690 /*
691 * For vfp_set() a read-modify-write is done on the VFP registers,
692 * in order to avoid writing back a half-modified set of registers on
693 * failure.
694 */
695 static int vfp_set(struct task_struct *target,
696 const struct user_regset *regset,
697 unsigned int pos, unsigned int count,
698 const void *kbuf, const void __user *ubuf)
699 {
700 int ret;
701 struct thread_info *thread = task_thread_info(target);
702 struct vfp_hard_struct new_vfp;
703 const size_t user_fpregs_offset = offsetof(struct user_vfp, fpregs);
704 const size_t user_fpscr_offset = offsetof(struct user_vfp, fpscr);
705
706 vfp_sync_hwstate(thread);
707 new_vfp = thread->vfpstate.hard;
708
709 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
710 &new_vfp.fpregs,
711 user_fpregs_offset,
712 user_fpregs_offset + sizeof(new_vfp.fpregs));
713 if (ret)
714 return ret;
715
716 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
717 user_fpregs_offset + sizeof(new_vfp.fpregs),
718 user_fpscr_offset);
719 if (ret)
720 return ret;
721
722 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
723 &new_vfp.fpscr,
724 user_fpscr_offset,
725 user_fpscr_offset + sizeof(new_vfp.fpscr));
726 if (ret)
727 return ret;
728
729 vfp_flush_hwstate(thread);
730 thread->vfpstate.hard = new_vfp;
731
732 return 0;
733 }
734 #endif /* CONFIG_VFP */
735
736 enum arm_regset {
737 REGSET_GPR,
738 REGSET_FPR,
739 #ifdef CONFIG_VFP
740 REGSET_VFP,
741 #endif
742 };
743
744 static const struct user_regset arm_regsets[] = {
745 [REGSET_GPR] = {
746 .core_note_type = NT_PRSTATUS,
747 .n = ELF_NGREG,
748 .size = sizeof(u32),
749 .align = sizeof(u32),
750 .get = gpr_get,
751 .set = gpr_set
752 },
753 [REGSET_FPR] = {
754 /*
755 * For the FPA regs in fpstate, the real fields are a mixture
756 * of sizes, so pretend that the registers are word-sized:
757 */
758 .core_note_type = NT_PRFPREG,
759 .n = sizeof(struct user_fp) / sizeof(u32),
760 .size = sizeof(u32),
761 .align = sizeof(u32),
762 .get = fpa_get,
763 .set = fpa_set
764 },
765 #ifdef CONFIG_VFP
766 [REGSET_VFP] = {
767 /*
768 * Pretend that the VFP regs are word-sized, since the FPSCR is
769 * a single word dangling at the end of struct user_vfp:
770 */
771 .core_note_type = NT_ARM_VFP,
772 .n = ARM_VFPREGS_SIZE / sizeof(u32),
773 .size = sizeof(u32),
774 .align = sizeof(u32),
775 .get = vfp_get,
776 .set = vfp_set
777 },
778 #endif /* CONFIG_VFP */
779 };
780
781 static const struct user_regset_view user_arm_view = {
782 .name = "arm", .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
783 .regsets = arm_regsets, .n = ARRAY_SIZE(arm_regsets)
784 };
785
786 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
787 {
788 return &user_arm_view;
789 }
790
791 long arch_ptrace(struct task_struct *child, long request,
792 unsigned long addr, unsigned long data)
793 {
794 int ret;
795 unsigned long __user *datap = (unsigned long __user *) data;
796
797 switch (request) {
798 case PTRACE_PEEKUSR:
799 ret = ptrace_read_user(child, addr, datap);
800 break;
801
802 case PTRACE_POKEUSR:
803 ret = ptrace_write_user(child, addr, data);
804 break;
805
806 case PTRACE_GETREGS:
807 ret = copy_regset_to_user(child,
808 &user_arm_view, REGSET_GPR,
809 0, sizeof(struct pt_regs),
810 datap);
811 break;
812
813 case PTRACE_SETREGS:
814 ret = copy_regset_from_user(child,
815 &user_arm_view, REGSET_GPR,
816 0, sizeof(struct pt_regs),
817 datap);
818 break;
819
820 case PTRACE_GETFPREGS:
821 ret = copy_regset_to_user(child,
822 &user_arm_view, REGSET_FPR,
823 0, sizeof(union fp_state),
824 datap);
825 break;
826
827 case PTRACE_SETFPREGS:
828 ret = copy_regset_from_user(child,
829 &user_arm_view, REGSET_FPR,
830 0, sizeof(union fp_state),
831 datap);
832 break;
833
834 #ifdef CONFIG_IWMMXT
835 case PTRACE_GETWMMXREGS:
836 ret = ptrace_getwmmxregs(child, datap);
837 break;
838
839 case PTRACE_SETWMMXREGS:
840 ret = ptrace_setwmmxregs(child, datap);
841 break;
842 #endif
843
844 case PTRACE_GET_THREAD_AREA:
845 ret = put_user(task_thread_info(child)->tp_value,
846 datap);
847 break;
848
849 case PTRACE_SET_SYSCALL:
850 task_thread_info(child)->syscall = data;
851 ret = 0;
852 break;
853
854 #ifdef CONFIG_CRUNCH
855 case PTRACE_GETCRUNCHREGS:
856 ret = ptrace_getcrunchregs(child, datap);
857 break;
858
859 case PTRACE_SETCRUNCHREGS:
860 ret = ptrace_setcrunchregs(child, datap);
861 break;
862 #endif
863
864 #ifdef CONFIG_VFP
865 case PTRACE_GETVFPREGS:
866 ret = copy_regset_to_user(child,
867 &user_arm_view, REGSET_VFP,
868 0, ARM_VFPREGS_SIZE,
869 datap);
870 break;
871
872 case PTRACE_SETVFPREGS:
873 ret = copy_regset_from_user(child,
874 &user_arm_view, REGSET_VFP,
875 0, ARM_VFPREGS_SIZE,
876 datap);
877 break;
878 #endif
879
880 #ifdef CONFIG_HAVE_HW_BREAKPOINT
881 case PTRACE_GETHBPREGS:
882 if (ptrace_get_breakpoints(child) < 0)
883 return -ESRCH;
884
885 ret = ptrace_gethbpregs(child, addr,
886 (unsigned long __user *)data);
887 ptrace_put_breakpoints(child);
888 break;
889 case PTRACE_SETHBPREGS:
890 if (ptrace_get_breakpoints(child) < 0)
891 return -ESRCH;
892
893 ret = ptrace_sethbpregs(child, addr,
894 (unsigned long __user *)data);
895 ptrace_put_breakpoints(child);
896 break;
897 #endif
898
899 default:
900 ret = ptrace_request(child, request, addr, data);
901 break;
902 }
903
904 return ret;
905 }
906
907 #ifdef __ARMEB__
908 #define AUDIT_ARCH_NR AUDIT_ARCH_ARMEB
909 #else
910 #define AUDIT_ARCH_NR AUDIT_ARCH_ARM
911 #endif
912
913 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
914 {
915 unsigned long ip;
916
917 /*
918 * Save IP. IP is used to denote syscall entry/exit:
919 * IP = 0 -> entry, = 1 -> exit
920 */
921 ip = regs->ARM_ip;
922 regs->ARM_ip = why;
923
924 if (!ip)
925 audit_syscall_exit(regs);
926 else
927 audit_syscall_entry(AUDIT_ARCH_NR, scno, regs->ARM_r0,
928 regs->ARM_r1, regs->ARM_r2, regs->ARM_r3);
929
930 if (!test_thread_flag(TIF_SYSCALL_TRACE))
931 return scno;
932 if (!(current->ptrace & PT_PTRACED))
933 return scno;
934
935 current_thread_info()->syscall = scno;
936
937 /* the 0x80 provides a way for the tracing parent to distinguish
938 between a syscall stop and SIGTRAP delivery */
939 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
940 ? 0x80 : 0));
941 /*
942 * this isn't the same as continuing with a signal, but it will do
943 * for normal use. strace only continues with a signal if the
944 * stopping signal is not SIGTRAP. -brl
945 */
946 if (current->exit_code) {
947 send_sig(current->exit_code, current, 1);
948 current->exit_code = 0;
949 }
950 regs->ARM_ip = ip;
951
952 return current_thread_info()->syscall;
953 }
This page took 0.050921 seconds and 5 git commands to generate.