Sun Jan 5 09:13:18 2014 UTC ()
Fix previous slightly differently.
No need to have an extra variable and to write to the list head.


(dsl)
diff -r1.43 -r1.44 src/sys/kern/core_elf32.c

cvs diff -r1.43 -r1.44 src/sys/kern/core_elf32.c (expand / switch to unified diff)

--- src/sys/kern/core_elf32.c 2014/01/05 00:53:53 1.43
+++ src/sys/kern/core_elf32.c 2014/01/05 09:13:18 1.44
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: core_elf32.c,v 1.43 2014/01/05 00:53:53 mrg Exp $ */ 1/* $NetBSD: core_elf32.c,v 1.44 2014/01/05 09:13:18 dsl Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38/* 38/*
39 * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format. 39 * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format.
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.43 2014/01/05 00:53:53 mrg Exp $"); 43__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.44 2014/01/05 09:13:18 dsl Exp $");
44 44
45#ifdef _KERNEL_OPT 45#ifdef _KERNEL_OPT
46#include "opt_coredump.h" 46#include "opt_coredump.h"
47#endif 47#endif
48 48
49#ifndef ELFSIZE 49#ifndef ELFSIZE
50#define ELFSIZE 32 50#define ELFSIZE 32
51#endif 51#endif
52 52
53#include <sys/param.h> 53#include <sys/param.h>
54#include <sys/systm.h> 54#include <sys/systm.h>
55#include <sys/proc.h> 55#include <sys/proc.h>
56#include <sys/vnode.h> 56#include <sys/vnode.h>
@@ -106,27 +106,26 @@ int @@ -106,27 +106,26 @@ int
106ELFNAMEEND(coredump)(struct lwp *l, struct coredump_iostate *cookie) 106ELFNAMEEND(coredump)(struct lwp *l, struct coredump_iostate *cookie)
107{ 107{
108 Elf_Ehdr ehdr; 108 Elf_Ehdr ehdr;
109 Elf_Phdr *psections; 109 Elf_Phdr *psections;
110 size_t psectionssize; 110 size_t psectionssize;
111 int npsections; 111 int npsections;
112 struct writesegs_state ws; 112 struct writesegs_state ws;
113 off_t notestart; 113 off_t notestart;
114 size_t notesize; 114 size_t notesize;
115 int error, i; 115 int error, i;
116 116
117 struct note_state ns; 117 struct note_state ns;
118 struct note_buf *nb; 118 struct note_buf *nb;
119 struct note_buf *nb_next; 
120 119
121 psections = NULL; 120 psections = NULL;
122 121
123 /* Get all of the notes (mostly all the registers). */ 122 /* Get all of the notes (mostly all the registers). */
124 ns.ns_first = kmem_alloc(sizeof *ns.ns_first, KM_SLEEP); 123 ns.ns_first = kmem_alloc(sizeof *ns.ns_first, KM_SLEEP);
125 ns.ns_last = ns.ns_first; 124 ns.ns_last = ns.ns_first;
126 ns.ns_count = 0; 125 ns.ns_count = 0;
127 ns.ns_offset = 0; 126 ns.ns_offset = 0;
128 error = ELFNAMEEND(coredump_notes)(l, &ns); 127 error = ELFNAMEEND(coredump_notes)(l, &ns);
129 ns.ns_last->nb_next = NULL; 128 ns.ns_last->nb_next = NULL;
130 if (error) 129 if (error)
131 goto out; 130 goto out;
132 notesize = ns.ns_count * sizeof nb->nb_data + ns.ns_offset; 131 notesize = ns.ns_count * sizeof nb->nb_data + ns.ns_offset;
@@ -247,28 +246,28 @@ ELFNAMEEND(coredump)(struct lwp *l, stru @@ -247,28 +246,28 @@ ELFNAMEEND(coredump)(struct lwp *l, stru
247 (long long) psections[i].p_filesz); 246 (long long) psections[i].p_filesz);
248#endif 247#endif
249 248
250 error = coredump_write(cookie, UIO_USERSPACE, 249 error = coredump_write(cookie, UIO_USERSPACE,
251 (void *)(vaddr_t)psections[i].p_vaddr, 250 (void *)(vaddr_t)psections[i].p_vaddr,
252 psections[i].p_filesz); 251 psections[i].p_filesz);
253 if (error) 252 if (error)
254 goto out; 253 goto out;
255 } 254 }
256 255
257 out: 256 out:
258 if (psections) 257 if (psections)
259 kmem_free(psections, psectionssize); 258 kmem_free(psections, psectionssize);
260 for (; (nb = ns.ns_first) != NULL; ns.ns_first = nb_next) { 259 while ((nb = ns.ns_first) != NULL) {
261 nb_next = nb->nb_next; 260 ns.ns_first = nb->nb_next;
262 kmem_free(nb, sizeof *nb); 261 kmem_free(nb, sizeof *nb);
263 } 262 }
264 return (error); 263 return (error);
265} 264}
266 265
267static int 266static int
268ELFNAMEEND(coredump_getseghdrs)(struct uvm_coredump_state *us) 267ELFNAMEEND(coredump_getseghdrs)(struct uvm_coredump_state *us)
269{ 268{
270 struct writesegs_state *ws = us->cookie; 269 struct writesegs_state *ws = us->cookie;
271 Elf_Phdr phdr; 270 Elf_Phdr phdr;
272 vsize_t size, realsize; 271 vsize_t size, realsize;
273 vaddr_t end; 272 vaddr_t end;
274 int error; 273 int error;