1 /* $NetBSD: core_netbsd.c,v 1.15 2008/04/29 16:21:27 ad Exp $ */
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.
10 * This code is derived from software contributed to Berkeley by
11 * the Systems Programming Group of the University of Utah Computer
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
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
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.
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
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
49 * core_netbsd.c: Support for the historic NetBSD core file format.
52 #include <sys/cdefs.h>
53 __KERNEL_RCSID(0, "$NetBSD: core_netbsd.c,v 1.15 2008/04/29 16:21:27 ad Exp $");
56 #include "opt_coredump.h"
59 #include <sys/param.h>
60 #include <sys/systm.h>
63 #include <sys/vnode.h>
66 #include <uvm/uvm_extern.h>
77 struct coredump_state
{
78 struct CORENAME(core
) core
;
81 static int CORENAME(coredump_countsegs_netbsd
)(struct proc
*, void *,
82 struct uvm_coredump_state
*);
83 static int CORENAME(coredump_writesegs_netbsd
)(struct proc
*, void *,
84 struct uvm_coredump_state
*);
87 CORENAME(coredump_netbsd
)(struct lwp
*l
, void *iocookie
)
89 struct coredump_state cs
;
90 struct proc
*p
= l
->l_proc
;
91 struct vmspace
*vm
= p
->p_vmspace
;
96 strncpy(cs
.core
.c_name
, p
->p_comm
, MAXCOMLEN
);
98 cs
.core
.c_signo
= p
->p_sigctx
.ps_signo
;
99 cs
.core
.c_ucode
= p
->p_sigctx
.ps_code
;
100 cs
.core
.c_cpusize
= 0;
101 cs
.core
.c_tsize
= (u_long
)ctob(vm
->vm_tsize
);
102 cs
.core
.c_dsize
= (u_long
)ctob(vm
->vm_dsize
);
103 cs
.core
.c_ssize
= (u_long
)round_page(ctob(vm
->vm_ssize
));
108 * It would be nice if we at least dumped the signal state (and made it
109 * available at run time to the debugger, as well), but this code
110 * hasn't actually had any effect for a long time, since we don't dump
111 * the user area. For now, it's dead.
113 memcpy(&p
->p_addr
->u_kproc
.kp_proc
, p
, sizeof(struct proc
));
114 fill_eproc(p
, &p
->p_addr
->u_kproc
.kp_eproc
, false);
116 error
= CORENAME(cpu_coredump
)(l
, NULL
, &cs
.core
);
119 error
= uvm_coredump_walkmap(p
, NULL
,
120 CORENAME(coredump_countsegs_netbsd
), &cs
);
124 /* First write out the core header. */
125 error
= coredump_write(iocookie
, UIO_SYSSPACE
, &cs
.core
,
130 /* Then the CPU specific stuff */
131 error
= CORENAME(cpu_coredump
)(l
, iocookie
, &cs
.core
);
135 /* Finally, the address space dump */
136 return uvm_coredump_walkmap(p
, iocookie
,
137 CORENAME(coredump_writesegs_netbsd
), &cs
);
141 CORENAME(coredump_countsegs_netbsd
)(struct proc
*p
, void *iocookie
,
142 struct uvm_coredump_state
*us
)
144 struct coredump_state
*cs
= us
->cookie
;
146 if (us
->start
!= us
->realend
)
153 CORENAME(coredump_writesegs_netbsd
)(struct proc
*p
, void *iocookie
,
154 struct uvm_coredump_state
*us
)
156 struct coredump_state
*cs
= us
->cookie
;
157 struct CORENAME(coreseg
) cseg
;
160 if (us
->start
== us
->realend
)
163 if (us
->flags
& UVM_COREDUMP_STACK
)
169 * Set up a new core file segment.
171 CORE_SETMAGIC(cseg
, CORESEGMAGIC
, CORE_GETMID(cs
->core
), flag
);
172 cseg
.c_addr
= us
->start
;
173 cseg
.c_size
= us
->end
- us
->start
;
175 error
= coredump_write(iocookie
, UIO_SYSSPACE
,
176 &cseg
, cs
->core
.c_seghdrsize
);
180 return coredump_write(iocookie
, UIO_USERSPACE
,
181 (void *)(vaddr_t
)us
->start
, cseg
.c_size
);
187 CORENAME(coredump_netbsd
)(struct lwp
*l
, void *cookie
)
193 #endif /* COREDUMP */