Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add support for dumping ELF-cormat core files.



details:   https://anonhg.NetBSD.org/src/rev/aca782203ddc
branches:  trunk
changeset: 519027:aca782203ddc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Dec 09 23:05:56 2001 +0000

description:
Add support for dumping ELF-cormat core files.

diffstat:

 sys/arch/alpha/include/elf_machdep.h   |    4 +-
 sys/arch/arm/include/elf_machdep.h     |    4 +-
 sys/arch/i386/include/elf_machdep.h    |    4 +-
 sys/arch/m68k/include/elf_machdep.h    |    4 +-
 sys/arch/mips/include/elf_machdep.h    |    5 +-
 sys/arch/powerpc/include/elf_machdep.h |    4 +-
 sys/arch/sh3/include/elf_machdep.h     |    4 +-
 sys/arch/sparc/include/elf_machdep.h   |    4 +-
 sys/arch/sparc64/include/elf_machdep.h |    5 +-
 sys/arch/sun2/include/elf_machdep.h    |    5 +-
 sys/arch/vax/include/elf_machdep.h     |    4 +-
 sys/arch/x86_64/include/elf_machdep.h  |    5 +-
 sys/kern/core_elf32.c                  |  427 +++++++++++++++++++++++++++++++++
 sys/kern/core_elf64.c                  |   43 +++
 sys/sys/exec_elf.h                     |   64 ++++-
 15 files changed, 573 insertions(+), 13 deletions(-)

diffs (truncated from 786 to 300 lines):

diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/alpha/include/elf_machdep.h
--- a/sys/arch/alpha/include/elf_machdep.h      Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/alpha/include/elf_machdep.h      Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: elf_machdep.h,v 1.9 2001/11/01 12:54:35 drochner Exp $ */
+/* $NetBSD: elf_machdep.h,v 1.10 2001/12/09 23:05:56 thorpej Exp $ */
 
 #ifndef        _ALPHA_ELF_MACHDEP_H_
 #define        _ALPHA_ELF_MACHDEP_H_
@@ -22,6 +22,8 @@
                case EM_ALPHA_EXP:                                      \
                        break;
 
+#define        ELF64_MACHDEP_ID        EM_ALPHA_EXP    /* XXX */
+
 #define ARCH_ELFSIZE           64      /* MD native binary size */
 
 /*
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/arm/include/elf_machdep.h
--- a/sys/arch/arm/include/elf_machdep.h        Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/arm/include/elf_machdep.h        Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.2 2001/01/18 23:50:50 bjh21 Exp $    */
+/*     $NetBSD: elf_machdep.h,v 1.3 2001/12/09 23:05:57 thorpej Exp $  */
 
 #define ELF32_MACHDEP_ENDIANNESS       ELFDATA2LSB
 
@@ -22,6 +22,8 @@
                case EM_ARM:                                            \
                        break;
 
+#define        ELF32_MACHDEP_ID        EM_ARM
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 /* Processor specific relocation types */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/i386/include/elf_machdep.h
--- a/sys/arch/i386/include/elf_machdep.h       Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/i386/include/elf_machdep.h       Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.8 2000/04/02 15:35:49 minoura Exp $  */
+/*     $NetBSD: elf_machdep.h,v 1.9 2001/12/09 23:05:57 thorpej Exp $  */
 
 #define        ELF32_MACHDEP_ENDIANNESS        ELFDATA2LSB
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -10,6 +10,8 @@
 #define        ELF64_MACHDEP_ID_CASES                                          \
                /* no 64-bit ELF machine types supported */
 
+#define        ELF32_MACHDEP_ID                EM_386
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 /* i386 relocations */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/m68k/include/elf_machdep.h
--- a/sys/arch/m68k/include/elf_machdep.h       Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/m68k/include/elf_machdep.h       Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.5 2000/04/02 15:35:49 minoura Exp $  */
+/*     $NetBSD: elf_machdep.h,v 1.6 2001/12/09 23:05:57 thorpej Exp $  */
 
 #define        ELF32_MACHDEP_ENDIANNESS        ELFDATA2MSB
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -9,6 +9,8 @@
 #define        ELF64_MACHDEP_ID_CASES                                          \
                /* no 64-bit ELF machine types supported */
 
+#define        ELF32_MACHDEP_ID        EM_68K
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 /* m68k relocation types */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/mips/include/elf_machdep.h
--- a/sys/arch/mips/include/elf_machdep.h       Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/mips/include/elf_machdep.h       Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.7 2000/04/02 15:35:50 minoura Exp $  */
+/*     $NetBSD: elf_machdep.h,v 1.8 2001/12/09 23:05:58 thorpej Exp $  */
 
 #define        ELF32_MACHDEP_ID_CASES                                          \
                case EM_MIPS:                                           \
@@ -8,6 +8,9 @@
                /* no 64-bit ELF machine types supported */
 
 
+#define        ELF32_MACHDEP_ID        EM_MIPS
+#define        ELF64_MACHDEP_ID        EM_MIPS
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 /* mips relocs.  */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/powerpc/include/elf_machdep.h
--- a/sys/arch/powerpc/include/elf_machdep.h    Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/powerpc/include/elf_machdep.h    Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.4 2000/04/02 15:35:50 minoura Exp $  */
+/*     $NetBSD: elf_machdep.h,v 1.5 2001/12/09 23:05:58 thorpej Exp $  */
 
 #define        ELF32_MACHDEP_ENDIANNESS        ELFDATA2MSB
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -9,6 +9,8 @@
 #define        ELF64_MACHDEP_ID_CASES                                          \
                /* no 64-bit ELF machine types supported */
 
+#define        ELF32_MACHDEP_ID        EM_PPC
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 #include <machine/reloc.h>             /* XXX */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/sh3/include/elf_machdep.h
--- a/sys/arch/sh3/include/elf_machdep.h        Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/sh3/include/elf_machdep.h        Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.4 2001/03/29 03:23:33 marcus Exp $   */
+/*     $NetBSD: elf_machdep.h,v 1.5 2001/12/09 23:05:58 thorpej Exp $  */
 
 #ifndef _BYTE_ORDER
 #error Define _BYTE_ORDER!
@@ -17,4 +17,6 @@
 #define        ELF64_MACHDEP_ID_CASES                                          \
                /* no 64-bit ELF machine types supported */
 
+#define        ELF32_MACHDEP_ID        EM_SH
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/sparc/include/elf_machdep.h
--- a/sys/arch/sparc/include/elf_machdep.h      Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/sparc/include/elf_machdep.h      Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.5 2000/04/02 15:35:50 minoura Exp $  */
+/*     $NetBSD: elf_machdep.h,v 1.6 2001/12/09 23:05:58 thorpej Exp $  */
 
 #define ELF32_MACHDEP_ENDIANNESS       ELFDATA2MSB
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -12,6 +12,8 @@
                case EM_SPARCV9:                                        \
                /* no 64-bit ELF machine types supported */
 
+#define        ELF32_MACHDEP_ID        EM_SPARC        /* XXX right? */
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 #define R_SPARC_NONE           0
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/sparc64/include/elf_machdep.h
--- a/sys/arch/sparc64/include/elf_machdep.h    Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/sparc64/include/elf_machdep.h    Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.7 2001/02/11 00:18:49 eeh Exp $      */
+/*     $NetBSD: elf_machdep.h,v 1.8 2001/12/09 23:05:58 thorpej Exp $  */
 
 #define ELF32_MACHDEP_ENDIANNESS       ELFDATA2MSB
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -12,6 +12,9 @@
                case EM_SPARCV9:                                        \
                        break;
 
+#define        ELF32_MACHDEP_ID        EM_SPARC32PLUS  /* XXX right? */
+#define        ELF64_MACHDEP_ID        EM_SPARCV9      /* XXX right? */
+
 #ifdef __arch64__
 #define ARCH_ELFSIZE           64      /* MD native binary size */
 #else
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/sun2/include/elf_machdep.h
--- a/sys/arch/sun2/include/elf_machdep.h       Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/sun2/include/elf_machdep.h       Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.2 2001/06/27 19:20:22 fredette Exp $ */
+/*     $NetBSD: elf_machdep.h,v 1.3 2001/12/09 23:05:59 thorpej Exp $  */
 
 #ifndef _MACHINE_ELF_MACHDEP_H_
 #define _MACHINE_ELF_MACHDEP_H_
@@ -10,4 +10,7 @@
                 case EM_68000:                                         \
                         break;
 
+#undef ELF32_MACHDEP_ID
+#define        ELF32_MACHDEP_ID        EM_68000
+
 #endif
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/vax/include/elf_machdep.h
--- a/sys/arch/vax/include/elf_machdep.h        Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/vax/include/elf_machdep.h        Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.4 2000/07/13 03:18:22 matt Exp $     */
+/*     $NetBSD: elf_machdep.h,v 1.5 2001/12/09 23:05:59 thorpej Exp $  */
 
 #define        ELF32_MACHDEP_ENDIANNESS        ELFDATA2LSB
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -9,6 +9,8 @@
 #define        ELF64_MACHDEP_ID_CASES                                          \
                /* no 64-bit ELF machine types supported */
 
+#define        ELF32_MACHDEP_ID        EM_VAX
+
 #define ARCH_ELFSIZE           32      /* MD native binary size */
 
 /* VAX relocations */
diff -r 67e6f46f03d2 -r aca782203ddc sys/arch/x86_64/include/elf_machdep.h
--- a/sys/arch/x86_64/include/elf_machdep.h     Sun Dec 09 22:56:10 2001 +0000
+++ b/sys/arch/x86_64/include/elf_machdep.h     Sun Dec 09 23:05:56 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elf_machdep.h,v 1.2 2001/06/20 01:20:33 fvdl Exp $     */
+/*     $NetBSD: elf_machdep.h,v 1.3 2001/12/09 23:05:59 thorpej Exp $  */
 
 #define        ELF32_MACHDEP_ENDIANNESS
 #define        ELF32_MACHDEP_ID_CASES                                          \
@@ -10,6 +10,9 @@
                case EM_X86_64:                                         \
                        break;
 
+#define        ELF32_MACHDEP_ID        EM_386
+#define        ELF64_MACHDEP_ID        EM_X86_64
+
 #define ARCH_ELFSIZE           64      /* MD native binary size */
 
 /* x86-64 relocations */
diff -r 67e6f46f03d2 -r aca782203ddc sys/kern/core_elf32.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/kern/core_elf32.c     Sun Dec 09 23:05:56 2001 +0000
@@ -0,0 +1,427 @@
+/*     $NetBSD: core_elf32.c,v 1.1 2001/12/09 23:05:59 thorpej Exp $   */
+
+/*
+ * Copyright (c) 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed for the NetBSD Project by
+ *     Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.1 2001/12/09 23:05:59 thorpej Exp $");
+
+/* If not included by core_elf64.c, ELFSIZE won't be defined. */
+#ifndef ELFSIZE
+#define        ELFSIZE         32
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+#include <sys/exec_elf.h>
+#include <sys/ptrace.h>
+
+#include <machine/reg.h>
+
+#include <uvm/uvm.h>
+
+int    ELFNAMEEND(coredump_notes)(struct proc *, struct vnode *,
+           struct ucred *, int *, off_t);
+
+#define        ELFROUNDSIZE    4       /* XXX Should it be sizeof(Elf_Word)? */
+#define        elfround(x)     roundup((x), ELFROUNDSIZE)
+
+int
+ELFNAMEEND(coredump)(struct proc *p, struct vnode *vp, struct ucred *cred)
+{
+       Elf_Ehdr ehdr;
+       Elf_Phdr phdr;
+       struct vmspace *vm = p->p_vmspace;
+       struct vm_map *map = &vm->vm_map;
+       struct vm_map_entry *entry;
+       vaddr_t start, end, maxstack;
+       vsize_t size;
+       off_t offset, secoff, notestart, secstart;
+       int npsections, notesize, error;
+
+       maxstack = trunc_page(USRSTACK - ctob(vm->vm_ssize));



Home | Main Index | Thread Index | Old Index