1994-10-14 08:53:16 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1994 Sean Eric Fagan
|
2012-01-15 13:23:18 +00:00
|
|
|
* Copyright (c) 1994 Søren Schmidt
|
1994-10-14 08:53:16 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
2002-06-02 20:05:59 +00:00
|
|
|
* derived from this software without specific prior written permission
|
1994-10-14 08:53:16 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-02 06:48:51 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-10-14 08:53:16 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2006-07-10 17:59:26 +00:00
|
|
|
#include <sys/exec.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/fcntl.h>
|
1994-10-14 08:53:16 +00:00
|
|
|
#include <sys/imgact.h>
|
|
|
|
#include <sys/kernel.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
1994-10-14 08:53:16 +00:00
|
|
|
#include <sys/malloc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/mman.h>
|
1994-10-14 08:53:16 +00:00
|
|
|
#include <sys/mount.h>
|
1996-05-01 02:43:13 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/vnode.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
|
1994-10-14 08:53:16 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
1994-10-14 08:53:16 +00:00
|
|
|
#include <vm/vm_kern.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
|
|
|
|
#include <i386/ibcs2/coff.h>
|
|
|
|
#include <i386/ibcs2/ibcs2_util.h>
|
|
|
|
|
2000-04-29 13:32:16 +00:00
|
|
|
MODULE_DEPEND(coff, ibcs2, 1, 1, 1);
|
|
|
|
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
extern struct sysentvec ibcs2_svr3_sysvec;
|
|
|
|
|
2002-03-20 05:48:58 +00:00
|
|
|
static int coff_load_file(struct thread *td, char *name);
|
|
|
|
static int exec_coff_imgact(struct image_params *imgp);
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
|
2002-03-20 05:48:58 +00:00
|
|
|
static 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);
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
|
1994-10-14 08:53:16 +00:00
|
|
|
static int
|
1997-08-25 22:15:31 +00:00
|
|
|
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)
|
1994-10-14 08:53:16 +00:00
|
|
|
{
|
|
|
|
size_t map_len;
|
|
|
|
vm_offset_t map_offset;
|
1995-04-08 15:52:30 +00:00
|
|
|
vm_offset_t map_addr;
|
1994-10-14 08:53:16 +00:00
|
|
|
int error;
|
|
|
|
unsigned char *data_buf = 0;
|
|
|
|
size_t copy_len;
|
|
|
|
|
|
|
|
map_offset = trunc_page(offset);
|
1998-10-13 08:24:45 +00:00
|
|
|
map_addr = trunc_page((vm_offset_t)vmaddr);
|
1994-10-14 08:53:16 +00:00
|
|
|
|
|
|
|
if (memsz > filsz) {
|
|
|
|
/*
|
|
|
|
* We have the stupid situation that
|
|
|
|
* the section is longer than it is on file,
|
|
|
|
* which means it has zero-filled areas, and
|
|
|
|
* we have to work for it. Stupid iBCS!
|
|
|
|
*/
|
|
|
|
map_len = trunc_page(offset + filsz) - trunc_page(map_offset);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The only stuff we care about is on disk, and we
|
|
|
|
* don't care if we map in more than is really there.
|
|
|
|
*/
|
|
|
|
map_len = round_page(offset + filsz) - trunc_page(map_offset);
|
|
|
|
}
|
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
DPRINTF(("%s(%d): vm_mmap(&vmspace->vm_map, &0x%08jx, 0x%x, 0x%x, "
|
2005-04-01 20:00:11 +00:00
|
|
|
"VM_PROT_ALL, MAP_PRIVATE | MAP_FIXED, OBJT_VNODE, vp, 0x%x)\n",
|
2011-08-02 18:12:19 +00:00
|
|
|
__FILE__, __LINE__, (uintmax_t)map_addr, map_len, prot,
|
|
|
|
map_offset));
|
1994-10-14 08:53:16 +00:00
|
|
|
|
1999-01-28 01:59:53 +00:00
|
|
|
if ((error = vm_mmap(&vmspace->vm_map,
|
1994-10-14 08:53:16 +00:00
|
|
|
&map_addr,
|
|
|
|
map_len,
|
|
|
|
prot,
|
|
|
|
VM_PROT_ALL,
|
1996-03-12 06:20:19 +00:00
|
|
|
MAP_PRIVATE | MAP_FIXED,
|
2005-04-01 20:00:11 +00:00
|
|
|
OBJT_VNODE,
|
|
|
|
vp,
|
1999-01-28 01:59:53 +00:00
|
|
|
map_offset)) != 0)
|
1994-10-14 08:53:16 +00:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if (memsz == filsz) {
|
|
|
|
/* We're done! */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we have screwball stuff, to accomodate stupid COFF.
|
|
|
|
* We have to map the remaining bit of the file into the kernel's
|
|
|
|
* memory map, allocate some anonymous memory, copy that last
|
|
|
|
* bit into it, and then we're done. *sigh*
|
|
|
|
* For clean-up reasons, we actally map in the file last.
|
|
|
|
*/
|
|
|
|
|
|
|
|
copy_len = (offset + filsz) - trunc_page(offset + filsz);
|
1998-10-13 08:24:45 +00:00
|
|
|
map_addr = trunc_page((vm_offset_t)vmaddr + filsz);
|
|
|
|
map_len = round_page((vm_offset_t)vmaddr + memsz) - map_addr;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
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));
|
1994-10-14 08:53:16 +00:00
|
|
|
|
1995-02-20 23:52:39 +00:00
|
|
|
if (map_len != 0) {
|
1995-04-08 15:52:30 +00:00
|
|
|
error = vm_map_find(&vmspace->vm_map, NULL, 0, &map_addr,
|
2011-08-02 18:12:19 +00:00
|
|
|
map_len, VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0);
|
1995-02-20 23:52:39 +00:00
|
|
|
if (error)
|
2011-08-02 18:12:19 +00:00
|
|
|
return (vm_mmap_to_errno(error));
|
1995-02-20 23:52:39 +00:00
|
|
|
}
|
1994-10-14 08:53:16 +00:00
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
if ((error = vm_mmap(exec_map,
|
1995-04-08 15:52:30 +00:00
|
|
|
(vm_offset_t *) &data_buf,
|
|
|
|
PAGE_SIZE,
|
|
|
|
VM_PROT_READ,
|
|
|
|
VM_PROT_READ,
|
1996-03-12 06:20:19 +00:00
|
|
|
0,
|
2005-04-01 20:00:11 +00:00
|
|
|
OBJT_VNODE,
|
|
|
|
vp,
|
1999-01-28 01:59:53 +00:00
|
|
|
trunc_page(offset + filsz))) != 0)
|
1994-10-14 08:53:16 +00:00
|
|
|
return error;
|
|
|
|
|
1996-03-12 06:13:08 +00:00
|
|
|
error = copyout(data_buf, (caddr_t) map_addr, copy_len);
|
1994-10-14 08:53:16 +00:00
|
|
|
|
2012-02-17 23:47:16 +00:00
|
|
|
kmem_free_wakeup(exec_map, (vm_offset_t)data_buf, PAGE_SIZE);
|
1994-10-14 08:53:16 +00:00
|
|
|
|
1996-03-12 06:13:08 +00:00
|
|
|
return error;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
coff_load_file(struct thread *td, char *name)
|
1994-10-14 08:53:16 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct proc *p = td->td_proc;
|
1994-10-14 08:53:16 +00:00
|
|
|
struct vmspace *vmspace = p->p_vmspace;
|
|
|
|
int error;
|
|
|
|
struct nameidata nd;
|
1995-11-06 12:52:37 +00:00
|
|
|
struct vnode *vp;
|
1994-10-14 08:53:16 +00:00
|
|
|
struct vattr attr;
|
|
|
|
struct filehdr *fhdr;
|
|
|
|
struct aouthdr *ahdr;
|
|
|
|
struct scnhdr *scns;
|
|
|
|
char *ptr = 0;
|
|
|
|
int nscns;
|
|
|
|
unsigned long text_offset = 0, text_address = 0, text_size = 0;
|
|
|
|
unsigned long data_offset = 0, data_address = 0, data_size = 0;
|
|
|
|
unsigned long bss_size = 0;
|
|
|
|
int i;
|
|
|
|
|
2005-04-27 09:05:19 +00:00
|
|
|
NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | FOLLOW | SAVENAME,
|
|
|
|
UIO_SYSSPACE, name, td);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-10-14 08:53:16 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error)
|
|
|
|
return error;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-11-06 12:52:37 +00:00
|
|
|
vp = nd.ni_vp;
|
|
|
|
if (vp == NULL)
|
1994-10-14 08:53:16 +00:00
|
|
|
return ENOEXEC;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-11-06 12:52:37 +00:00
|
|
|
if (vp->v_writecount) {
|
1994-10-14 08:53:16 +00:00
|
|
|
error = ETXTBSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-08-28 15:23:18 +00:00
|
|
|
if ((error = VOP_GETATTR(vp, &attr, td->td_ucred)) != 0)
|
1994-10-14 08:53:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
1995-11-06 12:52:37 +00:00
|
|
|
if ((vp->v_mount->mnt_flag & MNT_NOEXEC)
|
1994-10-14 08:53:16 +00:00
|
|
|
|| ((attr.va_mode & 0111) == 0)
|
2001-01-27 00:01:31 +00:00
|
|
|
|| (attr.va_type != VREG))
|
1994-10-14 08:53:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (attr.va_size == 0) {
|
|
|
|
error = ENOEXEC;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2002-02-27 18:32:23 +00:00
|
|
|
if ((error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td)) != 0)
|
1994-10-14 08:53:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
2007-05-31 11:51:53 +00:00
|
|
|
if ((error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL)) != 0)
|
1994-10-14 08:53:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
1995-09-13 02:12:51 +00:00
|
|
|
/*
|
|
|
|
* Lose the lock on the vnode. It's no longer needed, and must not
|
|
|
|
* exist for the pagefault paging to work below.
|
|
|
|
*/
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1995-09-13 02:12:51 +00:00
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
if ((error = vm_mmap(exec_map,
|
1995-04-08 15:52:30 +00:00
|
|
|
(vm_offset_t *) &ptr,
|
|
|
|
PAGE_SIZE,
|
|
|
|
VM_PROT_READ,
|
|
|
|
VM_PROT_READ,
|
1996-03-12 06:20:19 +00:00
|
|
|
0,
|
2005-04-01 20:00:11 +00:00
|
|
|
OBJT_VNODE,
|
|
|
|
vp,
|
1999-01-28 01:59:53 +00:00
|
|
|
0)) != 0)
|
1999-11-14 17:33:40 +00:00
|
|
|
goto unlocked_fail;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
|
|
|
fhdr = (struct filehdr *)ptr;
|
|
|
|
|
|
|
|
if (fhdr->f_magic != I386_COFF) {
|
|
|
|
error = ENOEXEC;
|
|
|
|
goto dealloc_and_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscns = fhdr->f_nscns;
|
|
|
|
|
|
|
|
if ((nscns * sizeof(struct scnhdr)) > PAGE_SIZE) {
|
|
|
|
/*
|
|
|
|
* XXX -- just fail. I'm so lazy.
|
|
|
|
*/
|
|
|
|
error = ENOEXEC;
|
|
|
|
goto dealloc_and_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ahdr = (struct aouthdr*)(ptr + sizeof(struct filehdr));
|
|
|
|
|
|
|
|
scns = (struct scnhdr*)(ptr + sizeof(struct filehdr)
|
|
|
|
+ sizeof(struct aouthdr));
|
|
|
|
|
|
|
|
for (i = 0; i < nscns; i++) {
|
|
|
|
if (scns[i].s_flags & STYP_NOLOAD)
|
|
|
|
continue;
|
|
|
|
else if (scns[i].s_flags & STYP_TEXT) {
|
|
|
|
text_address = scns[i].s_vaddr;
|
|
|
|
text_size = scns[i].s_size;
|
|
|
|
text_offset = scns[i].s_scnptr;
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1994-10-14 08:53:16 +00:00
|
|
|
else if (scns[i].s_flags & STYP_DATA) {
|
|
|
|
data_address = scns[i].s_vaddr;
|
|
|
|
data_size = scns[i].s_size;
|
|
|
|
data_offset = scns[i].s_scnptr;
|
|
|
|
} else if (scns[i].s_flags & STYP_BSS) {
|
|
|
|
bss_size = scns[i].s_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-28 01:59:53 +00:00
|
|
|
if ((error = load_coff_section(vmspace, vp, text_offset,
|
1998-08-16 01:21:52 +00:00
|
|
|
(caddr_t)(void *)(uintptr_t)text_address,
|
1994-10-14 08:53:16 +00:00
|
|
|
text_size, text_size,
|
1999-01-28 01:59:53 +00:00
|
|
|
VM_PROT_READ | VM_PROT_EXECUTE)) != 0) {
|
1994-10-14 08:53:16 +00:00
|
|
|
goto dealloc_and_fail;
|
|
|
|
}
|
1999-01-28 01:59:53 +00:00
|
|
|
if ((error = load_coff_section(vmspace, vp, data_offset,
|
1998-08-16 01:21:52 +00:00
|
|
|
(caddr_t)(void *)(uintptr_t)data_address,
|
1994-10-14 08:53:16 +00:00
|
|
|
data_size + bss_size, data_size,
|
1999-01-28 01:59:53 +00:00
|
|
|
VM_PROT_ALL)) != 0) {
|
1994-10-14 08:53:16 +00:00
|
|
|
goto dealloc_and_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
1999-11-14 17:33:40 +00:00
|
|
|
dealloc_and_fail:
|
2012-02-17 23:47:16 +00:00
|
|
|
kmem_free_wakeup(exec_map, (vm_offset_t)ptr, PAGE_SIZE);
|
1994-10-14 08:53:16 +00:00
|
|
|
fail:
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1999-11-14 17:33:40 +00:00
|
|
|
unlocked_fail:
|
1999-12-15 23:02:35 +00:00
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
1999-11-14 17:33:40 +00:00
|
|
|
vrele(nd.ni_vp);
|
1994-10-14 08:53:16 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static int
|
1995-11-06 12:52:37 +00:00
|
|
|
exec_coff_imgact(imgp)
|
|
|
|
struct image_params *imgp;
|
1994-10-14 08:53:16 +00:00
|
|
|
{
|
1996-09-03 22:19:16 +00:00
|
|
|
const struct filehdr *fhdr = (const struct filehdr*)imgp->image_header;
|
|
|
|
const struct aouthdr *ahdr;
|
|
|
|
const struct scnhdr *scns;
|
1994-10-14 08:53:16 +00:00
|
|
|
int i;
|
1997-04-13 01:48:35 +00:00
|
|
|
struct vmspace *vmspace;
|
1994-10-14 08:53:16 +00:00
|
|
|
int nscns;
|
1996-06-12 05:11:41 +00:00
|
|
|
int error;
|
1994-10-14 08:53:16 +00:00
|
|
|
unsigned long text_offset = 0, text_address = 0, text_size = 0;
|
|
|
|
unsigned long data_offset = 0, data_address = 0, data_size = 0;
|
|
|
|
unsigned long bss_size = 0;
|
2011-08-02 18:12:19 +00:00
|
|
|
vm_offset_t hole;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
|
|
|
if (fhdr->f_magic != I386_COFF ||
|
|
|
|
!(fhdr->f_flags & F_EXEC)) {
|
|
|
|
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("%s(%d): return -1\n", __FILE__, __LINE__));
|
|
|
|
return -1;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nscns = fhdr->f_nscns;
|
|
|
|
if ((nscns * sizeof(struct scnhdr)) > PAGE_SIZE) {
|
|
|
|
/*
|
|
|
|
* For now, return an error -- need to be able to
|
|
|
|
* read in all of the section structures.
|
|
|
|
*/
|
|
|
|
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("%s(%d): return -1\n", __FILE__, __LINE__));
|
|
|
|
return -1;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
|
|
|
|
1996-09-03 22:19:16 +00:00
|
|
|
ahdr = (const struct aouthdr*)
|
|
|
|
((const char*)(imgp->image_header) + sizeof(struct filehdr));
|
1995-11-06 12:52:37 +00:00
|
|
|
imgp->entry_addr = ahdr->entry;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
1996-09-03 22:19:16 +00:00
|
|
|
scns = (const struct scnhdr*)
|
|
|
|
((const char*)(imgp->image_header) + sizeof(struct filehdr) +
|
|
|
|
sizeof(struct aouthdr));
|
1994-10-14 08:53:16 +00:00
|
|
|
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(imgp->vp, 0);
|
2002-08-13 06:55:28 +00:00
|
|
|
|
2007-11-05 11:36:16 +00:00
|
|
|
error = exec_new_vmspace(imgp, &ibcs2_svr3_sysvec);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
1997-04-13 01:48:35 +00:00
|
|
|
vmspace = imgp->proc->p_vmspace;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nscns; i++) {
|
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
DPRINTF(("i = %d, s_name = %s, s_vaddr = %08lx, "
|
|
|
|
"s_scnptr = %ld s_size = %lx\n", i, scns[i].s_name,
|
|
|
|
scns[i].s_vaddr, scns[i].s_scnptr, scns[i].s_size));
|
1994-10-14 08:53:16 +00:00
|
|
|
if (scns[i].s_flags & STYP_NOLOAD) {
|
|
|
|
/*
|
|
|
|
* A section that is not loaded, for whatever
|
|
|
|
* reason. It takes precedance over other flag
|
|
|
|
* bits...
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
} else if (scns[i].s_flags & STYP_TEXT) {
|
|
|
|
text_address = scns[i].s_vaddr;
|
|
|
|
text_size = scns[i].s_size;
|
|
|
|
text_offset = scns[i].s_scnptr;
|
|
|
|
} else if (scns[i].s_flags & STYP_DATA) {
|
|
|
|
/* .data section */
|
|
|
|
data_address = scns[i].s_vaddr;
|
|
|
|
data_size = scns[i].s_size;
|
|
|
|
data_offset = scns[i].s_scnptr;
|
|
|
|
} else if (scns[i].s_flags & STYP_BSS) {
|
|
|
|
/* .bss section */
|
|
|
|
bss_size = scns[i].s_size;
|
|
|
|
} else if (scns[i].s_flags & STYP_LIB) {
|
1996-06-12 05:11:41 +00:00
|
|
|
char *buf = 0;
|
1994-10-14 08:53:16 +00:00
|
|
|
int foff = trunc_page(scns[i].s_scnptr);
|
|
|
|
int off = scns[i].s_scnptr - foff;
|
|
|
|
int len = round_page(scns[i].s_size + PAGE_SIZE);
|
|
|
|
int j;
|
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
if ((error = vm_mmap(exec_map,
|
1995-04-08 15:52:30 +00:00
|
|
|
(vm_offset_t *) &buf,
|
|
|
|
len,
|
|
|
|
VM_PROT_READ,
|
|
|
|
VM_PROT_READ,
|
2011-08-02 18:12:19 +00:00
|
|
|
MAP_SHARED,
|
2005-04-01 20:00:11 +00:00
|
|
|
OBJT_VNODE,
|
|
|
|
imgp->vp,
|
1999-01-28 01:59:53 +00:00
|
|
|
foff)) != 0) {
|
2002-08-13 06:55:28 +00:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto fail;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
1995-10-10 17:33:19 +00:00
|
|
|
if(scns[i].s_size) {
|
|
|
|
char *libbuf;
|
|
|
|
int emul_path_len = strlen(ibcs2_emul_path);
|
|
|
|
|
|
|
|
libbuf = malloc(MAXPATHLEN + emul_path_len,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_TEMP, M_WAITOK);
|
2003-11-18 14:21:34 +00:00
|
|
|
strcpy(libbuf, ibcs2_emul_path);
|
1995-10-10 17:33:19 +00:00
|
|
|
|
2002-09-09 15:51:10 +00:00
|
|
|
for (j = off; j < scns[i].s_size + off;) {
|
|
|
|
long stroff, nextoff;
|
1995-10-10 17:33:19 +00:00
|
|
|
char *libname;
|
|
|
|
|
2002-09-09 15:51:10 +00:00
|
|
|
nextoff = 4 * *(long *)(buf + j);
|
|
|
|
stroff = 4 * *(long *)(buf + j + sizeof(long));
|
|
|
|
|
|
|
|
libname = buf + j + stroff;
|
|
|
|
j += nextoff;
|
1995-10-10 17:33:19 +00:00
|
|
|
|
|
|
|
DPRINTF(("%s(%d): shared library %s\n",
|
|
|
|
__FILE__, __LINE__, libname));
|
2003-11-18 14:21:34 +00:00
|
|
|
strlcpy(&libbuf[emul_path_len], libname, MAXPATHLEN);
|
2008-03-12 10:12:01 +00:00
|
|
|
error = coff_load_file(
|
2002-02-07 20:58:47 +00:00
|
|
|
FIRST_THREAD_IN_PROC(imgp->proc), libbuf);
|
1995-10-10 17:33:19 +00:00
|
|
|
if (error)
|
2002-02-07 20:58:47 +00:00
|
|
|
error = coff_load_file(
|
|
|
|
FIRST_THREAD_IN_PROC(imgp->proc),
|
|
|
|
libname);
|
2011-08-02 18:12:19 +00:00
|
|
|
if (error) {
|
|
|
|
printf(
|
|
|
|
"error %d loading coff shared library %s\n",
|
|
|
|
error, libname);
|
1995-10-10 17:33:19 +00:00
|
|
|
break;
|
2011-08-02 18:12:19 +00:00
|
|
|
}
|
1995-10-10 17:33:19 +00:00
|
|
|
}
|
|
|
|
free(libbuf, M_TEMP);
|
|
|
|
}
|
2012-02-17 23:47:16 +00:00
|
|
|
kmem_free_wakeup(exec_map, (vm_offset_t)buf, len);
|
1994-10-14 08:53:16 +00:00
|
|
|
if (error)
|
2002-08-13 06:55:28 +00:00
|
|
|
goto fail;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Map in .text now
|
|
|
|
*/
|
|
|
|
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("%s(%d): load_coff_section(vmspace, "
|
2011-08-02 18:12:19 +00:00
|
|
|
"imgp->vp, %08lx, %08lx, 0x%lx, 0x%lx, 0x%x)\n",
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
__FILE__, __LINE__, text_offset, text_address,
|
|
|
|
text_size, text_size, VM_PROT_READ | VM_PROT_EXECUTE));
|
1999-01-28 01:59:53 +00:00
|
|
|
if ((error = load_coff_section(vmspace, imgp->vp,
|
1998-08-16 01:21:52 +00:00
|
|
|
text_offset,
|
|
|
|
(caddr_t)(void *)(uintptr_t)text_address,
|
1994-10-14 08:53:16 +00:00
|
|
|
text_size, text_size,
|
1999-01-28 01:59:53 +00:00
|
|
|
VM_PROT_READ | VM_PROT_EXECUTE)) != 0) {
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("%s(%d): error = %d\n", __FILE__, __LINE__, error));
|
2002-08-13 06:55:28 +00:00
|
|
|
goto fail;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Map in .data and .bss now
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("%s(%d): load_coff_section(vmspace, "
|
2011-08-02 18:12:19 +00:00
|
|
|
"imgp->vp, 0x%08lx, 0x%08lx, 0x%lx, 0x%lx, 0x%x)\n",
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
__FILE__, __LINE__, data_offset, data_address,
|
|
|
|
data_size + bss_size, data_size, VM_PROT_ALL));
|
1999-01-28 01:59:53 +00:00
|
|
|
if ((error = load_coff_section(vmspace, imgp->vp,
|
1998-08-16 01:21:52 +00:00
|
|
|
data_offset,
|
|
|
|
(caddr_t)(void *)(uintptr_t)data_address,
|
1994-10-14 08:53:16 +00:00
|
|
|
data_size + bss_size, data_size,
|
1999-01-28 01:59:53 +00:00
|
|
|
VM_PROT_ALL)) != 0) {
|
1994-10-14 08:53:16 +00:00
|
|
|
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("%s(%d): error = %d\n", __FILE__, __LINE__, error));
|
2002-08-13 06:55:28 +00:00
|
|
|
goto fail;
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
|
|
|
|
1995-11-06 12:52:37 +00:00
|
|
|
imgp->interpreted = 0;
|
|
|
|
imgp->proc->p_sysent = &ibcs2_svr3_sysvec;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
|
|
|
vmspace->vm_tsize = round_page(text_size) >> PAGE_SHIFT;
|
|
|
|
vmspace->vm_dsize = round_page(data_size + bss_size) >> PAGE_SHIFT;
|
1998-08-16 01:21:52 +00:00
|
|
|
vmspace->vm_taddr = (caddr_t)(void *)(uintptr_t)text_address;
|
|
|
|
vmspace->vm_daddr = (caddr_t)(void *)(uintptr_t)data_address;
|
1994-10-14 08:53:16 +00:00
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
hole = trunc_page((vm_offset_t)vmspace->vm_daddr +
|
|
|
|
ctob(vmspace->vm_dsize));
|
1994-10-14 08:53:16 +00:00
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
DPRINTF(("%s(%d): vm_map_find(&vmspace->vm_map, NULL, 0, &0x%jx, PAGE_SIZE, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0)\n",
|
|
|
|
__FILE__, __LINE__, (uintmax_t)hole));
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
DPRINTF(("imgact: error = %d\n", error));
|
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
vm_map_find(&vmspace->vm_map, NULL, 0,
|
|
|
|
(vm_offset_t *)&hole, PAGE_SIZE, VMFS_NO_SPACE,
|
|
|
|
VM_PROT_ALL, VM_PROT_ALL, 0);
|
|
|
|
DPRINTF(("IBCS2: start vm_dsize = 0x%x, vm_daddr = 0x%p end = 0x%p\n",
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
ctob(vmspace->vm_dsize), vmspace->vm_daddr,
|
|
|
|
ctob(vmspace->vm_dsize) + vmspace->vm_daddr ));
|
2011-08-02 18:12:19 +00:00
|
|
|
DPRINTF(("%s(%d): returning %d!\n", __FILE__, __LINE__, error));
|
Remove old files no longer needed.
Add new files created for emulator.
Modify NetBSD import to work with FreeBSD and add new features and
code. The complete emulator is essentially a combination of work/code
implemented by Sean Eric Fagan, Soren Schmidt, Scott Bartram, and myself,
Steven Wallace.
Features of this new emulator system include:
o "clean" code, including strict prototyping.
o Auto-generation of ibcs2 system calls, xenix system calls, isc system
calls. Generation includes system tables, structure definitions,
and prototyping of function calls.
o ibcs2 emulator does not rely on any COMPAT_43 system calls.
o embedded socksys support
o ibcs2 msgsys, semsys, shmsys calls supported if supported in kernel
o alternate /emul/ibcs2 namespace searched first for files in ibcs2
system. Usefull to keep sysv libraries, binaries in /emul/ibcs2.
o many other finer details and functions fixed or implemented.
1995-10-10 07:59:30 +00:00
|
|
|
|
2002-08-13 06:55:28 +00:00
|
|
|
fail:
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
|
2002-08-13 06:55:28 +00:00
|
|
|
|
2011-08-02 18:12:19 +00:00
|
|
|
return (error);
|
1994-10-14 08:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell kern_execve.c about it, with a little help from the linker.
|
|
|
|
*/
|
1999-05-09 16:04:14 +00:00
|
|
|
static struct execsw coff_execsw = { exec_coff_imgact, "coff" };
|
1998-10-16 03:55:01 +00:00
|
|
|
EXEC_SET(coff, coff_execsw);
|