Source-Changes-HG archive

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

[src/trunk]: src/sys/kern If we are writing PN_XNUM or more phdrs, include on...



details:   https://anonhg.NetBSD.org/src/rev/4cd453fe76db
branches:  trunk
changeset: 795148:4cd453fe76db
user:      matt <matt%NetBSD.org@localhost>
date:      Wed Apr 02 17:19:49 2014 +0000

description:
If we are writing PN_XNUM or more phdrs, include one section header and
encode the real # of sections in its sh_info.

diffstat:

 sys/kern/core_elf32.c |  36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diffs (75 lines):

diff -r aba600371b00 -r 4cd453fe76db sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c     Wed Apr 02 17:09:23 2014 +0000
+++ b/sys/kern/core_elf32.c     Wed Apr 02 17:19:49 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: core_elf32.c,v 1.44 2014/01/05 09:13:18 dsl Exp $      */
+/*     $NetBSD: core_elf32.c,v 1.45 2014/04/02 17:19:49 matt Exp $     */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.44 2014/01/05 09:13:18 dsl Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.45 2014/04/02 17:19:49 matt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -106,6 +106,7 @@
 ELFNAMEEND(coredump)(struct lwp *l, struct coredump_iostate *cookie)
 {
        Elf_Ehdr ehdr;
+       Elf_Shdr shdr;
        Elf_Phdr *psections;
        size_t psectionssize;
        int npsections;
@@ -165,14 +166,22 @@
        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 = npsections;
-       ehdr.e_shentsize = 0;
-       ehdr.e_shnum = 0;
+       if (npsections < PN_XNUM) {
+               ehdr.e_phnum = 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
@@ -184,8 +193,19 @@
        if (error)
                goto out;
 
+       /* Write out sections, if needed */
+       if (npsections >= PN_XNUM) {
+               memset(&shdr, 0, sizeof(shdr));
+               shdr.sh_type = SHT_NULL;
+               shdr.sh_info = npsections;
+               error = coredump_write(cookie, UIO_SYSSPACE, &shdr,
+                   sizeof(shdr));
+               if (error)
+                       goto out;
+       }
+
        psectionssize = npsections * sizeof(*psections);
-       notestart = sizeof(ehdr) + psectionssize;
+       notestart = ehdr.e_phoff + psectionssize;
 
        psections = kmem_zalloc(psectionssize, KM_SLEEP);
 



Home | Main Index | Thread Index | Old Index