core_elf32.c revision 1.5 1 1.5 atatat /* $NetBSD: core_elf32.c,v 1.5 2003/02/25 05:27:35 atatat Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2001 Wasabi Systems, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 thorpej *
9 1.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1 thorpej * modification, are permitted provided that the following conditions
11 1.1 thorpej * are met:
12 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1 thorpej * must display the following acknowledgement:
19 1.1 thorpej * This product includes software developed for the NetBSD Project by
20 1.1 thorpej * Wasabi Systems, Inc.
21 1.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 thorpej * or promote products derived from this software without specific prior
23 1.1 thorpej * written permission.
24 1.1 thorpej *
25 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1 thorpej */
37 1.1 thorpej
38 1.1 thorpej /*
39 1.1 thorpej * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format.
40 1.1 thorpej */
41 1.1 thorpej
42 1.1 thorpej #include <sys/cdefs.h>
43 1.5 atatat __KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.5 2003/02/25 05:27:35 atatat Exp $");
44 1.1 thorpej
45 1.1 thorpej /* If not included by core_elf64.c, ELFSIZE won't be defined. */
46 1.1 thorpej #ifndef ELFSIZE
47 1.1 thorpej #define ELFSIZE 32
48 1.1 thorpej #endif
49 1.1 thorpej
50 1.1 thorpej #include <sys/param.h>
51 1.1 thorpej #include <sys/systm.h>
52 1.1 thorpej #include <sys/proc.h>
53 1.1 thorpej #include <sys/vnode.h>
54 1.1 thorpej #include <sys/exec_elf.h>
55 1.1 thorpej #include <sys/ptrace.h>
56 1.1 thorpej
57 1.1 thorpej #include <machine/reg.h>
58 1.1 thorpej
59 1.2 thorpej #include <uvm/uvm_extern.h>
60 1.2 thorpej
61 1.2 thorpej struct countsegs_state {
62 1.2 thorpej int npsections;
63 1.2 thorpej };
64 1.2 thorpej
65 1.2 thorpej int ELFNAMEEND(coredump_countsegs)(struct proc *, struct vnode *,
66 1.2 thorpej struct ucred *, struct uvm_coredump_state *);
67 1.2 thorpej
68 1.2 thorpej struct writesegs_state {
69 1.2 thorpej off_t offset;
70 1.2 thorpej off_t secoff;
71 1.2 thorpej };
72 1.2 thorpej
73 1.2 thorpej int ELFNAMEEND(coredump_writeseghdrs)(struct proc *, struct vnode *,
74 1.2 thorpej struct ucred *, struct uvm_coredump_state *);
75 1.2 thorpej int ELFNAMEEND(coredump_writesegs)(struct proc *, struct vnode *,
76 1.2 thorpej struct ucred *, struct uvm_coredump_state *);
77 1.1 thorpej
78 1.1 thorpej int ELFNAMEEND(coredump_notes)(struct proc *, struct vnode *,
79 1.1 thorpej struct ucred *, int *, off_t);
80 1.1 thorpej
81 1.1 thorpej #define ELFROUNDSIZE 4 /* XXX Should it be sizeof(Elf_Word)? */
82 1.1 thorpej #define elfround(x) roundup((x), ELFROUNDSIZE)
83 1.1 thorpej
84 1.1 thorpej int
85 1.4 thorpej ELFNAMEEND(coredump)(struct lwp *l, struct vnode *vp, struct ucred *cred)
86 1.1 thorpej {
87 1.4 thorpej struct proc *p;
88 1.1 thorpej Elf_Ehdr ehdr;
89 1.1 thorpej Elf_Phdr phdr;
90 1.2 thorpej struct countsegs_state cs;
91 1.2 thorpej struct writesegs_state ws;
92 1.2 thorpej off_t notestart, secstart;
93 1.2 thorpej int notesize, error;
94 1.1 thorpej
95 1.4 thorpej p = l->l_proc;
96 1.1 thorpej /*
97 1.1 thorpej * We have to make a total of 3 passes across the map:
98 1.1 thorpej *
99 1.1 thorpej * 1. Count the number of map entries (the number of
100 1.1 thorpej * PT_LOAD sections).
101 1.1 thorpej *
102 1.1 thorpej * 2. Write the P-section headers.
103 1.1 thorpej *
104 1.1 thorpej * 3. Write the P-sections.
105 1.1 thorpej */
106 1.1 thorpej
107 1.1 thorpej /* Pass 1: count the entries. */
108 1.2 thorpej cs.npsections = 0;
109 1.2 thorpej error = uvm_coredump_walkmap(p, vp, cred,
110 1.2 thorpej ELFNAMEEND(coredump_countsegs), &cs);
111 1.2 thorpej if (error)
112 1.2 thorpej return (error);
113 1.1 thorpej
114 1.1 thorpej /* Get the size of the notes. */
115 1.1 thorpej error = ELFNAMEEND(coredump_notes)(p, vp, cred, ¬esize, 0);
116 1.1 thorpej if (error)
117 1.1 thorpej return (error);
118 1.1 thorpej
119 1.1 thorpej /* Count the PT_NOTE section. */
120 1.2 thorpej cs.npsections++;
121 1.1 thorpej
122 1.1 thorpej memcpy(ehdr.e_ident, ELFMAG, SELFMAG);
123 1.1 thorpej #if ELFSIZE == 32
124 1.1 thorpej ehdr.e_ident[EI_CLASS] = ELFCLASS32;
125 1.1 thorpej #elif ELFSIZE == 64
126 1.1 thorpej ehdr.e_ident[EI_CLASS] = ELFCLASS64;
127 1.1 thorpej #endif
128 1.1 thorpej ehdr.e_ident[EI_DATA] = ELFDEFNNAME(MACHDEP_ENDIANNESS);
129 1.1 thorpej ehdr.e_ident[EI_VERSION] = EV_CURRENT;
130 1.1 thorpej /* XXX Should be the OSABI/ABI version of the executable. */
131 1.1 thorpej ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV;
132 1.2 thorpej ehdr.e_ident[EI_ABIVERSION] = 0;
133 1.1 thorpej
134 1.1 thorpej ehdr.e_type = ET_CORE;
135 1.1 thorpej /* XXX This should be the e_machine of the executable. */
136 1.1 thorpej ehdr.e_machine = ELFDEFNNAME(MACHDEP_ID);
137 1.1 thorpej ehdr.e_version = EV_CURRENT;
138 1.1 thorpej ehdr.e_entry = 0;
139 1.1 thorpej ehdr.e_phoff = sizeof(ehdr);
140 1.1 thorpej ehdr.e_shoff = 0;
141 1.1 thorpej ehdr.e_flags = 0;
142 1.1 thorpej ehdr.e_ehsize = sizeof(ehdr);
143 1.1 thorpej ehdr.e_phentsize = sizeof(Elf_Phdr);
144 1.2 thorpej ehdr.e_phnum = cs.npsections;
145 1.1 thorpej ehdr.e_shentsize = 0;
146 1.1 thorpej ehdr.e_shnum = 0;
147 1.1 thorpej ehdr.e_shstrndx = 0;
148 1.1 thorpej
149 1.1 thorpej /* Write out the ELF header. */
150 1.1 thorpej error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&ehdr,
151 1.1 thorpej (int)sizeof(ehdr), (off_t)0,
152 1.1 thorpej UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p);
153 1.1 thorpej
154 1.2 thorpej ws.offset = ehdr.e_phoff;
155 1.2 thorpej notestart = ws.offset + (sizeof(phdr) * cs.npsections);
156 1.1 thorpej secstart = round_page(notestart + notesize);
157 1.1 thorpej
158 1.5 atatat /* Pass 2: now write the P-section headers. */
159 1.2 thorpej ws.secoff = secstart;
160 1.2 thorpej error = uvm_coredump_walkmap(p, vp, cred,
161 1.2 thorpej ELFNAMEEND(coredump_writeseghdrs), &ws);
162 1.2 thorpej if (error)
163 1.2 thorpej return (error);
164 1.1 thorpej
165 1.1 thorpej /* Write out the PT_NOTE header. */
166 1.1 thorpej phdr.p_type = PT_NOTE;
167 1.1 thorpej phdr.p_offset = notestart;
168 1.1 thorpej phdr.p_vaddr = 0;
169 1.1 thorpej phdr.p_paddr = 0;
170 1.1 thorpej phdr.p_filesz = notesize;
171 1.1 thorpej phdr.p_memsz = 0;
172 1.1 thorpej phdr.p_flags = PF_R;
173 1.1 thorpej phdr.p_align = ELFROUNDSIZE;
174 1.1 thorpej
175 1.1 thorpej error = vn_rdwr(UIO_WRITE, vp,
176 1.1 thorpej (caddr_t)&phdr, sizeof(phdr),
177 1.2 thorpej ws.offset, UIO_SYSSPACE,
178 1.1 thorpej IO_NODELOCKED|IO_UNIT, cred, NULL, p);
179 1.1 thorpej if (error)
180 1.1 thorpej return (error);
181 1.1 thorpej
182 1.2 thorpej ws.offset += sizeof(phdr);
183 1.1 thorpej
184 1.2 thorpej #ifdef DIAGNOSTIC
185 1.2 thorpej if (ws.offset != notestart)
186 1.2 thorpej panic("coredump: offset %lld != notestart %lld",
187 1.3 thorpej (long long) ws.offset, (long long) notestart);
188 1.2 thorpej #endif
189 1.1 thorpej
190 1.1 thorpej /* Write out the notes. */
191 1.2 thorpej error = ELFNAMEEND(coredump_notes)(p, vp, cred, ¬esize, ws.offset);
192 1.2 thorpej
193 1.2 thorpej ws.offset += notesize;
194 1.2 thorpej
195 1.2 thorpej #ifdef DIAGNOSTIC
196 1.2 thorpej if (round_page(ws.offset) != secstart)
197 1.2 thorpej panic("coredump: offset %lld != secstart %lld",
198 1.3 thorpej (long long) round_page(ws.offset), (long long) secstart);
199 1.2 thorpej #endif
200 1.2 thorpej
201 1.5 atatat /* Pass 3: finally, write the sections themselves. */
202 1.2 thorpej ws.secoff = secstart;
203 1.2 thorpej error = uvm_coredump_walkmap(p, vp, cred,
204 1.2 thorpej ELFNAMEEND(coredump_writesegs), &ws);
205 1.1 thorpej if (error)
206 1.1 thorpej return (error);
207 1.1 thorpej
208 1.2 thorpej return (error);
209 1.2 thorpej }
210 1.2 thorpej
211 1.2 thorpej int
212 1.2 thorpej ELFNAMEEND(coredump_countsegs)(struct proc *p, struct vnode *vp,
213 1.2 thorpej struct ucred *cred, struct uvm_coredump_state *us)
214 1.2 thorpej {
215 1.2 thorpej struct countsegs_state *cs = us->cookie;
216 1.1 thorpej
217 1.2 thorpej cs->npsections++;
218 1.2 thorpej return (0);
219 1.2 thorpej }
220 1.2 thorpej
221 1.2 thorpej int
222 1.2 thorpej ELFNAMEEND(coredump_writeseghdrs)(struct proc *p, struct vnode *vp,
223 1.2 thorpej struct ucred *cred, struct uvm_coredump_state *us)
224 1.2 thorpej {
225 1.2 thorpej struct writesegs_state *ws = us->cookie;
226 1.2 thorpej Elf_Phdr phdr;
227 1.2 thorpej vsize_t size;
228 1.2 thorpej int error;
229 1.2 thorpej
230 1.2 thorpej size = us->end - us->start;
231 1.2 thorpej
232 1.2 thorpej phdr.p_type = PT_LOAD;
233 1.2 thorpej phdr.p_offset = ws->secoff;
234 1.2 thorpej phdr.p_vaddr = us->start;
235 1.2 thorpej phdr.p_paddr = 0;
236 1.2 thorpej phdr.p_filesz = (us->flags & UVM_COREDUMP_NODUMP) ? 0 : size;
237 1.2 thorpej phdr.p_memsz = size;
238 1.2 thorpej phdr.p_flags = 0;
239 1.2 thorpej if (us->prot & VM_PROT_READ)
240 1.2 thorpej phdr.p_flags |= PF_R;
241 1.2 thorpej if (us->prot & VM_PROT_WRITE)
242 1.2 thorpej phdr.p_flags |= PF_W;
243 1.2 thorpej if (us->prot & VM_PROT_EXECUTE)
244 1.2 thorpej phdr.p_flags |= PF_X;
245 1.2 thorpej phdr.p_align = PAGE_SIZE;
246 1.2 thorpej
247 1.2 thorpej error = vn_rdwr(UIO_WRITE, vp,
248 1.2 thorpej (caddr_t)&phdr, sizeof(phdr),
249 1.2 thorpej ws->offset, UIO_SYSSPACE,
250 1.2 thorpej IO_NODELOCKED|IO_UNIT, cred, NULL, p);
251 1.2 thorpej if (error)
252 1.2 thorpej return (error);
253 1.2 thorpej
254 1.2 thorpej ws->offset += sizeof(phdr);
255 1.2 thorpej ws->secoff += phdr.p_filesz;
256 1.2 thorpej
257 1.2 thorpej return (0);
258 1.2 thorpej }
259 1.2 thorpej
260 1.2 thorpej int
261 1.2 thorpej ELFNAMEEND(coredump_writesegs)(struct proc *p, struct vnode *vp,
262 1.2 thorpej struct ucred *cred, struct uvm_coredump_state *us)
263 1.2 thorpej {
264 1.2 thorpej struct writesegs_state *ws = us->cookie;
265 1.2 thorpej vsize_t size;
266 1.2 thorpej int error;
267 1.2 thorpej
268 1.2 thorpej if (us->flags & UVM_COREDUMP_NODUMP)
269 1.2 thorpej return (0);
270 1.2 thorpej
271 1.2 thorpej size = us->end - us->start;
272 1.2 thorpej
273 1.2 thorpej error = vn_rdwr(UIO_WRITE, vp,
274 1.2 thorpej (caddr_t) us->start, size,
275 1.2 thorpej ws->secoff, UIO_USERSPACE,
276 1.2 thorpej IO_NODELOCKED|IO_UNIT, cred, NULL, p);
277 1.2 thorpej if (error)
278 1.2 thorpej return (error);
279 1.1 thorpej
280 1.2 thorpej ws->secoff += size;
281 1.1 thorpej
282 1.1 thorpej return (0);
283 1.1 thorpej }
284 1.1 thorpej
285 1.1 thorpej int
286 1.1 thorpej ELFNAMEEND(coredump_notes)(struct proc *p, struct vnode *vp,
287 1.1 thorpej struct ucred *cred, int *sizep, off_t offset)
288 1.1 thorpej {
289 1.1 thorpej struct netbsd_elfcore_procinfo cpi;
290 1.1 thorpej Elf_Nhdr nhdr;
291 1.1 thorpej int size, notesize, error;
292 1.1 thorpej char name[64];
293 1.1 thorpej int namesize;
294 1.4 thorpej struct lwp *l;
295 1.1 thorpej struct reg intreg;
296 1.1 thorpej #ifdef PT_GETFPREGS
297 1.1 thorpej struct fpreg freg;
298 1.1 thorpej #endif
299 1.1 thorpej
300 1.1 thorpej size = 0;
301 1.1 thorpej
302 1.1 thorpej /* First, write an elfcore_procinfo. */
303 1.1 thorpej notesize = sizeof(nhdr) + elfround(sizeof(ELF_NOTE_NETBSD_CORE_NAME)) +
304 1.1 thorpej elfround(sizeof(cpi));
305 1.1 thorpej if (offset) {
306 1.1 thorpej cpi.cpi_version = NETBSD_ELFCORE_PROCINFO_VERSION;
307 1.1 thorpej cpi.cpi_cpisize = sizeof(cpi);
308 1.1 thorpej cpi.cpi_signo = p->p_sigctx.ps_sig;
309 1.1 thorpej cpi.cpi_sigcode = p->p_sigctx.ps_code;
310 1.1 thorpej
311 1.1 thorpej memcpy(&cpi.cpi_sigpend, &p->p_sigctx.ps_siglist,
312 1.1 thorpej sizeof(cpi.cpi_sigpend));
313 1.1 thorpej memcpy(&cpi.cpi_sigmask, &p->p_sigctx.ps_sigmask,
314 1.1 thorpej sizeof(cpi.cpi_sigmask));
315 1.1 thorpej memcpy(&cpi.cpi_sigignore, &p->p_sigctx.ps_sigignore,
316 1.1 thorpej sizeof(cpi.cpi_sigignore));
317 1.1 thorpej memcpy(&cpi.cpi_sigcatch, &p->p_sigctx.ps_sigcatch,
318 1.1 thorpej sizeof(cpi.cpi_sigcatch));
319 1.1 thorpej
320 1.1 thorpej cpi.cpi_pid = p->p_pid;
321 1.1 thorpej cpi.cpi_ppid = p->p_pptr->p_pid;
322 1.1 thorpej cpi.cpi_pgrp = p->p_pgid;
323 1.1 thorpej cpi.cpi_sid = p->p_session->s_sid;
324 1.1 thorpej
325 1.1 thorpej cpi.cpi_ruid = p->p_cred->p_ruid;
326 1.1 thorpej cpi.cpi_euid = p->p_ucred->cr_uid;
327 1.1 thorpej cpi.cpi_svuid = p->p_cred->p_svuid;
328 1.1 thorpej
329 1.1 thorpej cpi.cpi_rgid = p->p_cred->p_rgid;
330 1.1 thorpej cpi.cpi_egid = p->p_ucred->cr_gid;
331 1.1 thorpej cpi.cpi_svgid = p->p_cred->p_svgid;
332 1.1 thorpej
333 1.4 thorpej cpi.cpi_nlwps = p->p_nlwps;
334 1.1 thorpej strcpy(cpi.cpi_name, p->p_comm);
335 1.1 thorpej
336 1.1 thorpej nhdr.n_namesz = sizeof(ELF_NOTE_NETBSD_CORE_NAME);
337 1.1 thorpej nhdr.n_descsz = sizeof(cpi);
338 1.1 thorpej nhdr.n_type = ELF_NOTE_NETBSD_CORE_PROCINFO;
339 1.1 thorpej
340 1.1 thorpej error = ELFNAMEEND(coredump_writenote)(p, vp, cred, offset,
341 1.1 thorpej &nhdr, ELF_NOTE_NETBSD_CORE_NAME, &cpi);
342 1.1 thorpej if (error)
343 1.1 thorpej return (error);
344 1.1 thorpej
345 1.1 thorpej offset += notesize;
346 1.1 thorpej }
347 1.1 thorpej
348 1.1 thorpej size += notesize;
349 1.1 thorpej
350 1.1 thorpej /* XXX Add hook for machdep per-proc notes. */
351 1.1 thorpej
352 1.1 thorpej /*
353 1.1 thorpej * Now, for each LWP, write the register info and any other
354 1.1 thorpej * per-LWP notes.
355 1.1 thorpej */
356 1.4 thorpej LIST_FOREACH(l, &p->p_lwps, l_sibling) {
357 1.4 thorpej sprintf(name, "%s@%d", ELF_NOTE_NETBSD_CORE_NAME, l->l_lid);
358 1.1 thorpej namesize = strlen(name) + 1;
359 1.1 thorpej
360 1.1 thorpej notesize = sizeof(nhdr) + elfround(namesize) +
361 1.1 thorpej elfround(sizeof(intreg));
362 1.1 thorpej if (offset) {
363 1.4 thorpej PHOLD(l);
364 1.4 thorpej error = process_read_regs(l, &intreg);
365 1.4 thorpej PRELE(l);
366 1.1 thorpej if (error)
367 1.1 thorpej return (error);
368 1.1 thorpej
369 1.1 thorpej nhdr.n_namesz = namesize;
370 1.1 thorpej nhdr.n_descsz = sizeof(intreg);
371 1.1 thorpej nhdr.n_type = PT_GETREGS;
372 1.1 thorpej
373 1.1 thorpej error = ELFNAMEEND(coredump_writenote)(p, vp, cred,
374 1.1 thorpej offset, &nhdr, name, &intreg);
375 1.1 thorpej if (error)
376 1.1 thorpej return (error);
377 1.1 thorpej
378 1.1 thorpej offset += notesize;
379 1.1 thorpej }
380 1.1 thorpej size += notesize;
381 1.1 thorpej
382 1.1 thorpej #ifdef PT_GETFPREGS
383 1.1 thorpej notesize = sizeof(nhdr) + elfround(namesize) +
384 1.1 thorpej elfround(sizeof(freg));
385 1.1 thorpej if (offset) {
386 1.4 thorpej PHOLD(l);
387 1.4 thorpej error = process_read_fpregs(l, &freg);
388 1.4 thorpej PRELE(l);
389 1.1 thorpej if (error)
390 1.1 thorpej return (error);
391 1.1 thorpej
392 1.1 thorpej nhdr.n_namesz = namesize;
393 1.1 thorpej nhdr.n_descsz = sizeof(freg);
394 1.1 thorpej nhdr.n_type = PT_GETFPREGS;
395 1.1 thorpej
396 1.1 thorpej error = ELFNAMEEND(coredump_writenote)(p, vp, cred,
397 1.1 thorpej offset, &nhdr, name, &freg);
398 1.1 thorpej if (error)
399 1.1 thorpej return (error);
400 1.1 thorpej
401 1.1 thorpej offset += notesize;
402 1.1 thorpej }
403 1.1 thorpej size += notesize;
404 1.1 thorpej #endif
405 1.1 thorpej /* XXX Add hook for machdep per-LWP notes. */
406 1.4 thorpej }
407 1.1 thorpej
408 1.1 thorpej *sizep = size;
409 1.1 thorpej return (0);
410 1.1 thorpej }
411 1.1 thorpej
412 1.1 thorpej int
413 1.1 thorpej ELFNAMEEND(coredump_writenote)(struct proc *p, struct vnode *vp,
414 1.1 thorpej struct ucred *cred, off_t offset, Elf_Nhdr *nhdr, const char *name,
415 1.1 thorpej void *data)
416 1.1 thorpej {
417 1.1 thorpej int error;
418 1.1 thorpej
419 1.1 thorpej error = vn_rdwr(UIO_WRITE, vp,
420 1.1 thorpej (caddr_t) nhdr, sizeof(*nhdr),
421 1.1 thorpej offset, UIO_SYSSPACE,
422 1.1 thorpej IO_NODELOCKED|IO_UNIT, cred, NULL, p);
423 1.1 thorpej if (error)
424 1.1 thorpej return (error);
425 1.1 thorpej
426 1.1 thorpej offset += sizeof(*nhdr);
427 1.1 thorpej
428 1.1 thorpej error = vn_rdwr(UIO_WRITE, vp,
429 1.1 thorpej (caddr_t)name, nhdr->n_namesz,
430 1.1 thorpej offset, UIO_SYSSPACE,
431 1.1 thorpej IO_NODELOCKED|IO_UNIT, cred, NULL, p);
432 1.1 thorpej if (error)
433 1.1 thorpej return (error);
434 1.1 thorpej
435 1.1 thorpej offset += elfround(nhdr->n_namesz);
436 1.1 thorpej
437 1.1 thorpej error = vn_rdwr(UIO_WRITE, vp,
438 1.1 thorpej data, nhdr->n_descsz,
439 1.1 thorpej offset, UIO_SYSSPACE,
440 1.1 thorpej IO_NODELOCKED|IO_UNIT, cred, NULL, p);
441 1.1 thorpej
442 1.1 thorpej return (error);
443 1.1 thorpej }
444