Skip to contentSkip to conversation

Threaded core dumps for PPC32

PATCH New Paul Mackerras 1 participant 1 message Mar 24, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Threaded core dumps for PPC32

At the moment, ppc32 kernels will oops if a threaded program tries to dump core. We call dump_fpu with a NULL regs pointer, which it tries to dereference. This patch fixes that by implementing the hooks used in doing threaded core dumps properly.

Please apply, preferably before 2.6.5 (since it fixes an oops).

Thanks,
Paul.

arch/ppc/kernel/process.c +4 -5
diff -urN linux-2.5/arch/ppc/kernel/process.c pmac-2.5/arch/ppc/kernel/process.c
@@ -45,7 +45,6 @@
 #include <asm/prom.h>
 #include <asm/hardirq.h>
 
-int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs);
 extern unsigned long _get_SP(void);
 
 struct task_struct *last_task_used_math = NULL;
@@ -189,11 +188,11 @@
 }
 
 int
-dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
+dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
 {
-	if (regs->msr & MSR_FP)
-		giveup_fpu(current);
-	memcpy(fpregs, &current->thread.fpr[0], sizeof(*fpregs));
+	if (tsk->thread.regs && tsk->thread.regs->msr & MSR_FP)
+		giveup_fpu(tsk);
+	memcpy(fpregs, &tsk->thread.fpr[0], sizeof(*fpregs));
 	return 1;
 }
 
include/asm-ppc/elf.h +10 -4
diff -urN linux-2.5/include/asm-ppc/elf.h pmac-2.5/include/asm-ppc/elf.h
@@ -90,11 +90,17 @@
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	4096
 
-#define ELF_CORE_COPY_REGS(gregs, regs) \
-	memcpy(gregs, regs, \
-	       sizeof(struct pt_regs) < sizeof(elf_gregset_t)? \
-	       sizeof(struct pt_regs): sizeof(elf_gregset_t));
+#define ELF_CORE_COPY_REGS(gregs, regs)				\
+	memcpy((gregs), (regs), sizeof(struct pt_regs));	\
+	memset((char *)(gregs) + sizeof(struct pt_regs), 0,	\
+	       sizeof(elf_gregset_t) - sizeof(struct pt_regs));
+
+#define ELF_CORE_COPY_TASK_REGS(t, elfregs)			\
+	((t)->thread.regs?					\
+	 ({ ELF_CORE_COPY_REGS((elfregs), (t)->thread.regs); 1; }): 0)
 
+extern int dump_task_fpu(struct task_struct *t, elf_fpregset_t *fpu);
+#define ELF_CORE_COPY_FPREGS(t, fpu)	dump_task_fpu((t), (fpu))
 
 /* This yields a mask that user programs can use to figure out what
    instruction set this cpu supports.  This could be done in userspace,