Subject: Making coredump handling exec-format/emulation specific
To: None <tech-kern@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 12/05/2001 20:44:44
--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Folks...

I'm working on a new core dump format for NetBSD (based on the ELF
core dump format) which will support LWPs (for the nathanw_sa branch)
and extended register sets (e.g. SSE/SSE2 on i386 and AltiVec on PowerPC).

Upshot of my changes it that they also clean up how core dumps for
compat/netbsd32 are handled.

Diff attached that sets up the basic infrastructure for this.  Currently
everything just points at "coredump_netbsd()" for now.

I'm probably going to make some cosmetic changes to exec_conf.c before
I commit this.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=us-ascii
Content-Description: coredump.diff
Content-Disposition: attachment; filename="coredump.diff"

Index: arch/sparc64/sparc64/netbsd32_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc64/sparc64/netbsd32_machdep.c,v
retrieving revision 1.18
diff -c -r1.18 netbsd32_machdep.c
*** arch/sparc64/sparc64/netbsd32_machdep.c	2001/09/21 17:12:22	1.18
--- arch/sparc64/sparc64/netbsd32_machdep.c	2001/12/06 04:14:24
***************
*** 81,89 ****
  	/* Mark this as a 32-bit emulation */
  	p->p_flag |= P_32;
  
! 	/* Setup the coredump32 and ev_out32 hook's */
! 	if (coredump32_hook == NULL)
! 		coredump32_hook = coredump32;
  	if (ev_out32_hook == NULL)
  		ev_out32_hook = ev_out32;
  
--- 81,87 ----
  	/* Mark this as a 32-bit emulation */
  	p->p_flag |= P_32;
  
! 	/* Setup the ev_out32 hook */
  	if (ev_out32_hook == NULL)
  		ev_out32_hook = ev_out32;
  
Index: arch/sparc64/sparc64/sunos32_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc64/sparc64/sunos32_machdep.c,v
retrieving revision 1.5
diff -c -r1.5 sunos32_machdep.c
*** arch/sparc64/sparc64/sunos32_machdep.c	2001/09/21 17:12:22	1.5
--- arch/sparc64/sparc64/sunos32_machdep.c	2001/12/06 04:14:26
***************
*** 111,119 ****
  	/* Mark this as a 32-bit emulation */
  	p->p_flag |= P_32;
  
! 	/* Setup the coredump32 and ev_out32 hook's */
! 	if (coredump32_hook == NULL)
! 		coredump32_hook = coredump32;
  	if (ev_out32_hook == NULL)
  		ev_out32_hook = ev_out32;
  
--- 111,117 ----
  	/* Mark this as a 32-bit emulation */
  	p->p_flag |= P_32;
  
! 	/* Setup the ev_out32 hook */
  	if (ev_out32_hook == NULL)
  		ev_out32_hook = ev_out32;
  
Index: compat/netbsd32/files.netbsd32
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/netbsd32/files.netbsd32,v
retrieving revision 1.10
diff -c -r1.10 files.netbsd32
*** compat/netbsd32/files.netbsd32	2001/06/06 21:30:28	1.10
--- compat/netbsd32/files.netbsd32	2001/12/06 04:14:36
***************
*** 6,11 ****
--- 6,12 ----
  # ports should define any machine-specific files they need in their
  # own file lists.
  
+ file	compat/netbsd32/netbsd32_core.c		compat_netbsd32
  file	compat/netbsd32/netbsd32_exec_elf32.c	compat_netbsd32 & exec_elf32
  file	compat/netbsd32/netbsd32_exec_aout.c	compat_netbsd32 & exec_aout
  file	compat/netbsd32/netbsd32_netbsd.c	compat_netbsd32
***************
*** 19,26 ****
  file	compat/netbsd32/netbsd32_sysctl.c	compat_netbsd32
  file	compat/netbsd32/netbsd32_time.c		compat_netbsd32
  file	compat/netbsd32/netbsd32_wait.c		compat_netbsd32
- file	compat/netbsd32/netbsd32_kern_sig.c	compat_netbsd32
- file	compat/netbsd32/netbsd32_uvm_unix.c	compat_netbsd32
  file	compat/netbsd32/netbsd32_sysent.c	compat_netbsd32
  file	compat/netbsd32/netbsd32_compat_09.c	compat_netbsd32 & (compat_09 | compat_sunos)
  file	compat/netbsd32/netbsd32_compat_10.c	compat_netbsd32 & compat_10
--- 20,25 ----
Index: compat/netbsd32/netbsd32.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/netbsd32/netbsd32.h,v
retrieving revision 1.20
diff -c -r1.20 netbsd32.h
*** compat/netbsd32/netbsd32.h	2001/08/25 15:06:02	1.20
--- compat/netbsd32/netbsd32.h	2001/12/06 04:14:37
***************
*** 533,540 ****
  #define	NETBSD32TOX_UAP(name, type)	NETBSD32TOX(uap, &ua, name, type);
  #define	NETBSD32TOX64_UAP(name, type)	NETBSD32TOX64(uap, &ua, name, type);
  
! /* hook for coredump */
! extern	int coredump32(struct proc *, struct vnode *);
  
  /*
   * random other stuff
--- 533,539 ----
  #define	NETBSD32TOX_UAP(name, type)	NETBSD32TOX(uap, &ua, name, type);
  #define	NETBSD32TOX64_UAP(name, type)	NETBSD32TOX64(uap, &ua, name, type);
  
! int	coredump_netbsd32(struct proc *, struct vnode *, struct ucred *);
  
  /*
   * random other stuff
Index: compat/netbsd32/netbsd32_core.c
===================================================================
RCS file: netbsd32_core.c
diff -N netbsd32_core.c
*** /dev/null	Thu Dec  6 03:15:07 2001
--- netbsd32_core.c	Thu Dec  6 06:14:37 2001
***************
*** 0 ****
--- 1,161 ----
+ /*	$NetBSD$	*/
+ 
+ /*
+  * Copyright (c) 1997 Charles D. Cranor and Washington University.
+  * Copyright (c) 1991, 1993 The Regents of the University of California.
+  * Copyright (c) 1988 University of Utah.
+  *
+  * All rights reserved.
+  *
+  * This code is derived from software contributed to Berkeley by
+  * the Systems Programming Group of the University of Utah Computer
+  * Science Department.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *      This product includes software developed by Charles D. Cranor,
+  *	Washington University, the University of California, Berkeley and
+  *	its contributors.
+  * 4. Neither the name of the University nor the names of its contributors
+  *    may be used to endorse or promote products derived from this software
+  *    without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  * SUCH DAMAGE.
+  *
+  * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
+  *      @(#)vm_unix.c   8.1 (Berkeley) 6/11/93
+  * from: NetBSD: uvm_unix.c,v 1.25 2001/11/10 07:37:01 lukem Exp
+  */
+ 
+ /*
+  * netbsd32_core.c: Support for the historic NetBSD core file format,
+  * 32-bit version.
+  */
+ 
+ #include <sys/cdefs.h>
+ __KERNEL_RCSID(0, "$NetBSD$");
+ 
+ #include <sys/param.h>
+ #include <sys/systm.h>
+ #include <sys/proc.h>
+ #include <sys/vnode.h>
+ #include <sys/core.h>
+ 
+ #include <uvm/uvm.h>
+ 
+ int
+ coredump_netbsd32(struct proc *p, struct vnode *vp, struct ucred *cred)
+ {
+ 	struct core32 core;
+ 	struct coreseg32 cseg;
+ 	struct vmspace *vm = p->p_vmspace;
+ 	struct vm_map *map = &vm->vm_map;
+ 	struct vm_map_entry *entry;
+ 	vaddr_t start, end, maxstack;
+ 	off_t offset;
+ 	int flag, error;
+ 
+ 	core.c_midmag = 0;
+ 	strncpy(core.c_name, p->p_comm, MAXCOMLEN);
+ 	core.c_nseg = 0;
+ 	core.c_signo = p->p_sigctx.ps_sig;
+ 	core.c_ucode = p->p_sigctx.ps_code;
+ 	core.c_cpusize = 0;
+ 	core.c_tsize = (u_long)ctob(vm->vm_tsize);
+ 	core.c_dsize = (u_long)ctob(vm->vm_dsize);
+ 	core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize));
+ 	error = cpu_coredump(p, vp, cred, &core);
+ 	if (error)
+ 		return (error);
+ 
+ #if 0
+ 	/*
+ 	 * XXX
+ 	 * It would be nice if we at least dumped the signal state (and made it
+ 	 * available at run time to the debugger, as well), but this code
+ 	 * hasn't actually had any effect for a long time, since we don't dump
+ 	 * the user area.  For now, it's dead.
+ 	 */
+ #endif
+ 
+ 	offset = core.c_hdrsize + core.c_seghdrsize + core.c_cpusize;
+ 	maxstack = trunc_page(USRSTACK - ctob(vm->vm_ssize));
+ 
+ 	for (entry = map->header.next; entry != &map->header;
+ 	     entry = entry->next) {
+ 		/* Should never happen for a user process. */
+ 		if (UVM_ET_ISSUBMAP(entry))
+ 			panic("coredump_netbsd: user process with submap?");
+ 
+ 		if ((entry->protection & VM_PROT_WRITE) == 0)
+ 			continue;
+ 
+ 		start = entry->start;
+ 		end = entry->end;
+ 
+ 		if (start >= VM_MAXUSER_ADDRESS)
+ 			continue;
+ 
+ 		if (end > VM_MAXUSER_ADDRESS)
+ 			end = VM_MAXUSER_ADDRESS;
+ 
+ 		if (start >= (vaddr_t)vm->vm_maxsaddr) {
+ 			if (end <= maxstack)
+ 				continue;
+ 			if (start < maxstack)
+ 				start = maxstack;
+ 			flag = CORE_STACK;
+ 		} else
+ 			flag = CORE_DATA;
+ 
+ 		/*
+ 		 * Set up a new core file segment.
+ 		 */
+ 		CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(core), flag);
+ 		cseg.c_addr = start;
+ 		cseg.c_size = end - start;
+ 
+ 		error = vn_rdwr(UIO_WRITE, vp,
+ 		    (caddr_t)&cseg, core.c_seghdrsize,
+ 		    offset, UIO_SYSSPACE,
+ 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
+ 		if (error)
+ 			return (error);
+ 
+ 		offset += core.c_seghdrsize;
+ 		error = vn_rdwr(UIO_WRITE, vp,
+ 		    (caddr_t)cseg.c_addr, (int)cseg.c_size,
+ 		    offset, UIO_USERSPACE,
+ 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
+ 		if (error)
+ 			return (error);
+ 
+ 		offset += cseg.c_size;
+ 		core.c_nseg++;
+ 	}
+ 
+ 	/* Now write out the core header. */
+ 	error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&core,
+ 	    (int)core.c_hdrsize, (off_t)0,
+ 	    UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p);
+ 
+ 	return (error);
+ }
Index: compat/netbsd32/netbsd32_kern_sig.c
===================================================================
RCS file: netbsd32_kern_sig.c
diff -N netbsd32_kern_sig.c
*** /tmp/cvs09217bc	Thu Dec  6 06:16:31 2001
--- /dev/null	Thu Dec  6 03:15:07 2001
***************
*** 1,111 ****
- /*	$NetBSD: netbsd32_kern_sig.c,v 1.2 2001/11/13 02:09:06 lukem Exp $	*/
- 
- /*
-  * Copyright (c) 1982, 1986, 1989, 1991, 1993
-  *	The Regents of the University of California.  All rights reserved.
-  * (c) UNIX System Laboratories, Inc.
-  * All or some portions of this file are derived from material licensed
-  * to the University of California by American Telephone and Telegraph
-  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
-  * the permission of UNIX System Laboratories, Inc.
-  *
-  * Redistribution and use in source and binary forms, with or without
-  * modification, are permitted provided that the following conditions
-  * are met:
-  * 1. Redistributions of source code must retain the above copyright
-  *    notice, this list of conditions and the following disclaimer.
-  * 2. Redistributions in binary form must reproduce the above copyright
-  *    notice, this list of conditions and the following disclaimer in the
-  *    documentation and/or other materials provided with the distribution.
-  * 3. All advertising materials mentioning features or use of this software
-  *    must display the following acknowledgement:
-  *	This product includes software developed by the University of
-  *	California, Berkeley and its contributors.
-  * 4. Neither the name of the University nor the names of its contributors
-  *    may be used to endorse or promote products derived from this software
-  *    without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-  * SUCH DAMAGE.
-  *
-  *	@(#)kern_sig.c	8.14 (Berkeley) 5/14/95
-  * from: NetBSD: kern_sig.c,v 1.112 2001/02/26 21:58:30 lukem Exp
-  */
- 
- #include <sys/cdefs.h>
- __KERNEL_RCSID(0, "$NetBSD: netbsd32_kern_sig.c,v 1.2 2001/11/13 02:09:06 lukem Exp $");
- 
- #include <sys/param.h>
- #include <sys/namei.h>
- #include <sys/vnode.h>
- #include <sys/proc.h>
- #include <sys/core.h>
- #include <sys/fcntl.h>
- 
- #include <uvm/uvm_extern.h>
- 
- #include <compat/netbsd32/netbsd32.h>
- 
- /*
-  * Same as coredump, but generates a 32-bit image.
-  */
- int
- coredump32(struct proc *p, struct vnode *vp)
- {
- 	struct vmspace	*vm;
- 	struct ucred	*cred;
- 	int		error, error1;
- 	struct core32	core;
- 
- 	vm = p->p_vmspace;
- 	cred = p->p_cred->pc_ucred;
- #if 0
- 	/*
- 	 * XXX
- 	 * It would be nice if we at least dumped the signal state (and made it
- 	 * available at run time to the debugger, as well), but this code
- 	 * hasn't actually had any effect for a long time, since we don't dump
- 	 * the user area.  For now, it's dead.
- 	 */
- 	memcpy(&p->p_addr->u_kproc.kp_proc, p, sizeof(struct proc));
- 	fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
- #endif
- 
- 	core.c_midmag = 0;
- 	strncpy(core.c_name, p->p_comm, MAXCOMLEN);
- 	core.c_nseg = 0;
- 	core.c_signo = p->p_sigctx.ps_sig;
- 	core.c_ucode = p->p_sigctx.ps_code;
- 	core.c_cpusize = 0;
- 	core.c_tsize = (u_long)ctob(vm->vm_tsize);
- 	core.c_dsize = (u_long)ctob(vm->vm_dsize);
- 	core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize));
- 	error = cpu_coredump32(p, vp, cred, &core);
- 	if (error)
- 		goto out;
- 	/*
- 	 * uvm_coredump() spits out all appropriate segments.
- 	 * All that's left to do is to write the core header.
- 	 */
- 	error = uvm_coredump32(p, vp, cred, &core);
- 	if (error)
- 		goto out;
- 	error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&core,
- 	    (int)core.c_hdrsize, (off_t)0,
- 	    UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p);
-  out:
- 	VOP_UNLOCK(vp, 0);
- 	error1 = vn_close(vp, FWRITE, cred, p);
- 	if (error == 0)
- 		error = error1;
- 	return (error);
- }
--- 0 ----
Index: compat/netbsd32/netbsd32_uvm_unix.c
===================================================================
RCS file: netbsd32_uvm_unix.c
diff -N netbsd32_uvm_unix.c
*** /tmp/cvs09217bd	Thu Dec  6 06:16:31 2001
--- /dev/null	Thu Dec  6 03:15:07 2001
***************
*** 1,141 ****
- /*	$NetBSD: netbsd32_uvm_unix.c,v 1.3 2001/11/13 02:09:10 lukem Exp $	*/
- 
- /*
-  * Copyright (c) 1997 Charles D. Cranor and Washington University.
-  * Copyright (c) 1991, 1993 The Regents of the University of California.
-  * Copyright (c) 1988 University of Utah.
-  *
-  * All rights reserved.
-  *
-  * This code is derived from software contributed to Berkeley by
-  * the Systems Programming Group of the University of Utah Computer
-  * Science Department.
-  *
-  * Redistribution and use in source and binary forms, with or without
-  * modification, are permitted provided that the following conditions
-  * are met:
-  * 1. Redistributions of source code must retain the above copyright
-  *    notice, this list of conditions and the following disclaimer.
-  * 2. Redistributions in binary form must reproduce the above copyright
-  *    notice, this list of conditions and the following disclaimer in the
-  *    documentation and/or other materials provided with the distribution.
-  * 3. All advertising materials mentioning features or use of this software
-  *    must display the following acknowledgement:
-  *      This product includes software developed by Charles D. Cranor,
-  *	Washington University, the University of California, Berkeley and
-  *	its contributors.
-  * 4. Neither the name of the University nor the names of its contributors
-  *    may be used to endorse or promote products derived from this software
-  *    without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-  * SUCH DAMAGE.
-  *
-  * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
-  *      @(#)vm_unix.c   8.1 (Berkeley) 6/11/93
-  * from: Id: uvm_unix.c,v 1.1.2.2 1997/08/25 18:52:30 chuck Exp
-  * from: NetBSD: uvm_unix.c,v 1.22 2001/05/25 04:06:18 chs Exp
-  */
- 
- #include <sys/cdefs.h>
- __KERNEL_RCSID(0, "$NetBSD: netbsd32_uvm_unix.c,v 1.3 2001/11/13 02:09:10 lukem Exp $");
- 
- #include <sys/param.h>
- #include <sys/systm.h>
- #include <sys/proc.h>
- #include <sys/resourcevar.h>
- #include <sys/vnode.h>
- #include <sys/core.h>
- 
- #include <sys/mount.h>
- #include <sys/syscallargs.h>
- 
- #include <uvm/uvm.h>
- 
- /*
-  * uvm_coredump32: dump 32-bit core!
-  */
- 
- int
- uvm_coredump32(p, vp, cred, chdr)
- 	struct proc *p;
- 	struct vnode *vp;
- 	struct ucred *cred;
- 	struct core32 *chdr;
- {
- 	struct vmspace *vm = p->p_vmspace;
- 	struct vm_map *map = &vm->vm_map;
- 	struct vm_map_entry *entry;
- 	vaddr_t start, end, maxstack;
- 	struct coreseg32 cseg;
- 	off_t offset;
- 	int flag, error = 0;
- 
- 	offset = chdr->c_hdrsize + chdr->c_seghdrsize + chdr->c_cpusize;
- 	maxstack = trunc_page(USRSTACK - ctob(vm->vm_ssize));
- 
- 	for (entry = map->header.next; entry != &map->header;
- 	    entry = entry->next) {
- 
- 		/* should never happen for a user process */
- 		if (UVM_ET_ISSUBMAP(entry)) {
- 			panic("uvm_coredump: user process with submap?");
- 		}
- 
- 		if (!(entry->protection & VM_PROT_WRITE))
- 			continue;
- 
- 		start = entry->start;
- 		end = entry->end;
- 
- 		if (start >= VM_MAXUSER_ADDRESS)
- 			continue;
- 
- 		if (end > VM_MAXUSER_ADDRESS)
- 			end = VM_MAXUSER_ADDRESS;
- 
- 		if (start >= (vaddr_t)vm->vm_maxsaddr) {
- 			if (end <= maxstack)
- 				continue;
- 			if (start < maxstack) start = maxstack;
- 			flag = CORE_STACK;
- 		} else
- 			flag = CORE_DATA;
- 
- 		/*
- 		 * Set up a new core file segment.
- 		 */
- 		CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(*chdr), flag);
- 		cseg.c_addr = start;
- 		cseg.c_size = end - start;
- 
- 		error = vn_rdwr(UIO_WRITE, vp,
- 		    (caddr_t)&cseg, chdr->c_seghdrsize,
- 		    offset, UIO_SYSSPACE,
- 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
- 		if (error)
- 			break;
- 
- 		offset += chdr->c_seghdrsize;
- 		error = vn_rdwr(UIO_WRITE, vp,
- 		    (caddr_t)(u_long)cseg.c_addr, (int)cseg.c_size,
- 		    offset, UIO_USERSPACE,
- 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
- 		if (error)
- 			break;
- 
- 		offset += cseg.c_size;
- 		chdr->c_nseg++;
- 	}
- 
- 	return (error);
- }
--- 0 ----
Index: conf/files
===================================================================
RCS file: /cvsroot/syssrc/sys/conf/files,v
retrieving revision 1.478
diff -c -r1.478 files
*** conf/files	2001/12/03 23:28:20	1.478
--- conf/files	2001/12/06 04:14:45
***************
*** 1008,1013 ****
--- 1008,1014 ----
  file	isofs/cd9660/cd9660_util.c	cd9660
  file	isofs/cd9660/cd9660_vfsops.c	cd9660
  file	isofs/cd9660/cd9660_vnops.c	cd9660
+ file	kern/core_netbsd.c
  file	kern/cnmagic.c
  file	kern/exec_aout.c		exec_aout
  file	kern/exec_conf.c
Index: kern/core_netbsd.c
===================================================================
RCS file: core_netbsd.c
diff -N core_netbsd.c
*** /dev/null	Thu Dec  6 03:15:07 2001
--- core_netbsd.c	Thu Dec  6 06:14:56 2001
***************
*** 0 ****
--- 1,162 ----
+ /*	$NetBSD$	*/
+ 
+ /*
+  * Copyright (c) 1997 Charles D. Cranor and Washington University.
+  * Copyright (c) 1991, 1993 The Regents of the University of California.
+  * Copyright (c) 1988 University of Utah.
+  *
+  * All rights reserved.
+  *
+  * This code is derived from software contributed to Berkeley by
+  * the Systems Programming Group of the University of Utah Computer
+  * Science Department.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *      This product includes software developed by Charles D. Cranor,
+  *	Washington University, the University of California, Berkeley and
+  *	its contributors.
+  * 4. Neither the name of the University nor the names of its contributors
+  *    may be used to endorse or promote products derived from this software
+  *    without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  * SUCH DAMAGE.
+  *
+  * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
+  *      @(#)vm_unix.c   8.1 (Berkeley) 6/11/93
+  * from: NetBSD: uvm_unix.c,v 1.25 2001/11/10 07:37:01 lukem Exp
+  */
+ 
+ /*
+  * core_netbsd.c: Support for the historic NetBSD core file format.
+  */
+ 
+ #include <sys/cdefs.h>
+ __KERNEL_RCSID(0, "$NetBSD$");
+ 
+ #include <sys/param.h>
+ #include <sys/systm.h>
+ #include <sys/proc.h>
+ #include <sys/vnode.h>
+ #include <sys/core.h>
+ 
+ #include <uvm/uvm.h>
+ 
+ int
+ coredump_netbsd(struct proc *p, struct vnode *vp, struct ucred *cred)
+ {
+ 	struct core core;
+ 	struct coreseg cseg;
+ 	struct vmspace *vm = p->p_vmspace;
+ 	struct vm_map *map = &vm->vm_map;
+ 	struct vm_map_entry *entry;
+ 	vaddr_t start, end, maxstack;
+ 	off_t offset;
+ 	int flag, error;
+ 
+ 	core.c_midmag = 0;
+ 	strncpy(core.c_name, p->p_comm, MAXCOMLEN);
+ 	core.c_nseg = 0;
+ 	core.c_signo = p->p_sigctx.ps_sig;
+ 	core.c_ucode = p->p_sigctx.ps_code;
+ 	core.c_cpusize = 0;
+ 	core.c_tsize = (u_long)ctob(vm->vm_tsize);
+ 	core.c_dsize = (u_long)ctob(vm->vm_dsize);
+ 	core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize));
+ 	error = cpu_coredump(p, vp, cred, &core);
+ 	if (error)
+ 		return (error);
+ 
+ #if 0
+ 	/*
+ 	 * XXX
+ 	 * It would be nice if we at least dumped the signal state (and made it
+ 	 * available at run time to the debugger, as well), but this code
+ 	 * hasn't actually had any effect for a long time, since we don't dump
+ 	 * the user area.  For now, it's dead.
+ 	 */
+ 	memcpy(&p->p_addr->u_kproc.kp_proc, p, sizeof(struct proc));
+ 	fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
+ #endif
+ 
+ 	offset = core.c_hdrsize + core.c_seghdrsize + core.c_cpusize;
+ 	maxstack = trunc_page(USRSTACK - ctob(vm->vm_ssize));
+ 
+ 	for (entry = map->header.next; entry != &map->header;
+ 	     entry = entry->next) {
+ 		/* Should never happen for a user process. */
+ 		if (UVM_ET_ISSUBMAP(entry))
+ 			panic("coredump_netbsd: user process with submap?");
+ 
+ 		if ((entry->protection & VM_PROT_WRITE) == 0)
+ 			continue;
+ 
+ 		start = entry->start;
+ 		end = entry->end;
+ 
+ 		if (start >= VM_MAXUSER_ADDRESS)
+ 			continue;
+ 
+ 		if (end > VM_MAXUSER_ADDRESS)
+ 			end = VM_MAXUSER_ADDRESS;
+ 
+ 		if (start >= (vaddr_t)vm->vm_maxsaddr) {
+ 			if (end <= maxstack)
+ 				continue;
+ 			if (start < maxstack)
+ 				start = maxstack;
+ 			flag = CORE_STACK;
+ 		} else
+ 			flag = CORE_DATA;
+ 
+ 		/*
+ 		 * Set up a new core file segment.
+ 		 */
+ 		CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(core), flag);
+ 		cseg.c_addr = start;
+ 		cseg.c_size = end - start;
+ 
+ 		error = vn_rdwr(UIO_WRITE, vp,
+ 		    (caddr_t)&cseg, core.c_seghdrsize,
+ 		    offset, UIO_SYSSPACE,
+ 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
+ 		if (error)
+ 			return (error);
+ 
+ 		offset += core.c_seghdrsize;
+ 		error = vn_rdwr(UIO_WRITE, vp,
+ 		    (caddr_t)cseg.c_addr, (int)cseg.c_size,
+ 		    offset, UIO_USERSPACE,
+ 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
+ 		if (error)
+ 			return (error);
+ 
+ 		offset += cseg.c_size;
+ 		core.c_nseg++;
+ 	}
+ 
+ 	/* Now write out the core header. */
+ 	error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&core,
+ 	    (int)core.c_hdrsize, (off_t)0,
+ 	    UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p);
+ 
+ 	return (error);
+ }
Index: kern/exec_conf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/exec_conf.c,v
retrieving revision 1.62
diff -c -r1.62 exec_conf.c
*** kern/exec_conf.c	2001/11/28 11:45:36	1.62
--- kern/exec_conf.c	2001/12/06 04:14:56
***************
*** 53,58 ****
--- 53,59 ----
  
  #include <sys/param.h>
  #include <sys/exec.h>
+ #include <sys/signalvar.h>
  
  #ifdef EXEC_SCRIPT
  #include <sys/exec_script.h>
***************
*** 175,181 ****
  #ifdef COMPAT_NETBSD32
  	{ sizeof(struct netbsd32_exec), exec_netbsd32_makecmds, { NULL },
  	  &emul_netbsd32, EXECSW_PRIO_FIRST,
! 	  0, netbsd32_copyargs, NULL }, /* sparc 32 bit */
  #endif
  	{ sizeof(struct exec), exec_aout_makecmds, { NULL },
  #ifdef COMPAT_AOUT
--- 176,182 ----
  #ifdef COMPAT_NETBSD32
  	{ sizeof(struct netbsd32_exec), exec_netbsd32_makecmds, { NULL },
  	  &emul_netbsd32, EXECSW_PRIO_FIRST,
! 	  0, netbsd32_copyargs, NULL, coredump_netbsd32 }, /* sparc 32 bit */
  #endif
  	{ sizeof(struct exec), exec_aout_makecmds, { NULL },
  #ifdef COMPAT_AOUT
***************
*** 186,197 ****
  	  &emul_netbsd,
  #endif /* COMPAT_AOUT */
  	  EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* a.out binaries */
  #endif
  #ifdef EXEC_COFF
  	{ COFF_HDR_SIZE, exec_coff_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* coff binaries */
  #endif
  #ifdef EXEC_ECOFF
  #ifdef COMPAT_OSF1
--- 187,198 ----
  	  &emul_netbsd,
  #endif /* COMPAT_AOUT */
  	  EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* a.out binaries */
  #endif
  #ifdef EXEC_COFF
  	{ COFF_HDR_SIZE, exec_coff_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* coff binaries */
  #endif
  #ifdef EXEC_ECOFF
  #ifdef COMPAT_OSF1
***************
*** 200,216 ****
  	  &emul_osf1, EXECSW_PRIO_ANY,
    	  howmany(OSF1_MAX_AUX_ENTRIES * sizeof (struct osf1_auxv) +
  	    2 * (MAXPATHLEN + 1), sizeof (char *)), /* exec & loader names */
! 	  osf1_copyargs, cpu_exec_ecoff_setregs }, /* OSF1 ecoff binaries */
  #endif /* COMPAT_OSF1 */
  	{ ECOFF_HDR_SIZE, exec_ecoff_makecmds,
  	  { .ecoff_probe_func = cpu_exec_ecoff_probe },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, cpu_exec_ecoff_setregs },	/* ecoff binaries */
  #ifdef COMPAT_ULTRIX
  	{ ECOFF_HDR_SIZE, exec_ecoff_makecmds,
  	  { .ecoff_probe_func = ultrix_exec_ecoff_probe },
  	  &emul_ultrix, EXECSW_PRIO_LAST, /* XXX probe func alw. succeeds */
!   	  0, copyargs, cpu_exec_ecoff_setregs }, /* Ultrix ecoff binaries */
  #endif /* COMPAT_ULTRIX */
  #endif
  #ifdef EXEC_ELF32
--- 201,220 ----
  	  &emul_osf1, EXECSW_PRIO_ANY,
    	  howmany(OSF1_MAX_AUX_ENTRIES * sizeof (struct osf1_auxv) +
  	    2 * (MAXPATHLEN + 1), sizeof (char *)), /* exec & loader names */
! 	  osf1_copyargs, cpu_exec_ecoff_setregs,
! 	  coredump_netbsd }, /* OSF1 ecoff binaries */
  #endif /* COMPAT_OSF1 */
  	{ ECOFF_HDR_SIZE, exec_ecoff_makecmds,
  	  { .ecoff_probe_func = cpu_exec_ecoff_probe },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, cpu_exec_ecoff_setregs,
! 	  coredump_netbsd},	/* ecoff binaries */
  #ifdef COMPAT_ULTRIX
  	{ ECOFF_HDR_SIZE, exec_ecoff_makecmds,
  	  { .ecoff_probe_func = ultrix_exec_ecoff_probe },
  	  &emul_ultrix, EXECSW_PRIO_LAST, /* XXX probe func alw. succeeds */
!   	  0, copyargs, cpu_exec_ecoff_setregs,
! 	  coredump_netbsd }, /* Ultrix ecoff binaries */
  #endif /* COMPAT_ULTRIX */
  #endif
  #ifdef EXEC_ELF32
***************
*** 220,287 ****
  	  { ELF32NAME2(netbsd32,probe) },
  	  &emul_netbsd32, EXECSW_PRIO_FIRST,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), sizeof (Elf32_Addr)),
! 	  netbsd32_elf32_copyargs, NULL }, /* NetBSD32 32bit ELF bins */
  	  /* This one should go first so it matches instead of netbsd */
  #endif
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(netbsd,probe) },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), sizeof (Elf32_Addr)),
! 	  elf32_copyargs, NULL },	/* NetBSD 32bit ELF bins */
  #ifdef COMPAT_FREEBSD
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(freebsd,probe) },
  	  &emul_freebsd, EXECSW_PRIO_ANY,
  	  FREEBSD_ELF_AUX_ARGSIZ,
! 	  elf32_copyargs, NULL },	/* FreeBSD 32bit ELF bins (not 64bit safe )*/
  #endif
  #ifdef COMPAT_LINUX
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(linux,probe) },
  	  &emul_linux, EXECSW_PRIO_ANY,
  	  LINUX_ELF_AUX_ARGSIZ,
! 	  LINUX_COPYARGS_FUNCTION, NULL },	/* Linux 32bit ELF bins */
  #endif
  #if defined(EXEC_MACHO) && defined(COMPAT_MACH)
  	{ sizeof (struct exec_macho_fat_header), exec_macho_makecmds,
  	  { .mach_probe_func = exec_mach_probe },
  	  &emul_mach, EXECSW_PRIO_ANY,
  	  MAXPATHLEN + 1,
! 	  exec_mach_copyargs, NULL },	/* Mach 32bit MACH-O bins */
  #endif
  #ifdef COMPAT_IRIX
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(irix,probe) },
  	  &emul_irix, EXECSW_PRIO_ANY,
  	  IRIX_AUX_ARGSIZ,
! 	  irix_elf32_copyargs, NULL }, /* IRIX o32 ELF bins */
  #endif
  #ifdef COMPAT_SVR4_32
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(svr4_32,probe) },
  	  &emul_svr4_32, EXECSW_PRIO_ANY,
  	  SVR4_32_AUX_ARGSIZ,
! 	  svr4_32_copyargs, NULL }, /* SVR4 32bit ELF bins (not 64bit safe) */
  #endif
  #ifdef COMPAT_SVR4
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(svr4,probe) },
  	  &emul_svr4, EXECSW_PRIO_ANY,
  	  SVR4_AUX_ARGSIZ,
! 	  svr4_copyargs, NULL },   /* SVR4 32bit ELF bins (not 64bit safe) */
  #endif
  #ifdef COMPAT_IBCS2
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(ibcs2,probe) },
  	  &emul_ibcs2, EXECSW_PRIO_ANY,
! 	  IBCS2_ELF_AUX_ARGSIZ, elf32_copyargs, NULL },
  				/* SCO 32bit ELF bins (not 64bit safe) */
  #endif
  #ifdef EXEC_ELF_CATCHALL
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_LAST,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), sizeof (Elf32_Addr)),
! 	  elf32_copyargs, NULL }, /* catch all - run as NetBSD 32bit ELF */
  #endif
  #endif /* EXEC_ELF32 */
  #ifdef EXEC_ELF64
--- 224,298 ----
  	  { ELF32NAME2(netbsd32,probe) },
  	  &emul_netbsd32, EXECSW_PRIO_FIRST,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), sizeof (Elf32_Addr)),
! 	  netbsd32_elf32_copyargs, NULL,
! 	  coredump_netbsd32 }, /* NetBSD32 32bit ELF bins */
  	  /* This one should go first so it matches instead of netbsd */
  #endif
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(netbsd,probe) },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), sizeof (Elf32_Addr)),
! 	  elf32_copyargs, NULL, coredump_netbsd }, /* NetBSD 32bit ELF bins */
  #ifdef COMPAT_FREEBSD
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(freebsd,probe) },
  	  &emul_freebsd, EXECSW_PRIO_ANY,
  	  FREEBSD_ELF_AUX_ARGSIZ,
! 	  elf32_copyargs, NULL,
! 	  coredump_netbsd }, /* FreeBSD 32bit ELF bins (not 64bit safe )*/
  #endif
  #ifdef COMPAT_LINUX
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(linux,probe) },
  	  &emul_linux, EXECSW_PRIO_ANY,
  	  LINUX_ELF_AUX_ARGSIZ,
! 	  LINUX_COPYARGS_FUNCTION, NULL,
! 	  coredump_netbsd },	/* Linux 32bit ELF bins */
  #endif
  #if defined(EXEC_MACHO) && defined(COMPAT_MACH)
  	{ sizeof (struct exec_macho_fat_header), exec_macho_makecmds,
  	  { .mach_probe_func = exec_mach_probe },
  	  &emul_mach, EXECSW_PRIO_ANY,
  	  MAXPATHLEN + 1,
! 	  exec_mach_copyargs, NULL,
! 	  coredump_netbsd },	/* Mach 32bit MACH-O bins */
  #endif
  #ifdef COMPAT_IRIX
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(irix,probe) },
  	  &emul_irix, EXECSW_PRIO_ANY,
  	  IRIX_AUX_ARGSIZ,
! 	  irix_elf32_copyargs, NULL, coredump_netbsd }, /* IRIX o32 ELF bins */
  #endif
  #ifdef COMPAT_SVR4_32
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(svr4_32,probe) },
  	  &emul_svr4_32, EXECSW_PRIO_ANY,
  	  SVR4_32_AUX_ARGSIZ,
! 	  svr4_32_copyargs, NULL,
! 	  coredump_netbsd32 }, /* SVR4 32bit ELF bins (not 64bit safe) */
  #endif
  #ifdef COMPAT_SVR4
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(svr4,probe) },
  	  &emul_svr4, EXECSW_PRIO_ANY,
  	  SVR4_AUX_ARGSIZ,
! 	  svr4_copyargs, NULL,
! 	  coredump_netbsd },   /* SVR4 32bit ELF bins (not 64bit safe) */
  #endif
  #ifdef COMPAT_IBCS2
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds,
  	  { ELF32NAME2(ibcs2,probe) },
  	  &emul_ibcs2, EXECSW_PRIO_ANY,
! 	  IBCS2_ELF_AUX_ARGSIZ, elf32_copyargs, NULL, coredump_netbsd },
  				/* SCO 32bit ELF bins (not 64bit safe) */
  #endif
  #ifdef EXEC_ELF_CATCHALL
  	{ sizeof (Elf32_Ehdr), exec_elf32_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_LAST,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), sizeof (Elf32_Addr)),
! 	  elf32_copyargs, NULL,
! 	  coredump_netbsd }, /* catch all - run as NetBSD 32bit ELF */
  #endif
  #endif /* EXEC_ELF32 */
  #ifdef EXEC_ELF64
***************
*** 290,366 ****
  	  { ELF64NAME2(netbsd,probe) },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux64Info), sizeof (Elf64_Addr)),
! 	  elf64_copyargs, NULL }, 	/* NetBSD 64bit ELF bins */
  #ifdef COMPAT_LINUX
  	{ sizeof (Elf64_Ehdr), exec_elf64_makecmds,
  	  { ELF64NAME2(linux,probe) },
  	  &emul_linux, EXECSW_PRIO_ANY,
  	  LINUX_ELF_AUX_ARGSIZ,
! 	  linux_elf64_copyargs, NULL },	/* Linux 64bit ELF bins */
  #endif
  #ifdef COMPAT_SVR4
  	{ sizeof (Elf64_Ehdr), exec_elf64_makecmds,
  	  { ELF64NAME2(svr4,probe) },
  	  &emul_svr4, EXECSW_PRIO_ANY,
  	  SVR4_AUX_ARGSIZ64,
! 	  svr4_copyargs64, NULL },	/* SVR4 64bit ELF bins (not 64bit safe) */
  #endif
  #ifdef EXEC_ELF_CATCHALL
  	{ sizeof (Elf64_Ehdr), exec_elf64_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux64Info), sizeof (Elf64_Addr)),
! 	  elf64_copyargs, NULL }, /* catch all - run as NetBSD 64bit ELF */
  #endif
  #endif /* EXEC_ELF64 */
  #ifdef COMPAT_SUNOS
  #ifdef COMPAT_NETBSD32
  	{ SUNOS32_AOUT_HDR_SIZE, exec_sunos32_aout_makecmds, { NULL },
  	  &emul_sunos, EXECSW_PRIO_ANY,
! 	  0, netbsd32_copyargs, NULL }, 	/* SunOS a.out, 64-bit kernel */
  #else
  	{ SUNOS_AOUT_HDR_SIZE, exec_sunos_aout_makecmds, { NULL },
  	  &emul_sunos, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL }, 		/* SunOS a.out */
  #endif
  #endif
  #if defined(COMPAT_LINUX) && defined(EXEC_AOUT)
  	{ LINUX_AOUT_HDR_SIZE, exec_linux_aout_makecmds, { NULL },
  	  &emul_linux, EXECSW_PRIO_ANY,
! 	  LINUX_AOUT_AUX_ARGSIZ, linux_aout_copyargs, NULL }, /* linux a.out */
  #endif
  #ifdef COMPAT_IBCS2
  	{ COFF_HDR_SIZE, exec_ibcs2_coff_makecmds, { NULL },
  	  &emul_ibcs2, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* coff binaries */
  	{ XOUT_HDR_SIZE, exec_ibcs2_xout_makecmds, { NULL },
  	  &emul_ibcs2, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* x.out binaries */
  #endif
  #if defined(COMPAT_FREEBSD) && defined(EXEC_AOUT)
  	{ FREEBSD_AOUT_HDR_SIZE, exec_freebsd_aout_makecmds, { NULL },
  	  &emul_freebsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* a.out */
  #endif
  #ifdef COMPAT_HPUX
  	{ HPUX_EXEC_HDR_SIZE, exec_hpux_makecmds, { NULL },
  	  &emul_hpux, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* HP-UX a.out */
  #endif
  #ifdef COMPAT_M68K4K
  	{ sizeof(struct exec), exec_m68k4k_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* m68k4k a.out */
  #endif
  #ifdef COMPAT_VAX1K
  	{ sizeof(struct exec), exec_vax1k_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL },	/* vax1k a.out */
  #endif
  #ifdef COMPAT_PECOFF
  	{ sizeof(struct exec), exec_pecoff_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY, /* XXX emul_pecoff once it's different */
  	  howmany(sizeof(struct pecoff_args), sizeof(char *)),
! 	  pecoff_copyargs, NULL },	/* Win32/CE PE/COFF */
  #endif
  };
  int nexecs_builtin = (sizeof(execsw_builtin) / sizeof(struct execsw));
--- 301,382 ----
  	  { ELF64NAME2(netbsd,probe) },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux64Info), sizeof (Elf64_Addr)),
! 	  elf64_copyargs, NULL, coredump_netbsd }, /* NetBSD 64bit ELF bins */
  #ifdef COMPAT_LINUX
  	{ sizeof (Elf64_Ehdr), exec_elf64_makecmds,
  	  { ELF64NAME2(linux,probe) },
  	  &emul_linux, EXECSW_PRIO_ANY,
  	  LINUX_ELF_AUX_ARGSIZ,
! 	  linux_elf64_copyargs, NULL,
! 	  coredump_netbsd },	/* Linux 64bit ELF bins */
  #endif
  #ifdef COMPAT_SVR4
  	{ sizeof (Elf64_Ehdr), exec_elf64_makecmds,
  	  { ELF64NAME2(svr4,probe) },
  	  &emul_svr4, EXECSW_PRIO_ANY,
  	  SVR4_AUX_ARGSIZ64,
! 	  svr4_copyargs64, NULL,
! 	  coredump_netbsd },	/* SVR4 64bit ELF bins (not 64bit safe) */
  #endif
  #ifdef EXEC_ELF_CATCHALL
  	{ sizeof (Elf64_Ehdr), exec_elf64_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
  	  howmany(ELF_AUX_ENTRIES * sizeof(Aux64Info), sizeof (Elf64_Addr)),
! 	  elf64_copyargs, NULL,
! 	  coredump_netbsd }, /* catch all - run as NetBSD 64bit ELF */
  #endif
  #endif /* EXEC_ELF64 */
  #ifdef COMPAT_SUNOS
  #ifdef COMPAT_NETBSD32
  	{ SUNOS32_AOUT_HDR_SIZE, exec_sunos32_aout_makecmds, { NULL },
  	  &emul_sunos, EXECSW_PRIO_ANY,
! 	  0, netbsd32_copyargs, NULL,
! 	  coredump_netbsd }, 	/* SunOS a.out, 64-bit kernel */
  #else
  	{ SUNOS_AOUT_HDR_SIZE, exec_sunos_aout_makecmds, { NULL },
  	  &emul_sunos, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* SunOS a.out */
  #endif
  #endif
  #if defined(COMPAT_LINUX) && defined(EXEC_AOUT)
  	{ LINUX_AOUT_HDR_SIZE, exec_linux_aout_makecmds, { NULL },
  	  &emul_linux, EXECSW_PRIO_ANY,
! 	  LINUX_AOUT_AUX_ARGSIZ, linux_aout_copyargs, NULL,
! 	  coredump_netbsd }, /* linux a.out */
  #endif
  #ifdef COMPAT_IBCS2
  	{ COFF_HDR_SIZE, exec_ibcs2_coff_makecmds, { NULL },
  	  &emul_ibcs2, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* coff binaries */
  	{ XOUT_HDR_SIZE, exec_ibcs2_xout_makecmds, { NULL },
  	  &emul_ibcs2, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* x.out binaries */
  #endif
  #if defined(COMPAT_FREEBSD) && defined(EXEC_AOUT)
  	{ FREEBSD_AOUT_HDR_SIZE, exec_freebsd_aout_makecmds, { NULL },
  	  &emul_freebsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* a.out */
  #endif
  #ifdef COMPAT_HPUX
  	{ HPUX_EXEC_HDR_SIZE, exec_hpux_makecmds, { NULL },
  	  &emul_hpux, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* HP-UX a.out */
  #endif
  #ifdef COMPAT_M68K4K
  	{ sizeof(struct exec), exec_m68k4k_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* m68k4k a.out */
  #endif
  #ifdef COMPAT_VAX1K
  	{ sizeof(struct exec), exec_vax1k_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY,
! 	  0, copyargs, NULL, coredump_netbsd },	/* vax1k a.out */
  #endif
  #ifdef COMPAT_PECOFF
  	{ sizeof(struct exec), exec_pecoff_makecmds, { NULL },
  	  &emul_netbsd, EXECSW_PRIO_ANY, /* XXX emul_pecoff once it's different */
  	  howmany(sizeof(struct pecoff_args), sizeof(char *)),
! 	  pecoff_copyargs, NULL, coredump_netbsd }, /* Win32/CE PE/COFF */
  #endif
  };
  int nexecs_builtin = (sizeof(execsw_builtin) / sizeof(struct execsw));
Index: kern/kern_exec.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/kern_exec.c,v
retrieving revision 1.147
diff -c -r1.147 kern_exec.c
*** kern/kern_exec.c	2001/11/23 22:02:39	1.147
--- kern/kern_exec.c	2001/12/06 04:14:57
***************
*** 677,682 ****
--- 677,686 ----
  
  	/* update p_emul, the old value is no longer needed */
  	p->p_emul = pack.ep_es->es_emul;
+ 
+ 	/* ...and the same for p_coredump */
+ 	p->p_coredump = pack.ep_es->es_coredump;
+ 
  #ifdef __HAVE_SYSCALL_INTERN
  	(*p->p_emul->e_syscall_intern)(p);
  #endif
Index: kern/kern_fork.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/kern_fork.c,v
retrieving revision 1.87
diff -c -r1.87 kern_fork.c
*** kern/kern_fork.c	2001/11/12 15:25:09	1.87
--- kern/kern_fork.c	2001/12/06 04:14:58
***************
*** 283,288 ****
--- 283,289 ----
  	 */
  	p2->p_flag = P_INMEM | (p1->p_flag & P_SUGID);
  	p2->p_emul = p1->p_emul;
+ 	p2->p_coredump = p1->p_coredump;
  
  	if (p1->p_flag & P_PROFIL)
  		startprofclock(p2);
Index: kern/kern_sig.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/kern_sig.c,v
retrieving revision 1.116
diff -c -r1.116 kern_sig.c
*** kern/kern_sig.c	2001/11/12 15:25:15	1.116
--- kern/kern_sig.c	2001/12/06 04:14:59
***************
*** 1322,1328 ****
  	struct vattr		vattr;
  	int			error, error1;
  	char			name[MAXPATHLEN];
- 	struct core		core;
  
  	vm = p->p_vmspace;
  	cred = p->p_cred->pc_ucred;
--- 1322,1327 ----
***************
*** 1374,1415 ****
  	VOP_SETATTR(vp, &vattr, cred, p);
  	p->p_acflag |= ACORE;
  
! 	if ((p->p_flag & P_32) && coredump32_hook != NULL)
! 		return (*coredump32_hook)(p, vp);
! #if 0
! 	/*
! 	 * XXX
! 	 * It would be nice if we at least dumped the signal state (and made it
! 	 * available at run time to the debugger, as well), but this code
! 	 * hasn't actually had any effect for a long time, since we don't dump
! 	 * the user area.  For now, it's dead.
! 	 */
! 	memcpy(&p->p_addr->u_kproc.kp_proc, p, sizeof(struct proc));
! 	fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
! #endif
! 
! 	core.c_midmag = 0;
! 	strncpy(core.c_name, p->p_comm, MAXCOMLEN);
! 	core.c_nseg = 0;
! 	core.c_signo = p->p_sigctx.ps_sig;
! 	core.c_ucode = p->p_sigctx.ps_code;
! 	core.c_cpusize = 0;
! 	core.c_tsize = (u_long)ctob(vm->vm_tsize);
! 	core.c_dsize = (u_long)ctob(vm->vm_dsize);
! 	core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize));
! 	error = cpu_coredump(p, vp, cred, &core);
! 	if (error)
! 		goto out;
! 	/*
! 	 * uvm_coredump() spits out all appropriate segments.
! 	 * All that's left to do is to write the core header.
! 	 */
! 	error = uvm_coredump(p, vp, cred, &core);
! 	if (error)
! 		goto out;
! 	error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&core,
! 	    (int)core.c_hdrsize, (off_t)0,
! 	    UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p);
   out:
  	VOP_UNLOCK(vp, 0);
  	error1 = vn_close(vp, FWRITE, cred, p);
--- 1373,1380 ----
  	VOP_SETATTR(vp, &vattr, cred, p);
  	p->p_acflag |= ACORE;
  
! 	/* Now dump the actual core file. */
! 	error = (*p->p_coredump)(p, vp, cred);
   out:
  	VOP_UNLOCK(vp, 0);
  	error1 = vn_close(vp, FWRITE, cred, p);
Index: sys/exec.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/exec.h,v
retrieving revision 1.81
diff -c -r1.81 exec.h
*** sys/exec.h	2001/07/29 21:23:19	1.81
--- sys/exec.h	2001/12/06 04:15:09
***************
*** 101,106 ****
--- 101,108 ----
  
  struct proc;
  struct exec_package;
+ struct vnode;
+ struct ucred;
  
  typedef int (*exec_makecmds_fcn) __P((struct proc *, struct exec_package *));
  
***************
*** 123,128 ****
--- 125,132 ----
  					/* Set registers before execution */
  	void	(*es_setregs) __P((struct proc *, struct exec_package *,
  				  u_long));
+ 	int	(*es_coredump) __P((struct proc *, struct vnode *,
+ 				    struct ucred *));
  };
  
  #define EXECSW_PRIO_ANY		0x000	/* default, no preference */
Index: sys/proc.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/proc.h,v
retrieving revision 1.134
diff -c -r1.134 proc.h
*** sys/proc.h	2001/09/18 19:36:32	1.134
--- sys/proc.h	2001/12/06 04:15:09
***************
*** 208,213 ****
--- 208,219 ----
  					 * Per-process emulation data, or NULL.
  					 * Malloc type M_EMULDATA
  					 */
+ 	/*
+ 	 * Pointer to the coredump routine that this process will use
+ 	 * in case it needs to do that.
+ 	 */
+ 	int		(*p_coredump)(struct proc *, struct vnode *,
+ 			    struct ucred *);
  
  /*
   * End area that is zeroed on creation
Index: sys/signalvar.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/signalvar.h,v
retrieving revision 1.30
diff -c -r1.30 signalvar.h
*** sys/signalvar.h	2001/06/06 21:46:59	1.30
--- sys/signalvar.h	2001/12/06 04:15:09
***************
*** 163,179 ****
  
  extern sigset_t contsigmask, stopsigmask, sigcantmask;
  
- /*
-  * Set if we need to short-cut coredump() with the 32-bit version
-  * on a 64-bit platform.
-  */
  struct vnode;
! extern	int (*coredump32_hook)(struct proc *p, struct vnode *vp);
  
  /*
   * Machine-independent functions:
   */
  int	coredump __P((struct proc *p));
  void	execsigs __P((struct proc *p));
  void	gsignal __P((int pgid, int sig));
  int	issignal __P((struct proc *p));
--- 163,177 ----
  
  extern sigset_t contsigmask, stopsigmask, sigcantmask;
  
  struct vnode;
! struct ucred;
  
  /*
   * Machine-independent functions:
   */
  int	coredump __P((struct proc *p));
+ int	coredump_netbsd __P((struct proc *p, struct vnode *vp,
+ 	    struct ucred *cred));
  void	execsigs __P((struct proc *p));
  void	gsignal __P((int pgid, int sig));
  int	issignal __P((struct proc *p));
***************
*** 210,217 ****
  void	sendsig __P((sig_t action, int sig, sigset_t *returnmask, u_long code));
  struct core;
  struct core32;
- struct vnode;
- struct ucred;
  int	cpu_coredump __P((struct proc *, struct vnode *, struct ucred *,
  			  struct core *));
  int	cpu_coredump32 __P((struct proc *, struct vnode *, struct ucred *, 
--- 208,213 ----
Index: uvm/uvm_extern.h
===================================================================
RCS file: /cvsroot/syssrc/sys/uvm/uvm_extern.h,v
retrieving revision 1.67
diff -c -r1.67 uvm_extern.h
*** uvm/uvm_extern.h	2001/09/15 20:36:45	1.67
--- uvm/uvm_extern.h	2001/12/06 04:15:10
***************
*** 647,659 ****
  void			uvm_swap_init __P((void));
  
  /* uvm_unix.c */
- int			uvm_coredump __P((struct proc *, struct vnode *,
- 				struct ucred *, struct core *));
  int			uvm_grow __P((struct proc *, vaddr_t));
- /* should only be needed if COMPAT_NETBSD32 is defined */
- struct core32;
- int			uvm_coredump32 __P((struct proc *, struct vnode *,
- 				struct ucred *, struct core32 *));
  
  /* uvm_user.c */
  void			uvm_deallocate __P((struct vm_map *, vaddr_t, vsize_t));
--- 647,653 ----
Index: uvm/uvm_unix.c
===================================================================
RCS file: /cvsroot/syssrc/sys/uvm/uvm_unix.c,v
retrieving revision 1.25
diff -c -r1.25 uvm_unix.c
*** uvm/uvm_unix.c	2001/11/10 07:37:01	1.25
--- uvm/uvm_unix.c	2001/12/06 04:15:10
***************
*** 57,63 ****
  #include <sys/proc.h>
  #include <sys/resourcevar.h>
  #include <sys/vnode.h>
- #include <sys/core.h>
  
  #include <sys/mount.h>
  #include <sys/syscallargs.h>
--- 57,62 ----
***************
*** 165,248 ****
  #endif
  
  	return (EINVAL);
- }
- 
- /*
-  * uvm_coredump: dump core!
-  */
- 
- int
- uvm_coredump(p, vp, cred, chdr)
- 	struct proc *p;
- 	struct vnode *vp;
- 	struct ucred *cred;
- 	struct core *chdr;
- {
- 	struct vmspace *vm = p->p_vmspace;
- 	struct vm_map *map = &vm->vm_map;
- 	struct vm_map_entry *entry;
- 	vaddr_t start, end, maxstack;
- 	struct coreseg cseg;
- 	off_t offset;
- 	int flag, error = 0;
- 
- 	offset = chdr->c_hdrsize + chdr->c_seghdrsize + chdr->c_cpusize;
- 	maxstack = trunc_page(USRSTACK - ctob(vm->vm_ssize));
- 
- 	for (entry = map->header.next; entry != &map->header;
- 	    entry = entry->next) {
- 
- 		/* should never happen for a user process */
- 		if (UVM_ET_ISSUBMAP(entry)) {
- 			panic("uvm_coredump: user process with submap?");
- 		}
- 
- 		if (!(entry->protection & VM_PROT_WRITE))
- 			continue;
- 
- 		start = entry->start;
- 		end = entry->end;
- 
- 		if (start >= VM_MAXUSER_ADDRESS)
- 			continue;
- 
- 		if (end > VM_MAXUSER_ADDRESS)
- 			end = VM_MAXUSER_ADDRESS;
- 
- 		if (start >= (vaddr_t)vm->vm_maxsaddr) {
- 			if (end <= maxstack)
- 				continue;
- 			if (start < maxstack)
- 				start = maxstack;
- 			flag = CORE_STACK;
- 		} else
- 			flag = CORE_DATA;
- 
- 		/*
- 		 * Set up a new core file segment.
- 		 */
- 		CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(*chdr), flag);
- 		cseg.c_addr = start;
- 		cseg.c_size = end - start;
- 
- 		error = vn_rdwr(UIO_WRITE, vp,
- 		    (caddr_t)&cseg, chdr->c_seghdrsize,
- 		    offset, UIO_SYSSPACE,
- 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
- 		if (error)
- 			break;
- 
- 		offset += chdr->c_seghdrsize;
- 		error = vn_rdwr(UIO_WRITE, vp,
- 		    (caddr_t)cseg.c_addr, (int)cseg.c_size,
- 		    offset, UIO_USERSPACE,
- 		    IO_NODELOCKED|IO_UNIT, cred, NULL, p);
- 		if (error)
- 			break;
- 
- 		offset += cseg.c_size;
- 		chdr->c_nseg++;
- 	}
- 
- 	return (error);
  }
--- 164,167 ----

--envbJBWh7q8WU6mo--