Commit f2ce4802 authored by Mike Frysinger's avatar Mike Frysinger

Blackfin: simplify PTRACE_{PEEK,POKE}USR in preperation for regset support

Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 5f09c77d
...@@ -173,4 +173,6 @@ extern void show_regs(struct pt_regs *); ...@@ -173,4 +173,6 @@ extern void show_regs(struct pt_regs *);
#define PT_FDPIC_EXEC 232 #define PT_FDPIC_EXEC 232
#define PT_FDPIC_INTERP 236 #define PT_FDPIC_INTERP 236
#define PT_LAST_PSEUDO PT_FDPIC_INTERP
#endif /* _BFIN_PTRACE_H */ #endif /* _BFIN_PTRACE_H */
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/mem_map.h> #include <asm/mem_map.h>
#define TEXT_OFFSET 0
/* /*
* does not yet catch signals sent when the child dies. * does not yet catch signals sent when the child dies.
* in exit.c or in signal.c. * in exit.c or in signal.c.
...@@ -43,7 +42,7 @@ ...@@ -43,7 +42,7 @@
* kernel stack will not be empty on entry to the kernel, so * kernel stack will not be empty on entry to the kernel, so
* ptracing these tasks will fail. * ptracing these tasks will fail.
*/ */
static inline struct pt_regs *get_user_regs(struct task_struct *task) static inline struct pt_regs *task_pt_regs(struct task_struct *task)
{ {
return (struct pt_regs *) return (struct pt_regs *)
((unsigned long)task_stack_page(task) + ((unsigned long)task_stack_page(task) +
...@@ -56,7 +55,7 @@ static inline struct pt_regs *get_user_regs(struct task_struct *task) ...@@ -56,7 +55,7 @@ static inline struct pt_regs *get_user_regs(struct task_struct *task)
static inline int ptrace_getregs(struct task_struct *tsk, void __user *uregs) static inline int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
{ {
struct pt_regs regs; struct pt_regs regs;
memcpy(&regs, get_user_regs(tsk), sizeof(regs)); memcpy(&regs, task_pt_regs(tsk), sizeof(regs));
regs.usp = tsk->thread.usp; regs.usp = tsk->thread.usp;
return copy_to_user(uregs, &regs, sizeof(struct pt_regs)) ? -EFAULT : 0; return copy_to_user(uregs, &regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
} }
...@@ -69,40 +68,49 @@ static inline int ptrace_getregs(struct task_struct *tsk, void __user *uregs) ...@@ -69,40 +68,49 @@ static inline int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
/* /*
* Get contents of register REGNO in task TASK. * Get contents of register REGNO in task TASK.
*/ */
static inline long get_reg(struct task_struct *task, int regno) static inline long
get_reg(struct task_struct *task, long regno, unsigned long __user *datap)
{ {
unsigned char *reg_ptr; long tmp;
struct pt_regs *regs = task_pt_regs(task);
struct pt_regs *regs = if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0)
(struct pt_regs *)((unsigned long)task_stack_page(task) + return -EIO;
(THREAD_SIZE - sizeof(struct pt_regs)));
reg_ptr = (char *)regs;
switch (regno) { switch (regno) {
case PT_TEXT_ADDR:
tmp = task->mm->start_code;
break;
case PT_TEXT_END_ADDR:
tmp = task->mm->end_code;
break;
case PT_DATA_ADDR:
tmp = task->mm->start_data;
break;
case PT_USP: case PT_USP:
return task->thread.usp; tmp = task->thread.usp;
break;
default: default:
if (regno <= 216) if (regno < sizeof(*regs)) {
return *(long *)(reg_ptr + regno); void *reg_ptr = regs;
tmp = *(long *)(reg_ptr + regno);
} else
return -EIO;
} }
/* slight mystery ... never seems to come here but kernel misbehaves without this code! */
printk(KERN_WARNING "Request to get for unknown register %d\n", regno); return put_user(tmp, datap);
return 0;
} }
/* /*
* Write contents of register REGNO in task TASK. * Write contents of register REGNO in task TASK.
*/ */
static inline int static inline int
put_reg(struct task_struct *task, int regno, unsigned long data) put_reg(struct task_struct *task, long regno, unsigned long data)
{ {
char *reg_ptr; struct pt_regs *regs = task_pt_regs(task);
struct pt_regs *regs = if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0)
(struct pt_regs *)((unsigned long)task_stack_page(task) + return -EIO;
(THREAD_SIZE - sizeof(struct pt_regs)));
reg_ptr = (char *)regs;
switch (regno) { switch (regno) {
case PT_PC: case PT_PC:
...@@ -119,10 +127,18 @@ put_reg(struct task_struct *task, int regno, unsigned long data) ...@@ -119,10 +127,18 @@ put_reg(struct task_struct *task, int regno, unsigned long data)
regs->usp = data; regs->usp = data;
task->thread.usp = data; task->thread.usp = data;
break; break;
case PT_SYSCFG: /* don't let userspace screw with this */
if ((data & ~1) != 0x6)
pr_warning("ptrace: ignore syscfg write of %#lx\n", data);
break; /* regs->syscfg = data; break; */
default: default:
if (regno <= 216) if (regno < sizeof(*regs)) {
*(long *)(reg_ptr + regno) = data; void *reg_offset = regs;
*(long *)(reg_offset + regno) = data;
}
/* Ignore writes to pseudo registers */
} }
return 0; return 0;
} }
...@@ -231,40 +247,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) ...@@ -231,40 +247,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
break; break;
} }
/* read the word at location addr in the USER area. */
case PTRACE_PEEKUSR:
{
unsigned long tmp;
ret = -EIO;
tmp = 0;
if ((addr & 3) || (addr > (sizeof(struct pt_regs) + 16))) {
printk(KERN_WARNING "ptrace error : PEEKUSR : temporarily returning "
"0 - %x sizeof(pt_regs) is %lx\n",
(int)addr, sizeof(struct pt_regs));
break;
}
if (addr == sizeof(struct pt_regs)) {
/* PT_TEXT_ADDR */
tmp = child->mm->start_code + TEXT_OFFSET;
} else if (addr == (sizeof(struct pt_regs) + 4)) {
/* PT_TEXT_END_ADDR */
tmp = child->mm->end_code;
} else if (addr == (sizeof(struct pt_regs) + 8)) {
/* PT_DATA_ADDR */
tmp = child->mm->start_data;
#ifdef CONFIG_BINFMT_ELF_FDPIC
} else if (addr == (sizeof(struct pt_regs) + 12)) {
goto case_PTRACE_GETFDPIC_EXEC;
} else if (addr == (sizeof(struct pt_regs) + 16)) {
goto case_PTRACE_GETFDPIC_INTERP;
#endif
} else {
tmp = get_reg(child, addr);
}
ret = put_user(tmp, datap);
break;
}
#ifdef CONFIG_BINFMT_ELF_FDPIC #ifdef CONFIG_BINFMT_ELF_FDPIC
case PTRACE_GETFDPIC: { case PTRACE_GETFDPIC: {
unsigned long tmp = 0; unsigned long tmp = 0;
...@@ -327,19 +309,21 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) ...@@ -327,19 +309,21 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
break; break;
} }
case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ case PTRACE_PEEKUSR:
ret = -EIO; switch (addr) {
if ((addr & 3) || (addr > (sizeof(struct pt_regs) + 16))) { #ifdef CONFIG_BINFMT_ELF_FDPIC /* backwards compat */
printk(KERN_WARNING "ptrace error : POKEUSR: temporarily returning 0\n"); case PT_FDPIC_EXEC: goto case_PTRACE_GETFDPIC_EXEC;
break; case PT_FDPIC_INTERP: goto case_PTRACE_GETFDPIC_INTERP;
#endif
default:
ret = get_reg(child, addr, datap);
} }
pr_debug("ptrace: PEEKUSR reg %li with %#lx = %i\n", addr, data, ret);
/* Ignore writes to SYSCFG and other pseudo regs */
if (addr >= PT_SYSCFG) {
ret = 0;
break; break;
}
case PTRACE_POKEUSR:
ret = put_reg(child, addr, data); ret = put_reg(child, addr, data);
pr_debug("ptrace: POKEUSR reg %li with %li = %i\n", addr, data, ret);
break; break;
case PTRACE_GETREGS: case PTRACE_GETREGS:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment