13584Ssos/*-
23584Ssos * Copyright (c) 1994 Sean Eric Fagan
3230132Suqs * Copyright (c) 1994 S��ren Schmidt
43584Ssos * All rights reserved.
53584Ssos *
63584Ssos * Redistribution and use in source and binary forms, with or without
73584Ssos * modification, are permitted provided that the following conditions
83584Ssos * are met:
93584Ssos * 1. Redistributions of source code must retain the above copyright
103584Ssos *    notice, this list of conditions and the following disclaimer
113584Ssos *    in this position and unchanged.
123584Ssos * 2. Redistributions in binary form must reproduce the above copyright
133584Ssos *    notice, this list of conditions and the following disclaimer in the
143584Ssos *    documentation and/or other materials provided with the distribution.
153584Ssos * 3. The name of the author may not be used to endorse or promote products
1697748Sschweikh *    derived from this software without specific prior written permission
173584Ssos *
183584Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
193584Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
203584Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
213584Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223584Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
233584Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243584Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
253584Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
263584Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
273584Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283584Ssos */
293584Ssos
30115684Sobrien#include <sys/cdefs.h>
31115684Sobrien__FBSDID("$FreeBSD$");
32115684Sobrien
333584Ssos#include <sys/param.h>
343584Ssos#include <sys/systm.h>
35160241Sjhb#include <sys/exec.h>
3676166Smarkm#include <sys/fcntl.h>
373584Ssos#include <sys/imgact.h>
383584Ssos#include <sys/kernel.h>
3976166Smarkm#include <sys/lock.h>
403584Ssos#include <sys/malloc.h>
4176166Smarkm#include <sys/mman.h>
423584Ssos#include <sys/mount.h>
4315494Sbde#include <sys/namei.h>
4415494Sbde#include <sys/vnode.h>
4512662Sdg
463584Ssos#include <vm/vm.h>
4712662Sdg#include <vm/pmap.h>
4812662Sdg#include <vm/vm_map.h>
493584Ssos#include <vm/vm_kern.h>
5012662Sdg#include <vm/vm_extern.h>
513584Ssos
5211397Sswallace#include <i386/ibcs2/coff.h>
5311397Sswallace#include <i386/ibcs2/ibcs2_util.h>
5411397Sswallace
5559753SpeterMODULE_DEPEND(coff, ibcs2, 1, 1, 1);
5659753Speter
5711397Sswallaceextern struct sysentvec ibcs2_svr3_sysvec;
5811397Sswallace
5992761Salfredstatic int coff_load_file(struct thread *td, char *name);
6092761Salfredstatic int exec_coff_imgact(struct image_params *imgp);
6111397Sswallace
6292761Salfredstatic int load_coff_section(struct vmspace *vmspace, struct vnode *vp, vm_offset_t offset, caddr_t vmaddr, size_t memsz, size_t filsz, vm_prot_t prot);
6311397Sswallace
643584Ssosstatic int
6528751Sbdeload_coff_section(struct vmspace *vmspace, struct vnode *vp, vm_offset_t offset,
6628751Sbde		  caddr_t vmaddr, size_t memsz, size_t filsz, vm_prot_t prot)
673584Ssos{
683584Ssos	size_t map_len;
693584Ssos	vm_offset_t map_offset;
707667Sjoerg	vm_offset_t map_addr;
713584Ssos	int error;
723584Ssos	unsigned char *data_buf = 0;
733584Ssos	size_t copy_len;
743584Ssos
753584Ssos	map_offset = trunc_page(offset);
7640286Sdg	map_addr = trunc_page((vm_offset_t)vmaddr);
773584Ssos
783584Ssos	if (memsz > filsz) {
793584Ssos		/*
803584Ssos		 * We have the stupid situation that
813584Ssos		 * the section is longer than it is on file,
823584Ssos		 * which means it has zero-filled areas, and
833584Ssos		 * we have to work for it.  Stupid iBCS!
843584Ssos		 */
853584Ssos		map_len = trunc_page(offset + filsz) - trunc_page(map_offset);
863584Ssos	} else {
873584Ssos		/*
883584Ssos		 * The only stuff we care about is on disk, and we
893584Ssos		 * don't care if we map in more than is really there.
903584Ssos		 */
913584Ssos		map_len = round_page(offset + filsz) - trunc_page(map_offset);
923584Ssos	}
933584Ssos
94224613Skib	DPRINTF(("%s(%d):  vm_mmap(&vmspace->vm_map, &0x%08jx, 0x%x, 0x%x, "
95144501Sjhb		"VM_PROT_ALL, MAP_PRIVATE | MAP_FIXED, OBJT_VNODE, vp, 0x%x)\n",
96224613Skib		__FILE__, __LINE__, (uintmax_t)map_addr, map_len, prot,
97224613Skib	        map_offset));
983584Ssos
9943314Sdillon	if ((error = vm_mmap(&vmspace->vm_map,
1003584Ssos			     &map_addr,
1013584Ssos			     map_len,
1023584Ssos			     prot,
1033584Ssos			     VM_PROT_ALL,
10414584Speter			     MAP_PRIVATE | MAP_FIXED,
105144501Sjhb			     OBJT_VNODE,
106144501Sjhb			     vp,
10743314Sdillon			     map_offset)) != 0)
1083584Ssos		return error;
1093584Ssos
1103584Ssos	if (memsz == filsz) {
1113584Ssos		/* We're done! */
1123584Ssos		return 0;
1133584Ssos	}
1143584Ssos
1153584Ssos	/*
1163584Ssos	 * Now we have screwball stuff, to accomodate stupid COFF.
1173584Ssos	 * We have to map the remaining bit of the file into the kernel's
1183584Ssos	 * memory map, allocate some anonymous memory, copy that last
1193584Ssos	 * bit into it, and then we're done. *sigh*
1203584Ssos	 * For clean-up reasons, we actally map in the file last.
1213584Ssos	 */
1223584Ssos
1233584Ssos	copy_len = (offset + filsz) - trunc_page(offset + filsz);
12440286Sdg	map_addr = trunc_page((vm_offset_t)vmaddr + filsz);
12540286Sdg	map_len = round_page((vm_offset_t)vmaddr + memsz) - map_addr;
1263584Ssos
127224613Skib	DPRINTF(("%s(%d): vm_map_find(&vmspace->vm_map, NULL, 0, &0x%08jx,0x%x, VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0)\n", __FILE__, __LINE__, (uintmax_t)map_addr, map_len));
1283584Ssos
1296581Sdg	if (map_len != 0) {
1307667Sjoerg		error = vm_map_find(&vmspace->vm_map, NULL, 0, &map_addr,
131255426Sjhb		    map_len, 0, VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0);
1326581Sdg		if (error)
133224613Skib			return (vm_mmap_to_errno(error));
1346581Sdg	}
1353584Ssos
136224613Skib	if ((error = vm_mmap(exec_map,
1377667Sjoerg			    (vm_offset_t *) &data_buf,
1387667Sjoerg			    PAGE_SIZE,
1397667Sjoerg			    VM_PROT_READ,
1407667Sjoerg			    VM_PROT_READ,
14114584Speter			    0,
142144501Sjhb			    OBJT_VNODE,
143144501Sjhb			    vp,
14443314Sdillon			    trunc_page(offset + filsz))) != 0)
1453584Ssos		return error;
1463584Ssos
14714583Speter	error = copyout(data_buf, (caddr_t) map_addr, copy_len);
1483584Ssos
149254025Sjeff	kmap_free_wakeup(exec_map, (vm_offset_t)data_buf, PAGE_SIZE);
1503584Ssos
15114583Speter	return error;
1523584Ssos}
1538876Srgrimes
15433181Seivindstatic int
15583366Sjuliancoff_load_file(struct thread *td, char *name)
1563584Ssos{
15783366Sjulian	struct proc *p = td->td_proc;
1583584Ssos  	struct vmspace *vmspace = p->p_vmspace;
1593584Ssos  	int error;
1603584Ssos  	struct nameidata nd;
16112130Sdg  	struct vnode *vp;
1623584Ssos  	struct vattr attr;
1633584Ssos  	struct filehdr *fhdr;
1643584Ssos  	struct aouthdr *ahdr;
1653584Ssos  	struct scnhdr *scns;
1663584Ssos  	char *ptr = 0;
1673584Ssos  	int nscns;
1683584Ssos  	unsigned long text_offset = 0, text_address = 0, text_size = 0;
1693584Ssos  	unsigned long data_offset = 0, data_address = 0, data_size = 0;
1703584Ssos  	unsigned long bss_size = 0;
171242476Skib	int i, writecount;
1723584Ssos
173145584Sjeff	NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | FOLLOW | SAVENAME,
174145584Sjeff	    UIO_SYSSPACE, name, td);
1758876Srgrimes
1763584Ssos  	error = namei(&nd);
1773584Ssos  	if (error)
1783584Ssos    		return error;
1798876Srgrimes
18012130Sdg  	vp = nd.ni_vp;
18112130Sdg  	if (vp == NULL)
1823584Ssos    		return ENOEXEC;
1838876Srgrimes
184242476Skib	error = VOP_GET_WRITECOUNT(vp, &writecount);
185242476Skib	if (error != 0)
186242476Skib		goto fail;
187242476Skib	if (writecount != 0) {
1883584Ssos    		error = ETXTBSY;
1893584Ssos    		goto fail;
1903584Ssos  	}
1913584Ssos
192182371Sattilio  	if ((error = VOP_GETATTR(vp, &attr, td->td_ucred)) != 0)
1933584Ssos    		goto fail;
1943584Ssos
19512130Sdg  	if ((vp->v_mount->mnt_flag & MNT_NOEXEC)
1963584Ssos	    || ((attr.va_mode & 0111) == 0)
19771699Sjhb	    || (attr.va_type != VREG))
1983584Ssos    		goto fail;
1993584Ssos
2003584Ssos  	if (attr.va_size == 0) {
2013584Ssos    		error = ENOEXEC;
2023584Ssos    		goto fail;
2033584Ssos  	}
2043584Ssos
20591406Sjhb  	if ((error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td)) != 0)
2063584Ssos    		goto fail;
2073584Ssos
208170152Skib  	if ((error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL)) != 0)
2093584Ssos    		goto fail;
2103584Ssos
21110705Ssef	/*
21210705Ssef	 * Lose the lock on the vnode. It's no longer needed, and must not
21310705Ssef	 * exist for the pagefault paging to work below.
21410705Ssef	 */
215175294Sattilio	VOP_UNLOCK(vp, 0);
21610705Ssef
217224613Skib	if ((error = vm_mmap(exec_map,
2187667Sjoerg			    (vm_offset_t *) &ptr,
2197667Sjoerg			    PAGE_SIZE,
2207667Sjoerg			    VM_PROT_READ,
2217667Sjoerg		       	    VM_PROT_READ,
22214584Speter			    0,
223144501Sjhb			    OBJT_VNODE,
224144501Sjhb			    vp,
22543314Sdillon			    0)) != 0)
22653155Seivind		goto unlocked_fail;
2273584Ssos
2283584Ssos  	fhdr = (struct filehdr *)ptr;
2293584Ssos
2303584Ssos  	if (fhdr->f_magic != I386_COFF) {
2313584Ssos    		error = ENOEXEC;
2323584Ssos    		goto dealloc_and_fail;
2333584Ssos  	}
2343584Ssos
2353584Ssos  	nscns = fhdr->f_nscns;
2363584Ssos
2373584Ssos  	if ((nscns * sizeof(struct scnhdr)) > PAGE_SIZE) {
2383584Ssos    		/*
2393584Ssos     		 * XXX -- just fail.  I'm so lazy.
2403584Ssos     		 */
2413584Ssos    		error = ENOEXEC;
2423584Ssos    		goto dealloc_and_fail;
2433584Ssos  	}
2443584Ssos
2453584Ssos  	ahdr = (struct aouthdr*)(ptr + sizeof(struct filehdr));
2463584Ssos
2473584Ssos  	scns = (struct scnhdr*)(ptr + sizeof(struct filehdr)
2483584Ssos			  + sizeof(struct aouthdr));
2493584Ssos
2503584Ssos  	for (i = 0; i < nscns; i++) {
2513584Ssos    		if (scns[i].s_flags & STYP_NOLOAD)
2523584Ssos      			continue;
2533584Ssos    		else if (scns[i].s_flags & STYP_TEXT) {
2543584Ssos      			text_address = scns[i].s_vaddr;
2553584Ssos      			text_size = scns[i].s_size;
2563584Ssos      			text_offset = scns[i].s_scnptr;
2578876Srgrimes    		}
2583584Ssos		else if (scns[i].s_flags & STYP_DATA) {
2593584Ssos      			data_address = scns[i].s_vaddr;
2603584Ssos      			data_size = scns[i].s_size;
2613584Ssos      			data_offset = scns[i].s_scnptr;
2623584Ssos    		} else if (scns[i].s_flags & STYP_BSS) {
2633584Ssos      			bss_size = scns[i].s_size;
2643584Ssos    		}
2653584Ssos  	}
2663584Ssos
26743314Sdillon  	if ((error = load_coff_section(vmspace, vp, text_offset,
26838354Sbde				      (caddr_t)(void *)(uintptr_t)text_address,
2693584Ssos				      text_size, text_size,
27043314Sdillon				      VM_PROT_READ | VM_PROT_EXECUTE)) != 0) {
2713584Ssos    		goto dealloc_and_fail;
2723584Ssos  	}
27343314Sdillon  	if ((error = load_coff_section(vmspace, vp, data_offset,
27438354Sbde				      (caddr_t)(void *)(uintptr_t)data_address,
2753584Ssos				      data_size + bss_size, data_size,
27643314Sdillon				      VM_PROT_ALL)) != 0) {
2773584Ssos    		goto dealloc_and_fail;
2783584Ssos  	}
2793584Ssos
2803584Ssos  	error = 0;
2813584Ssos
28253155Seivind dealloc_and_fail:
283254025Sjeff	kmap_free_wakeup(exec_map, (vm_offset_t)ptr,  PAGE_SIZE);
2843584Ssos fail:
285175294Sattilio	VOP_UNLOCK(vp, 0);
28653155Seivind unlocked_fail:
28754655Seivind	NDFREE(&nd, NDF_ONLY_PNBUF);
28853155Seivind	vrele(nd.ni_vp);
2893584Ssos  	return error;
2903584Ssos}
2913584Ssos
29233181Seivindstatic int
29312130Sdgexec_coff_imgact(imgp)
29412130Sdg	struct image_params *imgp;
2953584Ssos{
29618024Sbde	const struct filehdr *fhdr = (const struct filehdr*)imgp->image_header;
29718024Sbde	const struct aouthdr *ahdr;
29818024Sbde	const struct scnhdr *scns;
2993584Ssos	int i;
30024848Sdyson	struct vmspace *vmspace;
3013584Ssos	int nscns;
30216322Sgpalmer	int error;
3033584Ssos	unsigned long text_offset = 0, text_address = 0, text_size = 0;
3043584Ssos	unsigned long data_offset = 0, data_address = 0, data_size = 0;
3053584Ssos	unsigned long bss_size = 0;
306224613Skib	vm_offset_t hole;
3073584Ssos
3083584Ssos	if (fhdr->f_magic != I386_COFF ||
3093584Ssos	    !(fhdr->f_flags & F_EXEC)) {
3103584Ssos
31111397Sswallace		 DPRINTF(("%s(%d): return -1\n", __FILE__, __LINE__));
31211397Sswallace		 return -1;
3133584Ssos	}
3143584Ssos
3153584Ssos	nscns = fhdr->f_nscns;
3163584Ssos	if ((nscns * sizeof(struct scnhdr)) > PAGE_SIZE) {
3173584Ssos	  	/*
3183584Ssos	   	 * For now, return an error -- need to be able to
3193584Ssos	   	 * read in all of the section structures.
3203584Ssos	   	 */
3213584Ssos
32211397Sswallace		DPRINTF(("%s(%d): return -1\n", __FILE__, __LINE__));
32311397Sswallace		return -1;
3243584Ssos	}
3253584Ssos
32618024Sbde	ahdr = (const struct aouthdr*)
32718024Sbde	       ((const char*)(imgp->image_header) + sizeof(struct filehdr));
32812130Sdg	imgp->entry_addr = ahdr->entry;
3293584Ssos
33018024Sbde	scns = (const struct scnhdr*)
33118024Sbde	       ((const char*)(imgp->image_header) + sizeof(struct filehdr) +
33218024Sbde		sizeof(struct aouthdr));
3333584Ssos
334175294Sattilio	VOP_UNLOCK(imgp->vp, 0);
335101771Sjeff
336173361Skib	error = exec_new_vmspace(imgp, &ibcs2_svr3_sysvec);
337173361Skib	if (error)
338173361Skib		goto fail;
33924848Sdyson	vmspace = imgp->proc->p_vmspace;
3403584Ssos
3413584Ssos	for (i = 0; i < nscns; i++) {
3423584Ssos
343224613Skib	  DPRINTF(("i = %d, s_name = %s, s_vaddr = %08lx, "
344224613Skib		   "s_scnptr = %ld s_size = %lx\n", i, scns[i].s_name,
345224613Skib		   scns[i].s_vaddr, scns[i].s_scnptr, scns[i].s_size));
3463584Ssos	  if (scns[i].s_flags & STYP_NOLOAD) {
3473584Ssos	    	/*
3483584Ssos	     	 * A section that is not loaded, for whatever
3493584Ssos	     	 * reason.  It takes precedance over other flag
3503584Ssos	     	 * bits...
3513584Ssos	     	 */
3523584Ssos	    	continue;
3533584Ssos	  } else if (scns[i].s_flags & STYP_TEXT) {
3543584Ssos	    	text_address = scns[i].s_vaddr;
3553584Ssos	    	text_size = scns[i].s_size;
3563584Ssos	    	text_offset = scns[i].s_scnptr;
3573584Ssos	  } else if (scns[i].s_flags & STYP_DATA) {
3583584Ssos	    	/* .data section */
3593584Ssos	    	data_address = scns[i].s_vaddr;
3603584Ssos	    	data_size = scns[i].s_size;
3613584Ssos	    	data_offset = scns[i].s_scnptr;
3623584Ssos	  } else if (scns[i].s_flags & STYP_BSS) {
3633584Ssos	    	/* .bss section */
3643584Ssos	    	bss_size = scns[i].s_size;
3653584Ssos	  } else if (scns[i].s_flags & STYP_LIB) {
36616322Sgpalmer	    	char *buf = 0;
3673584Ssos	    	int foff = trunc_page(scns[i].s_scnptr);
3683584Ssos	    	int off = scns[i].s_scnptr - foff;
3693584Ssos	    	int len = round_page(scns[i].s_size + PAGE_SIZE);
3703584Ssos	    	int j;
3713584Ssos
372224613Skib		if ((error = vm_mmap(exec_map,
3737667Sjoerg				    (vm_offset_t *) &buf,
3747667Sjoerg				    len,
3757667Sjoerg				    VM_PROT_READ,
3767667Sjoerg				    VM_PROT_READ,
377224613Skib				    MAP_SHARED,
378144501Sjhb				    OBJT_VNODE,
379144501Sjhb				    imgp->vp,
38043314Sdillon				    foff)) != 0) {
381101771Sjeff	      		error = ENOEXEC;
382101771Sjeff			goto fail;
3833584Ssos	    	}
38411414Sswallace		if(scns[i].s_size) {
38511414Sswallace			char *libbuf;
38611414Sswallace			int emul_path_len = strlen(ibcs2_emul_path);
38711397Sswallace
38811414Sswallace			libbuf = malloc(MAXPATHLEN + emul_path_len,
389111119Simp					M_TEMP, M_WAITOK);
390122882Stjr			strcpy(libbuf, ibcs2_emul_path);
3913584Ssos
392103128Srobert		    	for (j = off; j < scns[i].s_size + off;) {
393103128Srobert				long stroff, nextoff;
39411414Sswallace	      			char *libname;
39511414Sswallace
396103128Srobert				nextoff = 4 * *(long *)(buf + j);
397103128Srobert				stroff = 4 * *(long *)(buf + j + sizeof(long));
39811414Sswallace
399103128Srobert		      		libname = buf + j + stroff;
400103128Srobert		      		j += nextoff;
401103128Srobert
40211414Sswallace				DPRINTF(("%s(%d):  shared library %s\n",
40311414Sswallace					 __FILE__, __LINE__, libname));
404122882Stjr				strlcpy(&libbuf[emul_path_len], libname, MAXPATHLEN);
405177091Sjeff			  	error = coff_load_file(
40690361Sjulian				    FIRST_THREAD_IN_PROC(imgp->proc), libbuf);
40711414Sswallace		      		if (error)
40890361Sjulian	      				error = coff_load_file(
40990361Sjulian					    FIRST_THREAD_IN_PROC(imgp->proc),
41090361Sjulian					    libname);
411224613Skib				if (error) {
412224613Skib					printf(
413224613Skib				"error %d loading coff shared library %s\n",
414224613Skib					    error, libname);
41511414Sswallace					break;
416224613Skib				}
41711414Sswallace		    	}
41811414Sswallace			free(libbuf, M_TEMP);
41911414Sswallace		}
420254025Sjeff		kmap_free_wakeup(exec_map, (vm_offset_t)buf, len);
4213584Ssos	    	if (error)
422101771Sjeff	      		goto fail;
4233584Ssos	  	}
4243584Ssos	}
4253584Ssos	/*
4263584Ssos	 * Map in .text now
4273584Ssos	 */
4283584Ssos
42911397Sswallace	DPRINTF(("%s(%d):  load_coff_section(vmspace, "
430224613Skib		"imgp->vp, %08lx, %08lx, 0x%lx, 0x%lx, 0x%x)\n",
43111397Sswallace		__FILE__, __LINE__, text_offset, text_address,
43211397Sswallace		text_size, text_size, VM_PROT_READ | VM_PROT_EXECUTE));
43343314Sdillon	if ((error = load_coff_section(vmspace, imgp->vp,
43438354Sbde				      text_offset,
43538354Sbde				      (caddr_t)(void *)(uintptr_t)text_address,
4363584Ssos				      text_size, text_size,
43743314Sdillon				      VM_PROT_READ | VM_PROT_EXECUTE)) != 0) {
43811397Sswallace		DPRINTF(("%s(%d): error = %d\n", __FILE__, __LINE__, error));
439101771Sjeff		goto fail;
4403584Ssos       	}
4413584Ssos	/*
4423584Ssos	 * Map in .data and .bss now
4433584Ssos	 */
4443584Ssos
4453584Ssos
44611397Sswallace	DPRINTF(("%s(%d): load_coff_section(vmspace, "
447224613Skib		"imgp->vp, 0x%08lx, 0x%08lx, 0x%lx, 0x%lx, 0x%x)\n",
44811397Sswallace		__FILE__, __LINE__, data_offset, data_address,
44911397Sswallace		data_size + bss_size, data_size, VM_PROT_ALL));
45043314Sdillon	if ((error = load_coff_section(vmspace, imgp->vp,
45138354Sbde				      data_offset,
45238354Sbde				      (caddr_t)(void *)(uintptr_t)data_address,
4533584Ssos				      data_size + bss_size, data_size,
45443314Sdillon				      VM_PROT_ALL)) != 0) {
4553584Ssos
45611397Sswallace		DPRINTF(("%s(%d): error = %d\n", __FILE__, __LINE__, error));
457101771Sjeff		goto fail;
4583584Ssos	}
4593584Ssos
46012130Sdg	imgp->interpreted = 0;
46112130Sdg	imgp->proc->p_sysent = &ibcs2_svr3_sysvec;
4623584Ssos
4633584Ssos	vmspace->vm_tsize = round_page(text_size) >> PAGE_SHIFT;
4643584Ssos	vmspace->vm_dsize = round_page(data_size + bss_size) >> PAGE_SHIFT;
46538354Sbde	vmspace->vm_taddr = (caddr_t)(void *)(uintptr_t)text_address;
46638354Sbde	vmspace->vm_daddr = (caddr_t)(void *)(uintptr_t)data_address;
4673584Ssos
468224613Skib	hole = trunc_page((vm_offset_t)vmspace->vm_daddr +
469224613Skib	    ctob(vmspace->vm_dsize));
4703584Ssos
471224613Skib	DPRINTF(("%s(%d): vm_map_find(&vmspace->vm_map, NULL, 0, &0x%jx, PAGE_SIZE, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0)\n",
472224613Skib	    __FILE__, __LINE__, (uintmax_t)hole));
47311397Sswallace        DPRINTF(("imgact: error = %d\n", error));
47411397Sswallace
475224613Skib	vm_map_find(&vmspace->vm_map, NULL, 0,
476255426Sjhb	    (vm_offset_t *)&hole, PAGE_SIZE, 0, VMFS_NO_SPACE,
477224613Skib	    VM_PROT_ALL, VM_PROT_ALL, 0);
478224613Skib	DPRINTF(("IBCS2: start vm_dsize = 0x%x, vm_daddr = 0x%p end = 0x%p\n",
47911397Sswallace		ctob(vmspace->vm_dsize), vmspace->vm_daddr,
48011397Sswallace		ctob(vmspace->vm_dsize) + vmspace->vm_daddr ));
481224613Skib	DPRINTF(("%s(%d):  returning %d!\n", __FILE__, __LINE__, error));
48211397Sswallace
483101771Sjefffail:
484175202Sattilio	vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
485101771Sjeff
486224613Skib	return (error);
4873584Ssos}
4883584Ssos
4893584Ssos/*
4903584Ssos * Tell kern_execve.c about it, with a little help from the linker.
4913584Ssos */
49246803Speterstatic struct execsw coff_execsw = { exec_coff_imgact, "coff" };
49340435SpeterEXEC_SET(coff, coff_execsw);
494