Module Name: src
Committed By: matt
Date: Wed Apr 2 17:19:49 UTC 2014
Modified Files:
src/sys/kern: core_elf32.c
Log Message:
If we are writing PN_XNUM or more phdrs, include one section header and
encode the real # of sections in its sh_info.
To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/kern/core_elf32.c
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.44 src/sys/kern/core_elf32.c:1.45
--- src/sys/kern/core_elf32.c:1.44 Sun Jan 5 09:13:18 2014
+++ src/sys/kern/core_elf32.c Wed Apr 2 17:19:49 2014
@@ -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 @@ int
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 @@ ELFNAMEEND(coredump)(struct lwp *l, stru
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 @@ ELFNAMEEND(coredump)(struct lwp *l, stru
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);