Commit 62a97d44 authored by Roland McGrath's avatar Roland McGrath Committed by Ingo Molnar

x86-32 ptrace: use task_pt_regs

This cleans up the 32-bit ptrace code to use task_pt_regs instead of its
own redundant code that does the same thing a different way.
Signed-off-by: default avatarRoland McGrath <roland@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent d6f4fb75
...@@ -37,53 +37,20 @@ ...@@ -37,53 +37,20 @@
*/ */
#define FLAG_MASK 0x00050dd5 #define FLAG_MASK 0x00050dd5
/* static long *pt_regs_access(struct pt_regs *regs, unsigned long regno)
* Offset of eflags on child stack..
*/
#define EFL_OFFSET offsetof(struct pt_regs, eflags)
static inline struct pt_regs *get_child_regs(struct task_struct *task)
{
void *stack_top = (void *)task->thread.esp0;
return stack_top - sizeof(struct pt_regs);
}
/*
* This routine will get a word off of the processes privileged stack.
* the offset is bytes into the pt_regs structure on the stack.
* This routine assumes that all the privileged stacks are in our
* data space.
*/
static inline int get_stack_long(struct task_struct *task, int offset)
{ {
unsigned char *stack; BUILD_BUG_ON(offsetof(struct pt_regs, ebx) != 0);
if (regno > FS)
stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs); --regno;
stack += offset; return &regs->ebx + regno;
return (*((int *)stack));
}
/*
* This routine will put a word on the processes privileged stack.
* the offset is bytes into the pt_regs structure on the stack.
* This routine assumes that all the privileged stacks are in our
* data space.
*/
static inline int put_stack_long(struct task_struct *task, int offset,
unsigned long data)
{
unsigned char * stack;
stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
stack += offset;
*(unsigned long *) stack = data;
return 0;
} }
static int putreg(struct task_struct *child, static int putreg(struct task_struct *child,
unsigned long regno, unsigned long value) unsigned long regno, unsigned long value)
{ {
switch (regno >> 2) { struct pt_regs *regs = task_pt_regs(child);
regno >>= 2;
switch (regno) {
case GS: case GS:
if (value && (value & 3) != 3) if (value && (value & 3) != 3)
return -EIO; return -EIO;
...@@ -113,26 +80,25 @@ static int putreg(struct task_struct *child, ...@@ -113,26 +80,25 @@ static int putreg(struct task_struct *child,
clear_tsk_thread_flag(child, TIF_FORCED_TF); clear_tsk_thread_flag(child, TIF_FORCED_TF);
else if (test_tsk_thread_flag(child, TIF_FORCED_TF)) else if (test_tsk_thread_flag(child, TIF_FORCED_TF))
value |= X86_EFLAGS_TF; value |= X86_EFLAGS_TF;
value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK; value |= regs->eflags & ~FLAG_MASK;
break; break;
} }
if (regno > FS*4) *pt_regs_access(regs, regno) = value;
regno -= 1*4;
put_stack_long(child, regno, value);
return 0; return 0;
} }
static unsigned long getreg(struct task_struct *child, static unsigned long getreg(struct task_struct *child, unsigned long regno)
unsigned long regno)
{ {
struct pt_regs *regs = task_pt_regs(child);
unsigned long retval = ~0UL; unsigned long retval = ~0UL;
switch (regno >> 2) { regno >>= 2;
switch (regno) {
case EFL: case EFL:
/* /*
* If the debugger set TF, hide it from the readout. * If the debugger set TF, hide it from the readout.
*/ */
retval = get_stack_long(child, EFL_OFFSET); retval = regs->eflags;
if (test_tsk_thread_flag(child, TIF_FORCED_TF)) if (test_tsk_thread_flag(child, TIF_FORCED_TF))
retval &= ~X86_EFLAGS_TF; retval &= ~X86_EFLAGS_TF;
break; break;
...@@ -147,9 +113,7 @@ static unsigned long getreg(struct task_struct *child, ...@@ -147,9 +113,7 @@ static unsigned long getreg(struct task_struct *child,
retval = 0xffff; retval = 0xffff;
/* fall through */ /* fall through */
default: default:
if (regno > FS*4) retval &= *pt_regs_access(regs, regno);
regno -= 1*4;
retval &= get_stack_long(child, regno);
} }
return retval; return retval;
} }
......
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