2 * Copyright (c) 2002 Doug Rabson
3 * Copyright (c) 2003 Peter Wemm
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include "opt_compat.h"
33 #define __ELF_WORD_SIZE 32
35 #include <sys/param.h>
37 #include <sys/fcntl.h>
38 #include <sys/imgact.h>
39 #include <sys/kernel.h>
41 #include <sys/malloc.h>
42 #include <sys/mutex.h>
44 #include <sys/namei.h>
45 #include <sys/pioctl.h>
47 #include <sys/procfs.h>
48 #include <sys/resourcevar.h>
49 #include <sys/systm.h>
50 #include <sys/signalvar.h>
53 #include <sys/syscall.h>
54 #include <sys/sysctl.h>
55 #include <sys/sysent.h>
56 #include <sys/vnode.h>
57 #include <sys/imgact_elf.h>
60 #include <vm/vm_kern.h>
61 #include <vm/vm_param.h>
63 #include <vm/vm_map.h>
64 #include <vm/vm_object.h>
65 #include <vm/vm_extern.h>
67 #include <compat/freebsd32/freebsd32_signal.h>
68 #include <compat/freebsd32/freebsd32_util.h>
69 #include <compat/freebsd32/freebsd32_proto.h>
70 #include <compat/freebsd32/freebsd32_syscall.h>
71 #include <compat/ia32/ia32_signal.h>
73 #include <machine/psl.h>
74 #include <machine/segments.h>
75 #include <machine/specialreg.h>
77 #include <i386/include/psl.h>
78 #include <i386/include/segments.h>
79 #include <i386/include/specialreg.h>
81 #include <machine/frame.h>
82 #include <machine/md_var.h>
83 #include <machine/pcb.h>
84 #include <machine/cpufunc.h>
86 CTASSERT(sizeof(struct ia32_mcontext) == 640);
87 CTASSERT(sizeof(struct ia32_ucontext) == 704);
88 CTASSERT(sizeof(struct ia32_sigframe) == 800);
89 CTASSERT(sizeof(struct siginfo32) == 64);
90 #ifdef COMPAT_FREEBSD4
91 CTASSERT(sizeof(struct ia32_mcontext4) == 260);
92 CTASSERT(sizeof(struct ia32_ucontext4) == 324);
93 CTASSERT(sizeof(struct ia32_sigframe4) == 408);
96 extern const char *freebsd32_syscallnames[];
98 static void ia32_fixlimit(struct rlimit *rl, int which);
100 SYSCTL_NODE(_compat, OID_AUTO, ia32, CTLFLAG_RW, 0, "ia32 mode");
102 static u_long ia32_maxdsiz = IA32_MAXDSIZ;
103 SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxdsiz, CTLFLAG_RW, &ia32_maxdsiz, 0, "");
104 TUNABLE_ULONG("compat.ia32.maxdsiz", &ia32_maxdsiz);
105 static u_long ia32_maxssiz = IA32_MAXSSIZ;
106 SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxssiz, CTLFLAG_RW, &ia32_maxssiz, 0, "");
107 TUNABLE_ULONG("compat.ia32.maxssiz", &ia32_maxssiz);
108 static u_long ia32_maxvmem = IA32_MAXVMEM;
109 SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxvmem, CTLFLAG_RW, &ia32_maxvmem, 0, "");
110 TUNABLE_ULONG("compat.ia32.maxvmem", &ia32_maxvmem);
112 struct sysentvec ia32_freebsd_sysvec = {
113 .sv_size = FREEBSD32_SYS_MAXSYSCALL,
114 .sv_table = freebsd32_sysent,
120 .sv_transtrap = NULL,
121 .sv_fixup = elf32_freebsd_fixup,
122 .sv_sendsig = ia32_sendsig,
123 .sv_sigcode = ia32_sigcode,
124 .sv_szsigcode = &sz_ia32_sigcode,
125 .sv_prepsyscall = NULL,
126 .sv_name = "FreeBSD ELF32",
127 .sv_coredump = elf32_coredump,
128 .sv_imgact_try = NULL,
129 .sv_minsigstksz = MINSIGSTKSZ,
130 .sv_pagesize = IA32_PAGE_SIZE,
132 .sv_maxuser = FREEBSD32_USRSTACK,
133 .sv_usrstack = FREEBSD32_USRSTACK,
134 .sv_psstrings = FREEBSD32_PS_STRINGS,
135 .sv_stackprot = VM_PROT_ALL,
136 .sv_copyout_strings = freebsd32_copyout_strings,
137 .sv_setregs = ia32_setregs,
138 .sv_fixlimit = ia32_fixlimit,
139 .sv_maxssiz = &ia32_maxssiz,
140 .sv_flags = SV_ABI_FREEBSD | SV_IA32 | SV_ILP32,
141 .sv_set_syscall_retval = ia32_set_syscall_retval,
142 .sv_fetch_syscall_args = ia32_fetch_syscall_args,
143 .sv_syscallnames = freebsd32_syscallnames,
147 static Elf32_Brandinfo ia32_brand_info = {
148 .brand = ELFOSABI_FREEBSD,
150 .compat_3_brand = "FreeBSD",
152 .interp_path = "/libexec/ld-elf.so.1",
153 .sysvec = &ia32_freebsd_sysvec,
154 .interp_newpath = "/libexec/ld-elf32.so.1",
155 .brand_note = &elf32_freebsd_brandnote,
156 .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
159 SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_MIDDLE,
160 (sysinit_cfunc_t) elf32_insert_brand_entry,
163 static Elf32_Brandinfo ia32_brand_oinfo = {
164 .brand = ELFOSABI_FREEBSD,
166 .compat_3_brand = "FreeBSD",
168 .interp_path = "/usr/libexec/ld-elf.so.1",
169 .sysvec = &ia32_freebsd_sysvec,
170 .interp_newpath = "/libexec/ld-elf32.so.1",
171 .brand_note = &elf32_freebsd_brandnote,
172 .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
175 SYSINIT(oia32, SI_SUB_EXEC, SI_ORDER_ANY,
176 (sysinit_cfunc_t) elf32_insert_brand_entry,
179 static Elf32_Brandinfo kia32_brand_info = {
180 .brand = ELFOSABI_FREEBSD,
182 .compat_3_brand = "FreeBSD",
184 .interp_path = "/lib/ld.so.1",
185 .sysvec = &ia32_freebsd_sysvec,
186 .brand_note = &elf32_kfreebsd_brandnote,
187 .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE_MANDATORY
190 SYSINIT(kia32, SI_SUB_EXEC, SI_ORDER_ANY,
191 (sysinit_cfunc_t) elf32_insert_brand_entry,
196 elf32_dump_thread(struct thread *td __unused, void *dst __unused,
197 size_t *off __unused)
202 ia32_fixlimit(struct rlimit *rl, int which)
207 if (ia32_maxdsiz != 0) {
208 if (rl->rlim_cur > ia32_maxdsiz)
209 rl->rlim_cur = ia32_maxdsiz;
210 if (rl->rlim_max > ia32_maxdsiz)
211 rl->rlim_max = ia32_maxdsiz;
215 if (ia32_maxssiz != 0) {
216 if (rl->rlim_cur > ia32_maxssiz)
217 rl->rlim_cur = ia32_maxssiz;
218 if (rl->rlim_max > ia32_maxssiz)
219 rl->rlim_max = ia32_maxssiz;
223 if (ia32_maxvmem != 0) {
224 if (rl->rlim_cur > ia32_maxvmem)
225 rl->rlim_cur = ia32_maxvmem;
226 if (rl->rlim_max > ia32_maxvmem)
227 rl->rlim_max = ia32_maxvmem;