struct vm_map *map = &vm->vm_map; struct vm_map_entry *entry;
vm_map_t map = &vm->vm_map; vm_map_entry_t entry;
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;#ifdef MACHINE_STACK_GROWS_UP		if (start >= USRSTACK) {			start = USRSTACK;#else		if (start >= (vaddr_t)vm->vm_maxsaddr) {			start = trunc_page(USRSTACK - ctob(vm->vm_ssize));#endif			flag = CORE_STACK;			if (start >= end)				continue;		} 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);}