Module Name: src Committed By: matt Date: Wed Apr 2 17:34:51 UTC 2014
Modified Files: src/sys/kern [matt-nb5-mips64]: core_elf32.c src/sys/sys [matt-nb5-mips64]: exec_elf.h Log Message: Support coredumps with >= 65535 psections. To generate a diff of this commit: cvs rdiff -u -r1.32.16.2 -r1.32.16.3 src/sys/kern/core_elf32.c cvs rdiff -u -r1.95 -r1.95.14.1 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.32.16.2 src/sys/kern/core_elf32.c:1.32.16.3 --- src/sys/kern/core_elf32.c:1.32.16.2 Sun Aug 23 03:38:19 2009 +++ src/sys/kern/core_elf32.c Wed Apr 2 17:34:51 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: core_elf32.c,v 1.32.16.2 2009/08/23 03:38:19 matt Exp $ */ +/* $NetBSD: core_elf32.c,v 1.32.16.3 2014/04/02 17:34:51 matt Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -40,7 +40,11 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.32.16.2 2009/08/23 03:38:19 matt Exp $"); +__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.32.16.3 2014/04/02 17:34:51 matt Exp $"); + +#ifdef _KERNEL_OPT +#include "opt_coredump.h" +#endif /* If not included by core_elf64.c, ELFSIZE won't be defined. */ #ifndef ELFSIZE @@ -98,7 +102,8 @@ ELFNAMEEND(coredump)(struct lwp *l, void { struct proc *p; Elf_Ehdr ehdr; - Elf_Phdr phdr, *psections; + Elf_Shdr shdr; + Elf_Phdr *psections; struct countsegs_state cs; struct writesegs_state ws; off_t notestart, secstart, offset; @@ -151,14 +156,22 @@ ELFNAMEEND(coredump)(struct lwp *l, void ehdr.e_machine = ELFDEFNNAME(MACHDEP_ID); ehdr.e_version = EV_CURRENT; ehdr.e_entry = 0; - ehdr.e_phoff = sizeof(ehdr); - ehdr.e_shoff = 0; ehdr.e_flags = 0; ehdr.e_ehsize = sizeof(ehdr); ehdr.e_phentsize = sizeof(Elf_Phdr); - ehdr.e_phnum = cs.npsections; - ehdr.e_shentsize = 0; - ehdr.e_shnum = 0; + if (cs.npsections < PN_XNUM) { + ehdr.e_phnum = cs.npsections; + ehdr.e_shentsize = 0; + ehdr.e_shnum = 0; + ehdr.e_shoff = 0; + ehdr.e_phoff = sizeof(ehdr); + } else { + ehdr.e_phnum = PN_XNUM; + ehdr.e_shentsize = sizeof(Elf_Shdr); + ehdr.e_shnum = 1; + ehdr.e_shoff = sizeof(ehdr); + ehdr.e_phoff = sizeof(ehdr) + sizeof(shdr); + } ehdr.e_shstrndx = 0; #ifdef ELF_MD_COREDUMP_SETUP @@ -170,9 +183,20 @@ ELFNAMEEND(coredump)(struct lwp *l, void if (error) goto out; - offset = sizeof(ehdr); + /* Write out sections, if needed */ + if (cs.npsections >= PN_XNUM) { + memset(&shdr, 0, sizeof(shdr)); + shdr.sh_type = SHT_NULL; + shdr.sh_info = cs.npsections; + error = coredump_write(cookie, UIO_SYSSPACE, &shdr, + sizeof(shdr)); + if (error) + goto out; + } + + offset = ehdr.e_phoff; - notestart = offset + sizeof(phdr) * cs.npsections; + notestart = offset + sizeof(Elf_Phdr) * cs.npsections; secstart = notestart + notesize; psections = malloc(cs.npsections * sizeof(Elf_Phdr), Index: src/sys/sys/exec_elf.h diff -u src/sys/sys/exec_elf.h:1.95 src/sys/sys/exec_elf.h:1.95.14.1 --- src/sys/sys/exec_elf.h:1.95 Mon Apr 28 20:24:10 2008 +++ src/sys/sys/exec_elf.h Wed Apr 2 17:34:51 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.h,v 1.95 2008/04/28 20:24:10 martin Exp $ */ +/* $NetBSD: exec_elf.h,v 1.95.14.1 2014/04/02 17:34:51 matt Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -343,6 +343,9 @@ typedef struct { #define PF_MASKOS 0x0ff00000 /* Operating system specific values */ #define PF_MASKPROC 0xf0000000 /* Processor-specific values */ +/* Extended program header index. */ +#define PN_XNUM 0xffff + /* * Section Headers */