2002-07-20 02:56:12 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Doug Rabson
|
2003-05-14 04:10:49 +00:00
|
|
|
* Copyright (c) 2003 Peter Wemm
|
2002-07-20 02:56:12 +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.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2003-07-25 21:19:19 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-05-14 04:10:49 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
#define __ELF_WORD_SIZE 32
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/imgact.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/pioctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/procfs.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/sx.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/imgact_elf.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
2003-08-23 00:04:53 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_util.h>
|
|
|
|
#include <compat/freebsd32/freebsd32_proto.h>
|
2003-12-10 23:16:32 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_syscall.h>
|
2003-08-23 00:04:53 +00:00
|
|
|
#include <compat/ia32/ia32_signal.h>
|
2003-12-11 01:05:09 +00:00
|
|
|
#ifdef __amd64__
|
2003-05-14 04:10:49 +00:00
|
|
|
#include <machine/psl.h>
|
|
|
|
#include <machine/segments.h>
|
|
|
|
#include <machine/specialreg.h>
|
2003-12-11 01:05:09 +00:00
|
|
|
#else
|
|
|
|
#include <i386/include/psl.h>
|
|
|
|
#include <i386/include/segments.h>
|
|
|
|
#include <i386/include/specialreg.h>
|
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
#include <machine/frame.h>
|
|
|
|
#include <machine/md_var.h>
|
2003-05-14 04:10:49 +00:00
|
|
|
#include <machine/pcb.h>
|
|
|
|
#include <machine/cpufunc.h>
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2003-10-30 02:43:19 +00:00
|
|
|
CTASSERT(sizeof(struct ia32_mcontext) == 640);
|
|
|
|
CTASSERT(sizeof(struct ia32_ucontext) == 704);
|
|
|
|
CTASSERT(sizeof(struct ia32_sigframe) == 800);
|
|
|
|
CTASSERT(sizeof(struct ia32_siginfo) == 64);
|
|
|
|
#ifdef COMPAT_FREEBSD4
|
|
|
|
CTASSERT(sizeof(struct ia32_mcontext4) == 260);
|
|
|
|
CTASSERT(sizeof(struct ia32_ucontext4) == 324);
|
|
|
|
CTASSERT(sizeof(struct ia32_sigframe4) == 408);
|
|
|
|
#endif
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
static register_t *ia32_copyout_strings(struct image_params *imgp);
|
2005-11-02 21:18:07 +00:00
|
|
|
static void ia32_fixlimits(struct proc *p);
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2003-08-22 23:19:02 +00:00
|
|
|
extern struct sysent freebsd32_sysent[];
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2003-09-25 01:10:26 +00:00
|
|
|
SYSCTL_NODE(_compat, OID_AUTO, ia32, CTLFLAG_RW, 0, "ia32 mode");
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
struct sysentvec ia32_freebsd_sysvec = {
|
2003-12-10 23:16:32 +00:00
|
|
|
FREEBSD32_SYS_MAXSYSCALL,
|
2003-08-22 23:19:02 +00:00
|
|
|
freebsd32_sysent,
|
2002-07-20 02:56:12 +00:00
|
|
|
0,
|
|
|
|
0,
|
2002-09-01 21:41:24 +00:00
|
|
|
NULL,
|
2002-07-20 02:56:12 +00:00
|
|
|
0,
|
2002-09-01 21:41:24 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-07-20 02:56:12 +00:00
|
|
|
elf32_freebsd_fixup,
|
2003-05-14 04:10:49 +00:00
|
|
|
ia32_sendsig,
|
2002-07-20 02:56:12 +00:00
|
|
|
ia32_sigcode,
|
2003-05-14 04:10:49 +00:00
|
|
|
&sz_ia32_sigcode,
|
2002-09-01 21:41:24 +00:00
|
|
|
NULL,
|
2003-05-14 04:10:49 +00:00
|
|
|
"FreeBSD ELF32",
|
2002-07-20 02:56:12 +00:00
|
|
|
elf32_coredump,
|
|
|
|
NULL,
|
|
|
|
MINSIGSTKSZ,
|
2003-12-11 01:05:09 +00:00
|
|
|
IA32_PAGE_SIZE,
|
2002-09-01 21:41:24 +00:00
|
|
|
0,
|
2003-08-23 00:04:53 +00:00
|
|
|
FREEBSD32_USRSTACK,
|
|
|
|
FREEBSD32_USRSTACK,
|
|
|
|
FREEBSD32_PS_STRINGS,
|
2002-09-01 21:41:24 +00:00
|
|
|
VM_PROT_ALL,
|
2002-07-20 02:56:12 +00:00
|
|
|
ia32_copyout_strings,
|
2003-09-25 01:10:26 +00:00
|
|
|
ia32_setregs,
|
|
|
|
ia32_fixlimits
|
2002-07-20 02:56:12 +00:00
|
|
|
};
|
|
|
|
|
2003-05-14 04:10:49 +00:00
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
static Elf32_Brandinfo ia32_brand_info = {
|
|
|
|
ELFOSABI_FREEBSD,
|
|
|
|
EM_386,
|
|
|
|
"FreeBSD",
|
2003-12-23 02:42:39 +00:00
|
|
|
NULL,
|
|
|
|
"/libexec/ld-elf.so.1",
|
|
|
|
&ia32_freebsd_sysvec,
|
2004-03-21 01:22:24 +00:00
|
|
|
"/libexec/ld-elf32.so.1",
|
2002-07-20 02:56:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY,
|
|
|
|
(sysinit_cfunc_t) elf32_insert_brand_entry,
|
|
|
|
&ia32_brand_info);
|
|
|
|
|
2003-12-23 02:42:39 +00:00
|
|
|
static Elf32_Brandinfo ia32_brand_oinfo = {
|
|
|
|
ELFOSABI_FREEBSD,
|
|
|
|
EM_386,
|
|
|
|
"FreeBSD",
|
|
|
|
NULL,
|
|
|
|
"/usr/libexec/ld-elf.so.1",
|
|
|
|
&ia32_freebsd_sysvec,
|
2004-07-16 20:53:00 +00:00
|
|
|
"/libexec/ld-elf32.so.1",
|
2003-12-23 02:42:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SYSINIT(oia32, SI_SUB_EXEC, SI_ORDER_ANY,
|
|
|
|
(sysinit_cfunc_t) elf32_insert_brand_entry,
|
|
|
|
&ia32_brand_oinfo);
|
|
|
|
|
2004-08-11 02:35:06 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
elf32_dump_thread(struct thread *td __unused, void *dst __unused,
|
|
|
|
size_t *off __unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-22 23:19:02 +00:00
|
|
|
/* XXX may be freebsd32 MI */
|
2002-07-20 02:56:12 +00:00
|
|
|
static register_t *
|
|
|
|
ia32_copyout_strings(struct image_params *imgp)
|
|
|
|
{
|
|
|
|
int argc, envc;
|
|
|
|
u_int32_t *vectp;
|
|
|
|
char *stringp, *destp;
|
|
|
|
u_int32_t *stack_base;
|
2003-08-23 00:04:53 +00:00
|
|
|
struct freebsd32_ps_strings *arginfo;
|
2002-07-20 02:56:12 +00:00
|
|
|
int szsigcode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate string base and vector table pointers.
|
|
|
|
* Also deal with signal trampoline code for this exec type.
|
|
|
|
*/
|
2003-08-23 00:04:53 +00:00
|
|
|
arginfo = (struct freebsd32_ps_strings *)FREEBSD32_PS_STRINGS;
|
2002-07-20 02:56:12 +00:00
|
|
|
szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
|
|
|
|
destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
|
2005-01-29 23:12:00 +00:00
|
|
|
roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* install sigcode
|
|
|
|
*/
|
|
|
|
if (szsigcode)
|
|
|
|
copyout(imgp->proc->p_sysent->sv_sigcode,
|
|
|
|
((caddr_t)arginfo - szsigcode), szsigcode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a valid auxargs ptr, prepare some room
|
|
|
|
* on the stack.
|
|
|
|
*/
|
|
|
|
if (imgp->auxargs) {
|
|
|
|
/*
|
|
|
|
* 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
|
|
|
|
* lower compatibility.
|
|
|
|
*/
|
|
|
|
imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
|
|
|
|
: (AT_COUNT * 2);
|
|
|
|
/*
|
|
|
|
* The '+ 2' is for the null pointers at the end of each of
|
|
|
|
* the arg and env vector sets,and imgp->auxarg_size is room
|
|
|
|
* for argument of Runtime loader.
|
|
|
|
*/
|
2005-01-29 23:12:00 +00:00
|
|
|
vectp = (u_int32_t *) (destp - (imgp->args->argc + imgp->args->envc + 2 +
|
2002-07-20 02:56:12 +00:00
|
|
|
imgp->auxarg_size) * sizeof(u_int32_t));
|
|
|
|
|
|
|
|
} else
|
|
|
|
/*
|
|
|
|
* The '+ 2' is for the null pointers at the end of each of
|
|
|
|
* the arg and env vector sets
|
|
|
|
*/
|
|
|
|
vectp = (u_int32_t *)
|
2005-01-29 23:12:00 +00:00
|
|
|
(destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t));
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* vectp also becomes our initial stack base
|
|
|
|
*/
|
|
|
|
stack_base = vectp;
|
|
|
|
|
2005-01-29 23:12:00 +00:00
|
|
|
stringp = imgp->args->begin_argv;
|
|
|
|
argc = imgp->args->argc;
|
|
|
|
envc = imgp->args->envc;
|
2002-07-20 02:56:12 +00:00
|
|
|
/*
|
|
|
|
* Copy out strings - arguments and environment.
|
|
|
|
*/
|
2005-01-29 23:12:00 +00:00
|
|
|
copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in "ps_strings" struct for ps, w, etc.
|
|
|
|
*/
|
|
|
|
suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
|
|
|
|
suword32(&arginfo->ps_nargvstr, argc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in argument portion of vector table.
|
|
|
|
*/
|
|
|
|
for (; argc > 0; --argc) {
|
|
|
|
suword32(vectp++, (u_int32_t)(intptr_t)destp);
|
|
|
|
while (*stringp++ != 0)
|
|
|
|
destp++;
|
|
|
|
destp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* a null vector table pointer separates the argp's from the envp's */
|
|
|
|
suword32(vectp++, 0);
|
|
|
|
|
|
|
|
suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
|
|
|
|
suword32(&arginfo->ps_nenvstr, envc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in environment portion of vector table.
|
|
|
|
*/
|
|
|
|
for (; envc > 0; --envc) {
|
|
|
|
suword32(vectp++, (u_int32_t)(intptr_t)destp);
|
|
|
|
while (*stringp++ != 0)
|
|
|
|
destp++;
|
|
|
|
destp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of vector table is a null pointer */
|
|
|
|
suword32(vectp, 0);
|
|
|
|
|
|
|
|
return ((register_t *)stack_base);
|
|
|
|
}
|
|
|
|
|
2003-09-25 01:10:26 +00:00
|
|
|
static u_long ia32_maxdsiz = IA32_MAXDSIZ;
|
|
|
|
SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxdsiz, CTLFLAG_RW, &ia32_maxdsiz, 0, "");
|
|
|
|
static u_long ia32_maxssiz = IA32_MAXSSIZ;
|
|
|
|
SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxssiz, CTLFLAG_RW, &ia32_maxssiz, 0, "");
|
|
|
|
static u_long ia32_maxvmem = IA32_MAXVMEM;
|
|
|
|
SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxvmem, CTLFLAG_RW, &ia32_maxvmem, 0, "");
|
|
|
|
|
|
|
|
static void
|
2005-11-02 21:18:07 +00:00
|
|
|
ia32_fixlimits(struct proc *p)
|
2003-09-25 01:10:26 +00:00
|
|
|
{
|
2004-02-04 21:52:57 +00:00
|
|
|
struct plimit *oldlim, *newlim;
|
|
|
|
|
|
|
|
if (ia32_maxdsiz == 0 && ia32_maxssiz == 0 && ia32_maxvmem == 0)
|
|
|
|
return;
|
|
|
|
newlim = lim_alloc();
|
|
|
|
PROC_LOCK(p);
|
|
|
|
oldlim = p->p_limit;
|
|
|
|
lim_copy(newlim, oldlim);
|
2003-09-25 01:10:26 +00:00
|
|
|
if (ia32_maxdsiz != 0) {
|
2004-02-04 21:52:57 +00:00
|
|
|
if (newlim->pl_rlimit[RLIMIT_DATA].rlim_cur > ia32_maxdsiz)
|
|
|
|
newlim->pl_rlimit[RLIMIT_DATA].rlim_cur = ia32_maxdsiz;
|
|
|
|
if (newlim->pl_rlimit[RLIMIT_DATA].rlim_max > ia32_maxdsiz)
|
|
|
|
newlim->pl_rlimit[RLIMIT_DATA].rlim_max = ia32_maxdsiz;
|
2003-09-25 01:10:26 +00:00
|
|
|
}
|
|
|
|
if (ia32_maxssiz != 0) {
|
2004-02-04 21:52:57 +00:00
|
|
|
if (newlim->pl_rlimit[RLIMIT_STACK].rlim_cur > ia32_maxssiz)
|
|
|
|
newlim->pl_rlimit[RLIMIT_STACK].rlim_cur = ia32_maxssiz;
|
|
|
|
if (newlim->pl_rlimit[RLIMIT_STACK].rlim_max > ia32_maxssiz)
|
|
|
|
newlim->pl_rlimit[RLIMIT_STACK].rlim_max = ia32_maxssiz;
|
2003-09-25 01:10:26 +00:00
|
|
|
}
|
|
|
|
if (ia32_maxvmem != 0) {
|
2004-02-04 21:52:57 +00:00
|
|
|
if (newlim->pl_rlimit[RLIMIT_VMEM].rlim_cur > ia32_maxvmem)
|
|
|
|
newlim->pl_rlimit[RLIMIT_VMEM].rlim_cur = ia32_maxvmem;
|
|
|
|
if (newlim->pl_rlimit[RLIMIT_VMEM].rlim_max > ia32_maxvmem)
|
|
|
|
newlim->pl_rlimit[RLIMIT_VMEM].rlim_max = ia32_maxvmem;
|
2003-09-25 01:10:26 +00:00
|
|
|
}
|
2004-02-04 21:52:57 +00:00
|
|
|
p->p_limit = newlim;
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
lim_free(oldlim);
|
2003-09-25 01:10:26 +00:00
|
|
|
}
|