2 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
3 * these modifications are Copyright 2004-2010 Analog Devices Inc.
5 * Licensed under the GPL-2
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
11 #include <linux/smp.h>
12 #include <linux/elf.h>
13 #include <linux/errno.h>
14 #include <linux/ptrace.h>
15 #include <linux/user.h>
16 #include <linux/regset.h>
17 #include <linux/signal.h>
18 #include <linux/tracehook.h>
19 #include <linux/uaccess.h>
22 #include <asm/pgtable.h>
23 #include <asm/system.h>
24 #include <asm/processor.h>
25 #include <asm/asm-offsets.h>
27 #include <asm/fixed_code.h>
28 #include <asm/cacheflush.h>
29 #include <asm/mem_map.h>
30 #include <asm/mmu_context.h>
33 * does not yet catch signals sent when the child dies.
34 * in exit.c or in signal.c.
38 * Get contents of register REGNO in task TASK.
41 get_reg(struct task_struct *task, long regno, unsigned long __user *datap)
44 struct pt_regs *regs = task_pt_regs(task);
46 if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0)
51 tmp = task->mm->start_code;
53 case PT_TEXT_END_ADDR:
54 tmp = task->mm->end_code;
57 tmp = task->mm->start_data;
60 tmp = task->thread.usp;
63 if (regno < sizeof(*regs)) {
65 tmp = *(long *)(reg_ptr + regno);
70 return put_user(tmp, datap);
74 * Write contents of register REGNO in task TASK.
77 put_reg(struct task_struct *task, long regno, unsigned long data)
79 struct pt_regs *regs = task_pt_regs(task);
81 if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0)
86 /*********************************************************************/
87 /* At this point the kernel is most likely in exception. */
88 /* The RETX register will be used to populate the pc of the process. */
89 /*********************************************************************/
94 break; /* regs->retx = data; break; */
97 task->thread.usp = data;
99 case PT_SYSCFG: /* don't let userspace screw with this */
100 if ((data & ~1) != 0x6)
101 pr_warning("ptrace: ignore syscfg write of %#lx\n", data);
102 break; /* regs->syscfg = data; break; */
104 if (regno < sizeof(*regs)) {
105 void *reg_offset = regs;
106 *(long *)(reg_offset + regno) = data;
108 /* Ignore writes to pseudo registers */
115 * check that an address falls within the bounds of the target process's memory mappings
118 is_user_addr_valid(struct task_struct *child, unsigned long start, unsigned long len)
120 struct vm_area_struct *vma;
121 struct sram_list_struct *sraml;
124 if (start + len < start)
127 vma = find_vma(child->mm, start);
128 if (vma && start >= vma->vm_start && start + len <= vma->vm_end)
131 for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next)
132 if (start >= (unsigned long)sraml->addr
133 && start + len < (unsigned long)sraml->addr + sraml->length)
136 if (start >= FIXED_CODE_START && start + len < FIXED_CODE_END)
139 #ifdef CONFIG_APP_STACK_L1
140 if (child->mm->context.l1_stack_save)
141 if (start >= (unsigned long)l1_stack_base &&
142 start + len < (unsigned long)l1_stack_base + l1_stack_len)
150 * retrieve the contents of Blackfin userspace general registers
152 static int genregs_get(struct task_struct *target,
153 const struct user_regset *regset,
154 unsigned int pos, unsigned int count,
155 void *kbuf, void __user *ubuf)
157 struct pt_regs *regs = task_pt_regs(target);
161 regs->usp = target->thread.usp;
163 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
164 regs, 0, sizeof(*regs));
168 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
173 * update the contents of the Blackfin userspace general registers
175 static int genregs_set(struct task_struct *target,
176 const struct user_regset *regset,
177 unsigned int pos, unsigned int count,
178 const void *kbuf, const void __user *ubuf)
180 struct pt_regs *regs = task_pt_regs(target);
183 /* Don't let people set SYSCFG (it's at the end of pt_regs) */
184 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
190 target->thread.usp = regs->usp;
191 /* regs->retx = regs->pc; */
193 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
198 * Define the register sets available on the Blackfin under Linux
204 static const struct user_regset bfin_regsets[] = {
206 .core_note_type = NT_PRSTATUS,
207 .n = sizeof(struct pt_regs) / sizeof(long),
208 .size = sizeof(long),
209 .align = sizeof(long),
215 static const struct user_regset_view user_bfin_native_view = {
217 .e_machine = EM_BLACKFIN,
218 .regsets = bfin_regsets,
219 .n = ARRAY_SIZE(bfin_regsets),
222 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
224 return &user_bfin_native_view;
227 void user_enable_single_step(struct task_struct *child)
229 struct pt_regs *regs = task_pt_regs(child);
230 regs->syscfg |= SYSCFG_SSSTEP;
232 set_tsk_thread_flag(child, TIF_SINGLESTEP);
235 void user_disable_single_step(struct task_struct *child)
237 struct pt_regs *regs = task_pt_regs(child);
238 regs->syscfg &= ~SYSCFG_SSSTEP;
240 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
243 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
246 unsigned long __user *datap = (unsigned long __user *)data;
247 void *paddr = (void *)addr;
250 /* when I and D space are separate, these will need to be fixed. */
251 case PTRACE_PEEKDATA:
252 pr_debug("ptrace: PEEKDATA\n");
254 case PTRACE_PEEKTEXT: /* read word at location addr. */
256 unsigned long tmp = 0;
257 int copied = 0, to_copy = sizeof(tmp);
260 pr_debug("ptrace: PEEKTEXT at addr 0x%08lx + %i\n", addr, to_copy);
261 if (is_user_addr_valid(child, addr, to_copy) < 0)
263 pr_debug("ptrace: user address is valid\n");
265 switch (bfin_mem_access_type(addr, to_copy)) {
266 case BFIN_MEM_ACCESS_CORE:
267 case BFIN_MEM_ACCESS_CORE_ONLY:
268 copied = access_process_vm(child, addr, &tmp,
273 /* hrm, why didn't that work ... maybe no mapping */
274 if (addr >= FIXED_CODE_START &&
275 addr + to_copy <= FIXED_CODE_END) {
276 copy_from_user_page(0, 0, 0, &tmp, paddr, to_copy);
278 } else if (addr >= BOOT_ROM_START) {
279 memcpy(&tmp, paddr, to_copy);
284 case BFIN_MEM_ACCESS_DMA:
285 if (safe_dma_memcpy(&tmp, paddr, to_copy))
288 case BFIN_MEM_ACCESS_ITEST:
289 if (isram_memcpy(&tmp, paddr, to_copy))
297 pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp);
298 if (copied == to_copy)
299 ret = put_user(tmp, datap);
303 /* when I and D space are separate, this will have to be fixed. */
304 case PTRACE_POKEDATA:
305 pr_debug("ptrace: PTRACE_PEEKDATA\n");
307 case PTRACE_POKETEXT: /* write the word at location addr. */
309 int copied = 0, to_copy = sizeof(data);
312 pr_debug("ptrace: POKETEXT at addr 0x%08lx + %i bytes %lx\n",
313 addr, to_copy, data);
314 if (is_user_addr_valid(child, addr, to_copy) < 0)
316 pr_debug("ptrace: user address is valid\n");
318 switch (bfin_mem_access_type(addr, to_copy)) {
319 case BFIN_MEM_ACCESS_CORE:
320 case BFIN_MEM_ACCESS_CORE_ONLY:
321 copied = access_process_vm(child, addr, &data,
324 case BFIN_MEM_ACCESS_DMA:
325 if (safe_dma_memcpy(paddr, &data, to_copy))
328 case BFIN_MEM_ACCESS_ITEST:
329 if (isram_memcpy(paddr, &data, to_copy))
337 pr_debug("ptrace: copied size %d\n", copied);
338 if (copied == to_copy)
345 #ifdef CONFIG_BINFMT_ELF_FDPIC /* backwards compat */
347 request = PTRACE_GETFDPIC;
348 addr = PTRACE_GETFDPIC_EXEC;
350 case PT_FDPIC_INTERP:
351 request = PTRACE_GETFDPIC;
352 addr = PTRACE_GETFDPIC_INTERP;
356 ret = get_reg(child, addr, datap);
358 pr_debug("ptrace: PEEKUSR reg %li with %#lx = %i\n", addr, data, ret);
362 ret = put_reg(child, addr, data);
363 pr_debug("ptrace: POKEUSR reg %li with %li = %i\n", addr, data, ret);
367 pr_debug("ptrace: PTRACE_GETREGS\n");
368 return copy_regset_to_user(child, &user_bfin_native_view,
370 0, sizeof(struct pt_regs),
371 (void __user *)data);
374 pr_debug("ptrace: PTRACE_SETREGS\n");
375 return copy_regset_from_user(child, &user_bfin_native_view,
377 0, sizeof(struct pt_regs),
378 (const void __user *)data);
382 ret = ptrace_request(child, request, addr, data);
389 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
393 if (test_thread_flag(TIF_SYSCALL_TRACE))
394 ret = tracehook_report_syscall_entry(regs);
399 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
403 step = test_thread_flag(TIF_SINGLESTEP);
404 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
405 tracehook_report_syscall_exit(regs, step);