[PATCH 09/50] i386: fix task_pt_regs()

From: Al Viro
Date: Tue Jan 03 2006 - 16:17:14 EST


References: <20060103210515.5135@xxxxxxxxxxxxxxxx>
In-Reply-To: <20060103210515.5135@xxxxxxxxxxxxxxxx>

task_pt_regs() needs the same offset-by-8 to match copy_thread()

Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>

---

arch/i386/kernel/process.c | 20 ++------------------
arch/i386/kernel/smpboot.c | 3 +--
include/asm-i386/processor.h | 12 +++++++++++-
3 files changed, 14 insertions(+), 21 deletions(-)

a363a5cdd3f6e20f7166e4b18f9e3b2d0f043461
diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
index b48cfe1..7765f3a 100644
--- a/arch/i386/kernel/process.c
+++ b/arch/i386/kernel/process.c
@@ -435,18 +435,7 @@ int copy_thread(int nr, unsigned long cl
struct task_struct *tsk;
int err;

- childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
- /*
- * The below -8 is to reserve 8 bytes on top of the ring0 stack.
- * This is necessary to guarantee that the entire "struct pt_regs"
- * is accessable even if the CPU haven't stored the SS/ESP registers
- * on the stack (interrupt gate does not save these registers
- * when switching to the same priv ring).
- * Therefore beware: accessing the xss/esp fields of the
- * "struct pt_regs" is possible, but they may contain the
- * completely wrong values.
- */
- childregs = (struct pt_regs *) ((unsigned long) childregs - 8);
+ childregs = task_pt_regs(p);
*childregs = *regs;
childregs->eax = 0;
childregs->esp = esp;
@@ -551,12 +540,7 @@ EXPORT_SYMBOL(dump_thread);
*/
int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
{
- struct pt_regs ptregs;
-
- ptregs = *(struct pt_regs *)
- ((unsigned long)tsk->thread_info +
- /* see comments in copy_thread() about -8 */
- THREAD_SIZE - sizeof(ptregs) - 8);
+ struct pt_regs ptregs = *task_pt_regs(tsk);
ptregs.xcs &= 0xffff;
ptregs.xds &= 0xffff;
ptregs.xes &= 0xffff;
diff --git a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
index 9ed449a..b96b29f 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -875,8 +875,7 @@ static inline struct task_struct * alloc
/* initialize thread_struct. we really want to avoid destroy
* idle tread
*/
- idle->thread.esp = (unsigned long)(((struct pt_regs *)
- (THREAD_SIZE + (unsigned long) idle->thread_info)) - 1);
+ idle->thread.esp = (unsigned long)task_pt_regs(idle);
init_idle(idle, cpu);
return idle;
}
diff --git a/include/asm-i386/processor.h b/include/asm-i386/processor.h
index 5c96cf6..84f2fd1 100644
--- a/include/asm-i386/processor.h
+++ b/include/asm-i386/processor.h
@@ -557,10 +557,20 @@ unsigned long get_wchan(struct task_stru
(unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
})

+/*
+ * The below -8 is to reserve 8 bytes on top of the ring0 stack.
+ * This is necessary to guarantee that the entire "struct pt_regs"
+ * is accessable even if the CPU haven't stored the SS/ESP registers
+ * on the stack (interrupt gate does not save these registers
+ * when switching to the same priv ring).
+ * Therefore beware: accessing the xss/esp fields of the
+ * "struct pt_regs" is possible, but they may contain the
+ * completely wrong values.
+ */
#define task_pt_regs(task) \
({ \
struct pt_regs *__regs__; \
- __regs__ = (struct pt_regs *)KSTK_TOP((task)->thread_info); \
+ __regs__ = (struct pt_regs *)(KSTK_TOP((task)->thread_info)-8); \
__regs__ - 1; \
})

--
0.99.9.GIT

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/