netbsd32_core.c revision 1.7
1/* $NetBSD: netbsd32_core.c,v 1.7 2003/06/29 22:29:36 fvdl Exp $ */ 2 3/* 4 * Copyright (c) 1997 Charles D. Cranor and Washington University. 5 * Copyright (c) 1991, 1993 The Regents of the University of California. 6 * Copyright (c) 1988 University of Utah. 7 * 8 * All rights reserved. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * the Systems Programming Group of the University of Utah Computer 12 * Science Department. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgement: 24 * This product includes software developed by Charles D. Cranor, 25 * Washington University, the University of California, Berkeley and 26 * its contributors. 27 * 4. Neither the name of the University nor the names of its contributors 28 * may be used to endorse or promote products derived from this software 29 * without specific prior written permission. 30 * 31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41 * SUCH DAMAGE. 42 * 43 * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$ 44 * @(#)vm_unix.c 8.1 (Berkeley) 6/11/93 45 * from: NetBSD: uvm_unix.c,v 1.25 2001/11/10 07:37:01 lukem Exp 46 */ 47 48/* 49 * core_netbsd.c: Support for the historic NetBSD core file format. 50 */ 51 52#include <sys/cdefs.h> 53__KERNEL_RCSID(0, "$NetBSD: netbsd32_core.c,v 1.7 2003/06/29 22:29:36 fvdl Exp $"); 54 55#include <sys/param.h> 56#include <sys/systm.h> 57#include <sys/lwp.h> 58#include <sys/proc.h> 59#include <sys/vnode.h> 60#include <sys/core.h> 61 62#include <uvm/uvm_extern.h> 63 64#include <compat/netbsd32/netbsd32.h> 65 66struct coredump_state { 67 struct core32 core; 68 off_t offset; 69}; 70 71int coredump_writesegs_netbsd32(struct proc *, struct vnode *, 72 struct ucred *, struct uvm_coredump_state *); 73 74int 75coredump_netbsd32(struct lwp *l, struct vnode *vp, struct ucred *cred) 76{ 77 struct coredump_state cs; 78 struct proc *p = l->l_proc; 79 struct vmspace *vm = p->p_vmspace; 80 int error; 81 82 cs.core.c_midmag = 0; 83 strncpy(cs.core.c_name, p->p_comm, MAXCOMLEN); 84 cs.core.c_nseg = 0; 85 cs.core.c_signo = p->p_sigctx.ps_sig; 86 cs.core.c_ucode = p->p_sigctx.ps_code; 87 cs.core.c_cpusize = 0; 88 cs.core.c_tsize = (u_long)ctob(vm->vm_tsize); 89 cs.core.c_dsize = (u_long)ctob(vm->vm_dsize); 90 cs.core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize)); 91 error = cpu_coredump32(l, vp, cred, &cs.core); 92 if (error) 93 return (error); 94 95#if 0 96 /* 97 * XXX 98 * It would be nice if we at least dumped the signal state (and made it 99 * available at run time to the debugger, as well), but this code 100 * hasn't actually had any effect for a long time, since we don't dump 101 * the user area. For now, it's dead. 102 */ 103 memcpy(&p->p_addr->u_kproc.kp_proc, p, sizeof(struct proc)); 104 fill_eproc(p, &p->p_addr->u_kproc.kp_eproc); 105#endif 106 107 cs.offset = cs.core.c_hdrsize + cs.core.c_seghdrsize + 108 cs.core.c_cpusize; 109 error = uvm_coredump_walkmap(p, vp, cred, coredump_writesegs_netbsd32, 110 &cs); 111 if (error) 112 return (error); 113 114 /* Now write out the core header. */ 115 error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cs.core, 116 (int)cs.core.c_hdrsize, (off_t)0, 117 UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p); 118 119 return (error); 120} 121 122int 123coredump_writesegs_netbsd32(struct proc *p, struct vnode *vp, 124 struct ucred *cred, struct uvm_coredump_state *us) 125{ 126 struct coredump_state *cs = us->cookie; 127 struct coreseg32 cseg; 128 int flag, error; 129 130 if (us->flags & UVM_COREDUMP_NODUMP) 131 return (0); 132 133 if (us->flags & UVM_COREDUMP_STACK) 134 flag = CORE_STACK; 135 else 136 flag = CORE_DATA; 137 138 /* 139 * Set up a new core file segment. 140 */ 141 CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(cs->core), flag); 142 cseg.c_addr = us->start; 143 cseg.c_size = us->end - us->start; 144 145 error = vn_rdwr(UIO_WRITE, vp, 146 (caddr_t)&cseg, cs->core.c_seghdrsize, 147 cs->offset, UIO_SYSSPACE, 148 IO_NODELOCKED|IO_UNIT, cred, NULL, p); 149 if (error) 150 return (error); 151 152 cs->offset += cs->core.c_seghdrsize; 153 error = vn_rdwr(UIO_WRITE, vp, 154 (caddr_t) us->start, (int) cseg.c_size, 155 cs->offset, UIO_USERSPACE, 156 IO_NODELOCKED|IO_UNIT, cred, NULL, p); 157 if (error) 158 return (error); 159 160 cs->offset += cseg.c_size; 161 cs->core.c_nseg++; 162 163 return (0); 164} 165