[parisc-linux-cvs] binfmt_elf changes for 64-bit coredumps of 32-bit binaries

Matthew Wilcox willy@ldl.fc.hp.com
Mon, 12 Feb 2001 11:41:05 -0700


Here's the reorg of my binfmt_elf changes that are being committed RSN.

Index: arch/parisc/kernel/process.c
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc/kernel/process.c,v
retrieving revision 1.27
diff -u -p -r1.27 process.c
--- process.c	2001/01/24 23:59:51	1.27
+++ process.c	2001/02/12 18:34:31
@@ -208,49 +208,6 @@ int dump_fpu (struct pt_regs * regs, elf
 	return 1;
 }
 
-/*
- * Fill in general registers in a core dump.  This saves pretty
- * much the same registers as hp-ux, although in a different order.
- * Registers marked # below are not currently saved in pt_regs, so
- * we use their current values here.
- *
- * 	gr0..gr31
- * 	sr0..sr7
- * 	iaoq0..iaoq1
- * 	iasq0..iasq1
- * 	cr11 (sar)
- * 	cr19 (iir)
- * 	cr20 (isr)
- * 	cr21 (ior)
- *  #	cr22 (ipsw)
- *  #	cr0 (recovery counter)
- *  #	cr24..cr31 (temporary registers)
- *  #	cr8,9,12,13 (protection IDs)
- *  #	cr10 (scr/ccr)
- *  #	cr15 (ext int enable mask)
- *
- */
-
-void
-parisc_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
-{
-	memset(dst, 0, sizeof(dst));	/* don't leak any "random" bits */
-	memcpy(dst + 0, pt->gr, 32 * sizeof(elf_greg_t));
-	memcpy(dst + 32, pt->sr, 8 * sizeof(elf_greg_t));
-	memcpy(dst + 40, pt->iaoq, 2 * sizeof(elf_greg_t));
-	memcpy(dst + 42, pt->iasq, 2 * sizeof(elf_greg_t));
-	dst[44] = pt->sar;   dst[45] = pt->iir;
-	dst[46] = pt->isr;   dst[47] = pt->ior;
-	dst[48] = mfctl(22); dst[49] = mfctl(0);
-	dst[50] = mfctl(24); dst[51] = mfctl(25);
-	dst[52] = mfctl(26); dst[53] = mfctl(27);
-	dst[54] = mfctl(28); dst[55] = mfctl(29);
-	dst[56] = mfctl(30); dst[57] = mfctl(31);
-	dst[58] = mfctl( 8); dst[59] = mfctl( 9);
-	dst[60] = mfctl(12); dst[61] = mfctl(13);
-	dst[62] = mfctl(10); dst[63] = mfctl(15);
-}
-
 /* Note that "fork()" is implemented in terms of clone, with
    parameters (SIGCHLD, regs->gr[30], regs). */
 int
Index: arch/parisc64/kernel/binfmt_elf32.c
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc64/kernel/binfmt_elf32.c,v
retrieving revision 1.3
diff -u -p -r1.3 binfmt_elf32.c
--- binfmt_elf32.c	2000/12/19 23:56:50	1.3
+++ binfmt_elf32.c	2001/02/12 18:34:31
@@ -8,60 +8,12 @@
  * (ia64,sparc64/mips64)
  */
 
-/* Make sure include/asm-parisc/elf.h doesn't get included */
+/* Make sure include/asm-parisc/elf.h does the right thing */
 
-#define __ASMPARISC_ELF_H
-
-#define EM_PARISC 15
-
 #define ELF_CLASS	ELFCLASS32
-#define ELF_DATA	ELFDATA2MSB
-#define ELF_ARCH	EM_PARISC
-
-/*
- * ELF register definitions..
- */
-
-#define ELF_NGREG 32
-#define ELF_NFPREG 32
 
-typedef unsigned long elf_greg_t;
-typedef elf_greg_t elf_gregset_t[ELF_NGREG];
-
-typedef double elf_fpreg_t;
-typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
-
-#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));
-
-/*
- * This is used to ensure we don't load something for the wrong architecture.
- *
- * This version is for an alternate elf binary handler to support 32 bit
- * parisc binaries on a 64 bit kernel.
- */
+typedef unsigned int elf_greg_t;
 
-
-#define elf_check_arch(x) ((x)->e_machine == EM_PARISC && (x)->e_ident[EI_CLASS] == ELF_CLASS)
-
-
-/* %r23 is set by ld.so to a pointer to a function which might be 
-   registered using atexit.  This provides a mean for the dynamic
-   linker to call DT_FINI functions for shared libraries that have
-   been loaded before the code runs.
-
-   So that we can use the same startup file with static executables,
-   we start programs with a value of 0 to indicate that there is no
-   such function.  */
-#define ELF_PLAT_INIT(_r)       _r->gr[23] = 0
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE	4096
-
-#define ELF_ET_DYN_BASE         0x80000000
-
 #include <asm/processor.h>
 #include <linux/module.h>
 #include <linux/config.h>
@@ -103,21 +55,11 @@ struct elf_prpsinfo32
 	char	pr_psargs[ELF_PRARGSZ];	/* initial part of arg list */
 };
 
-#include <linux/highuid.h>
-
-#undef NEW_TO_OLD_UID
-#undef NEW_TO_OLD_GID
-#define NEW_TO_OLD_UID(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
-#define NEW_TO_OLD_GID(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
-
 #define elf_addr_t	unsigned int
 typedef unsigned int elf_caddr_t;
 #define init_elf_binfmt init_elf32_binfmt
-
-#define ELF_HWCAP	0
-/* (boot_cpu_data.x86_capability) */
 
-#define ELF_PLATFORM  ("PARISC32\0" /*+((boot_cpu_data.x86-3)*5) */)
+#define ELF_PLATFORM  ("PARISC32\0")
 
 /*
  * We should probably use this macro to set a flag somewhere to indicate
@@ -125,9 +67,7 @@ typedef unsigned int elf_caddr_t;
  * could set a processor dependent flag in the thread_struct.
  */
 
-#ifdef __KERNEL__
 #define SET_PERSONALITY(ex, ibcs2) \
 	current->personality = PER_LINUX_32BIT
-#endif
 
 #include "../../../fs/binfmt_elf.c"
Index: arch/parisc64/kernel/sys32.h
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc64/kernel/sys32.h,v
retrieving revision 1.4
diff -u -p -r1.4 sys32.h
--- sys32.h	2001/02/02 15:49:08	1.4
+++ sys32.h	2001/02/12 18:34:31
@@ -2,7 +2,7 @@
 #define _PARISC64_KERNEL_SYS32_H
 
 /* Call a kernel syscall which will use kernel space instead of user
- * space for it's copy_to/from_user.
+ * space for its copy_to/from_user.
  */
 #define KERNEL_SYSCALL(ret, syscall, args...) \
 { \
Index: include/asm-parisc/elf.h
===================================================================
RCS file: /home/cvs/parisc/linux/include/asm-parisc/elf.h,v
retrieving revision 1.12
diff -u -p -r1.12 elf.h
--- elf.h	2000/12/21 12:27:28	1.12
+++ elf.h	2001/02/12 18:34:32
@@ -9,19 +9,13 @@
 
 #define EM_PARISC 15
 
-#define ELF_NGREG 80	/* We only need 64 at present, but leave space
-			   for expansion. */
-#define ELF_NFPREG 32
-
-typedef unsigned long elf_greg_t;
-typedef elf_greg_t elf_gregset_t[ELF_NGREG];
-
-typedef double elf_fpreg_t;
-typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
-
-struct pt_regs;	/* forward declaration... */
-extern void parisc_elf_core_copy_regs (struct pt_regs *src, elf_gregset_t dst);
-#define ELF_CORE_COPY_REGS(_dest,_regs)	parisc_elf_core_copy_regs(_regs, _dest);
+/*
+ * The following definitions are those for 32-bit ELF binaries on a 32-bit kernel
+ * and for 64-bit binaries on a 64-bit kernel.  To run 32-bit binaries on a 64-bit
+ * kernel, arch/parisc64/kernel/binfmt_elf32.c defines these macros appropriately
+ * and then #includes binfmt_elf.c, which then includes this file.
+ */
+#ifndef ELF_CLASS
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
@@ -30,16 +24,84 @@ extern void parisc_elf_core_copy_regs (s
  * the following macros are for the default case. However, for the 64
  * bit kernel we also support 32 bit parisc binaries. To do that
  * arch/parisc64/kernel/binfmt_elf32.c defines its own set of these
- * macros, and then if includes fs/binfmt_elf.c to provide an alternate
+ * macros, and then it includes fs/binfmt_elf.c to provide an alternate
  * elf binary handler for 32 bit binaries (on the 64 bit kernel).
  */
-
 #ifdef __LP64__
 #define ELF_CLASS       ELFCLASS64
 #else
 #define ELF_CLASS	ELFCLASS32
 #endif
 
+typedef unsigned long elf_greg_t;
+
+/* This yields a string that ld.so will use to load implementation
+   specific libraries for optimization.  This is more specific in
+   intent than poking at uname or /proc/cpuinfo.
+
+   For the moment, we have only optimizations for the Intel generations,
+   but that could change... */
+
+#define ELF_PLATFORM  ("PARISC\0" /*+((boot_cpu_data.x86-3)*5) */)
+
+#ifdef __KERNEL__
+#define SET_PERSONALITY(ex, ibcs2) \
+	current->personality = PER_LINUX
+#endif
+
+#endif /* ! ELF_CLASS */
+
+#define ELF_NGREG 80	/* We only need 64 at present, but leave space
+			   for expansion. */
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+#define ELF_NFPREG 32
+typedef double elf_fpreg_t;
+typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+struct pt_regs;	/* forward declaration... */
+
+/*
+ * Fill in general registers in a core dump.  This saves pretty
+ * much the same registers as hp-ux, although in a different order.
+ * Registers marked # below are not currently saved in pt_regs, so
+ * we use their current values here.
+ *
+ * 	gr0..gr31
+ * 	sr0..sr7
+ * 	iaoq0..iaoq1
+ * 	iasq0..iasq1
+ * 	cr11 (sar)
+ * 	cr19 (iir)
+ * 	cr20 (isr)
+ * 	cr21 (ior)
+ *  #	cr22 (ipsw)
+ *  #	cr0 (recovery counter)
+ *  #	cr24..cr31 (temporary registers)
+ *  #	cr8,9,12,13 (protection IDs)
+ *  #	cr10 (scr/ccr)
+ *  #	cr15 (ext int enable mask)
+ *
+ */
+
+#define ELF_CORE_COPY_REGS(dst, pt)	\
+	memset(dst, 0, sizeof(dst));	/* don't leak any "random" bits */ \
+	memcpy(dst + 0, pt->gr, 32 * sizeof(elf_greg_t)); \
+	memcpy(dst + 32, pt->sr, 8 * sizeof(elf_greg_t)); \
+	memcpy(dst + 40, pt->iaoq, 2 * sizeof(elf_greg_t)); \
+	memcpy(dst + 42, pt->iasq, 2 * sizeof(elf_greg_t)); \
+	dst[44] = pt->sar;   dst[45] = pt->iir; \
+	dst[46] = pt->isr;   dst[47] = pt->ior; \
+	dst[48] = mfctl(22); dst[49] = mfctl(0); \
+	dst[50] = mfctl(24); dst[51] = mfctl(25); \
+	dst[52] = mfctl(26); dst[53] = mfctl(27); \
+	dst[54] = mfctl(28); dst[55] = mfctl(29); \
+	dst[56] = mfctl(30); dst[57] = mfctl(31); \
+	dst[58] = mfctl( 8); dst[59] = mfctl( 9); \
+	dst[60] = mfctl(12); dst[61] = mfctl(13); \
+	dst[62] = mfctl(10); dst[63] = mfctl(15);
+
+
 #define elf_check_arch(x) ((x)->e_machine == EM_PARISC && (x)->e_ident[EI_CLASS] == ELF_CLASS)
 
 /*
@@ -79,19 +141,5 @@ extern void parisc_elf_core_copy_regs (s
 
 #define ELF_HWCAP	0
 /* (boot_cpu_data.x86_capability) */
-
-/* This yields a string that ld.so will use to load implementation
-   specific libraries for optimization.  This is more specific in
-   intent than poking at uname or /proc/cpuinfo.
-
-   For the moment, we have only optimizations for the Intel generations,
-   but that could change... */
-
-#define ELF_PLATFORM  ("PARISC\0" /*+((boot_cpu_data.x86-3)*5) */)
-
-#ifdef __KERNEL__
-#define SET_PERSONALITY(ex, ibcs2) \
-	current->personality = PER_LINUX
-#endif
 
 #endif