Source-Changes-HG archive

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

[src/trunk]: src/sys Fix bug in previous (panic during process core dump).



details:   https://anonhg.NetBSD.org/src/rev/c21873749e11
branches:  trunk
changeset: 325708:c21873749e11
user:      dsl <dsl%NetBSD.org@localhost>
date:      Fri Jan 03 21:34:40 2014 +0000

description:
Fix bug in previous (panic during process core dump).
Change the interface to ELFNAMEEND(coredump_savenote) so that the caller
  doesn't need to know the type of the elf note header.
Simplifies the calling code somewhat.

diffstat:

 sys/kern/core_elf32.c |  46 +++++++++++++++++++---------------------------
 sys/sys/exec_elf.h    |  10 +++++-----
 2 files changed, 24 insertions(+), 32 deletions(-)

diffs (147 lines):

diff -r 4d9a67117faa -r c21873749e11 sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c     Fri Jan 03 21:21:17 2014 +0000
+++ b/sys/kern/core_elf32.c     Fri Jan 03 21:34:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: core_elf32.c,v 1.40 2014/01/03 21:12:18 dsl Exp $      */
+/*     $NetBSD: core_elf32.c,v 1.41 2014/01/03 21:34:40 dsl Exp $      */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.40 2014/01/03 21:12:18 dsl Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.41 2014/01/03 21:34:40 dsl Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -197,6 +197,7 @@
        ws.secoff = notestart + notesize;
        ws.psections = psections;
        ws.npsections = npsections - 1;
+       ws.p = l->l_proc;
        error = uvm_coredump_walkmap(l->l_proc, ELFNAMEEND(coredump_getseghdrs),
            &ws);
        if (error)
@@ -329,7 +330,6 @@
 {
        struct proc *p;
        struct netbsd_elfcore_procinfo cpi;
-       Elf_Nhdr nhdr;
        int error;
        struct lwp *l0;
        sigset_t ss1, ss2;
@@ -378,12 +378,8 @@
        (void)strncpy(cpi.cpi_name, p->p_comm, sizeof(cpi.cpi_name));
        cpi.cpi_name[sizeof(cpi.cpi_name) - 1] = '\0';
 
-       nhdr.n_namesz = sizeof(ELF_NOTE_NETBSD_CORE_NAME);
-       nhdr.n_descsz = sizeof(cpi);
-       nhdr.n_type = ELF_NOTE_NETBSD_CORE_PROCINFO;
-
-       ELFNAMEEND(coredump_savenote)(ns, &nhdr, ELF_NOTE_NETBSD_CORE_NAME,
-           &cpi);
+       ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_PROCINFO,
+           ELF_NOTE_NETBSD_CORE_NAME, &cpi, sizeof(cpi));
 
        /* XXX Add hook for machdep per-proc notes. */
 
@@ -416,9 +412,7 @@
 static int
 ELFNAMEEND(coredump_note)(struct lwp *l, struct note_state *ns)
 {
-       Elf_Nhdr nhdr;
        int error;
-       int namesize;
        char name[64];
        elf_reg intreg;
 #ifdef PT_GETFPREGS
@@ -428,17 +422,13 @@
 
        snprintf(name, sizeof(name), "%s@%d",
            ELF_NOTE_NETBSD_CORE_NAME, l->l_lid);
-       namesize = strlen(name) + 1;
 
        error = elf_process_read_regs(l, &intreg);
        if (error)
                return (error);
 
-       nhdr.n_namesz = namesize;
-       nhdr.n_descsz = sizeof(intreg);
-       nhdr.n_type = PT_GETREGS;
-
-       ELFNAMEEND(coredump_savenote)(ns, &nhdr, name, &intreg);
+       ELFNAMEEND(coredump_savenote)(ns, PT_GETREGS, name, &intreg,
+           sizeof(intreg));
 
 #ifdef PT_GETFPREGS
        freglen = sizeof(freg);
@@ -450,11 +440,7 @@
        if (error)
                return (error);
 
-       nhdr.n_namesz = namesize;
-       nhdr.n_descsz = freglen;
-       nhdr.n_type = PT_GETFPREGS;
-
-       ELFNAMEEND(coredump_savenote)(ns, &nhdr, name, &freg);
+       ELFNAMEEND(coredump_savenote)(ns, PT_GETFPREGS, name, &freg, freglen);
 #endif
        /* XXX Add hook for machdep per-LWP notes. */
        return (0);
@@ -493,12 +479,18 @@
 }
 
 void
-ELFNAMEEND(coredump_savenote)(struct note_state *ns, Elf_Nhdr *nhdr,
-    const char *name, void *data)
+ELFNAMEEND(coredump_savenote)(struct note_state *ns, unsigned int type,
+    const char *name, void *data, size_t data_len)
 {
-       save_note_bytes(ns, nhdr, sizeof (*nhdr));
-       save_note_bytes(ns, name, nhdr->n_namesz);
-       save_note_bytes(ns, data, nhdr->n_descsz);
+       Elf_Nhdr nhdr;
+
+       nhdr.n_namesz = strlen(name) + 1;
+       nhdr.n_descsz = data_len;
+       nhdr.n_type = type;
+
+       save_note_bytes(ns, &nhdr, sizeof (nhdr));
+       save_note_bytes(ns, name, nhdr.n_namesz);
+       save_note_bytes(ns, data, data_len);
 }
 
 #else  /* COREDUMP */
diff -r 4d9a67117faa -r c21873749e11 sys/sys/exec_elf.h
--- a/sys/sys/exec_elf.h        Fri Jan 03 21:21:17 2014 +0000
+++ b/sys/sys/exec_elf.h        Fri Jan 03 21:34:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.h,v 1.136 2014/01/03 20:52:47 dsl Exp $       */
+/*     $NetBSD: exec_elf.h,v 1.137 2014/01/03 21:34:40 dsl Exp $       */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -1258,8 +1258,8 @@
     struct ps_strings *, char **, void *);
 
 int    coredump_elf32(struct lwp *, struct coredump_iostate *);
-void   coredump_savenote_elf32(struct note_state *, Elf32_Nhdr *,
-           const char *, void *);
+void   coredump_savenote_elf32(struct note_state *, unsigned int,
+           const char *, void *, size_t);
 
 int    elf32_check_header(Elf32_Ehdr *, int);
 #endif
@@ -1270,8 +1270,8 @@
     struct ps_strings *, char **, void *);
 
 int    coredump_elf64(struct lwp *, struct coredump_iostate *);
-void   coredump_savenote_elf64(struct note_state *, Elf64_Nhdr *,
-           const char *, void *);
+void   coredump_savenote_elf64(struct note_state *, unsigned int,
+           const char *, void *, size_t);
 
 int    elf64_check_header(Elf64_Ehdr *, int);
 #endif



Home | Main Index | Thread Index | Old Index