Module Name: src Committed By: dsl Date: Fri Jan 3 21:34:40 UTC 2014
Modified Files: src/sys/kern: core_elf32.c src/sys/sys: exec_elf.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sys/kern/core_elf32.c cvs rdiff -u -r1.136 -r1.137 src/sys/sys/exec_elf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/core_elf32.c diff -u src/sys/kern/core_elf32.c:1.40 src/sys/kern/core_elf32.c:1.41 --- src/sys/kern/core_elf32.c:1.40 Fri Jan 3 21:12:18 2014 +++ src/sys/kern/core_elf32.c Fri Jan 3 21:34:40 2014 @@ -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 @@ ELFNAMEEND(coredump)(struct lwp *l, stru 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 @@ ELFNAMEEND(coredump_notes)(struct lwp *l { struct proc *p; struct netbsd_elfcore_procinfo cpi; - Elf_Nhdr nhdr; int error; struct lwp *l0; sigset_t ss1, ss2; @@ -378,12 +378,8 @@ ELFNAMEEND(coredump_notes)(struct lwp *l (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 @@ ELFNAMEEND(coredump_notes)(struct lwp *l 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 @@ ELFNAMEEND(coredump_note)(struct lwp *l, 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 @@ ELFNAMEEND(coredump_note)(struct lwp *l, 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 @@ save_note_bytes(struct note_state *ns, c } 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 */ Index: src/sys/sys/exec_elf.h diff -u src/sys/sys/exec_elf.h:1.136 src/sys/sys/exec_elf.h:1.137 --- src/sys/sys/exec_elf.h:1.136 Fri Jan 3 20:52:47 2014 +++ src/sys/sys/exec_elf.h Fri Jan 3 21:34:40 2014 @@ -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 @@ int elf32_copyargs(struct lwp *, struct 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 @@ int elf64_copyargs(struct lwp *, struct 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