19454b2d8SWarner Losh /*- 28a36da99SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 38a36da99SPedro F. Giffuni * 4cfefd687SGarrett Wollman * Copyright (c) 1993, David Greenman 5cfefd687SGarrett Wollman * All rights reserved. 6cfefd687SGarrett Wollman * 7cfefd687SGarrett Wollman * Redistribution and use in source and binary forms, with or without 8cfefd687SGarrett Wollman * modification, are permitted provided that the following conditions 9cfefd687SGarrett Wollman * are met: 10cfefd687SGarrett Wollman * 1. Redistributions of source code must retain the above copyright 11cfefd687SGarrett Wollman * notice, this list of conditions and the following disclaimer. 12cfefd687SGarrett Wollman * 2. Redistributions in binary form must reproduce the above copyright 13cfefd687SGarrett Wollman * notice, this list of conditions and the following disclaimer in the 14cfefd687SGarrett Wollman * documentation and/or other materials provided with the distribution. 15cfefd687SGarrett Wollman * 16cfefd687SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17cfefd687SGarrett Wollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18cfefd687SGarrett Wollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191984b014SDavid Greenman * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20cfefd687SGarrett Wollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21cfefd687SGarrett Wollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22cfefd687SGarrett Wollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23cfefd687SGarrett Wollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24cfefd687SGarrett Wollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25cfefd687SGarrett Wollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26cfefd687SGarrett Wollman * SUCH DAMAGE. 27cfefd687SGarrett Wollman */ 28cfefd687SGarrett Wollman 29677b542eSDavid E. O'Brien #include <sys/cdefs.h> 30677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 31677b542eSDavid E. O'Brien 3226f9a767SRodney W. Grimes #include <sys/param.h> 3326f9a767SRodney W. Grimes #include <sys/exec.h> 3426f9a767SRodney W. Grimes #include <sys/imgact.h> 35bc6d7444SDavid Greenman #include <sys/imgact_aout.h> 3626f9a767SRodney W. Grimes #include <sys/kernel.h> 377332c129SKonstantin Belousov #include <sys/limits.h> 38fb919e4dSMark Murray #include <sys/lock.h> 39e5d6cd0cSBruce Evans #include <sys/malloc.h> 40fb919e4dSMark Murray #include <sys/mutex.h> 41a794e791SBruce Evans #include <sys/proc.h> 421ba5ad42SEdward Tomasz Napierala #include <sys/racct.h> 43fb919e4dSMark Murray #include <sys/resourcevar.h> 4422d4b0fbSJohn Polstra #include <sys/signalvar.h> 4522d4b0fbSJohn Polstra #include <sys/syscall.h> 46e5d6cd0cSBruce Evans #include <sys/sysent.h> 47e5d6cd0cSBruce Evans #include <sys/systm.h> 48a794e791SBruce Evans #include <sys/vnode.h> 49fb919e4dSMark Murray 50710ded3aSPeter Wemm #include <machine/frame.h> 51e5d6cd0cSBruce Evans #include <machine/md_var.h> 52cfefd687SGarrett Wollman 5326f9a767SRodney W. Grimes #include <vm/vm.h> 54efeaf95aSDavid Greenman #include <vm/pmap.h> 55efeaf95aSDavid Greenman #include <vm/vm_map.h> 561616db3cSJohn Dyson #include <vm/vm_object.h> 57e5d6cd0cSBruce Evans #include <vm/vm_param.h> 58cfefd687SGarrett Wollman 597332c129SKonstantin Belousov #ifdef __amd64__ 607332c129SKonstantin Belousov #include <compat/freebsd32/freebsd32_signal.h> 617332c129SKonstantin Belousov #include <compat/freebsd32/freebsd32_util.h> 627332c129SKonstantin Belousov #include <compat/freebsd32/freebsd32_proto.h> 637332c129SKonstantin Belousov #include <compat/freebsd32/freebsd32_syscall.h> 647332c129SKonstantin Belousov #include <compat/ia32/ia32_signal.h> 657332c129SKonstantin Belousov #endif 667332c129SKonstantin Belousov 674d77a549SAlfred Perlstein static int exec_aout_imgact(struct image_params *imgp); 6831174518SJohn Baldwin static int aout_fixup(uintptr_t *stack_base, struct image_params *imgp); 697ee050b7SBruce Evans 70d86c1f0dSKonstantin Belousov #define AOUT32_USRSTACK 0xbfc00000 71d86c1f0dSKonstantin Belousov 727332c129SKonstantin Belousov #if defined(__i386__) 73d86c1f0dSKonstantin Belousov 74d86c1f0dSKonstantin Belousov #define AOUT32_PS_STRINGS (AOUT32_USRSTACK - sizeof(struct ps_strings)) 75d86c1f0dSKonstantin Belousov 7622d4b0fbSJohn Polstra struct sysentvec aout_sysvec = { 77a8d403e1SKonstantin Belousov .sv_size = SYS_MAXSYSCALL, 78a8d403e1SKonstantin Belousov .sv_table = sysent, 79a8d403e1SKonstantin Belousov .sv_transtrap = NULL, 80a8d403e1SKonstantin Belousov .sv_fixup = aout_fixup, 81a8d403e1SKonstantin Belousov .sv_sendsig = sendsig, 82a8d403e1SKonstantin Belousov .sv_sigcode = sigcode, 83a8d403e1SKonstantin Belousov .sv_szsigcode = &szsigcode, 84a8d403e1SKonstantin Belousov .sv_name = "FreeBSD a.out", 85a8d403e1SKonstantin Belousov .sv_coredump = NULL, 86a8d403e1SKonstantin Belousov .sv_imgact_try = NULL, 87a8d403e1SKonstantin Belousov .sv_minsigstksz = MINSIGSTKSZ, 88a8d403e1SKonstantin Belousov .sv_minuser = VM_MIN_ADDRESS, 89d86c1f0dSKonstantin Belousov .sv_maxuser = AOUT32_USRSTACK, 90d86c1f0dSKonstantin Belousov .sv_usrstack = AOUT32_USRSTACK, 91d86c1f0dSKonstantin Belousov .sv_psstrings = AOUT32_PS_STRINGS, 92a8d403e1SKonstantin Belousov .sv_stackprot = VM_PROT_ALL, 93a8d403e1SKonstantin Belousov .sv_copyout_strings = exec_copyout_strings, 94a8d403e1SKonstantin Belousov .sv_setregs = exec_setregs, 95a8d403e1SKonstantin Belousov .sv_fixlimit = NULL, 96b4cf0e62SKonstantin Belousov .sv_maxssiz = NULL, 977332c129SKonstantin Belousov .sv_flags = SV_ABI_FREEBSD | SV_AOUT | SV_IA32 | SV_ILP32, 98afe1a688SKonstantin Belousov .sv_set_syscall_retval = cpu_set_syscall_retval, 99afe1a688SKonstantin Belousov .sv_fetch_syscall_args = cpu_fetch_syscall_args, 100afe1a688SKonstantin Belousov .sv_syscallnames = syscallnames, 101e5d81ef1SDmitry Chagin .sv_schedtail = NULL, 10291d1786fSDmitry Chagin .sv_thread_detach = NULL, 103038c7205SDmitry Chagin .sv_trap = NULL, 10428a66fc3SKonstantin Belousov .sv_onexec_old = exec_onexec_old, 10528a66fc3SKonstantin Belousov .sv_onexit = exit_onexit, 106de8374dfSDmitry Chagin .sv_set_fork_retval = x86_set_fork_retval, 10722d4b0fbSJohn Polstra }; 10822d4b0fbSJohn Polstra 1097332c129SKonstantin Belousov #elif defined(__amd64__) 1107332c129SKonstantin Belousov 111*98c8b625SKonstantin Belousov #include "vdso_ia32_offsets.h" 112*98c8b625SKonstantin Belousov 113*98c8b625SKonstantin Belousov extern const char _binary_elf_vdso32_so_1_start[]; 114*98c8b625SKonstantin Belousov extern const char _binary_elf_vdso32_so_1_end[]; 115*98c8b625SKonstantin Belousov extern char _binary_elf_vdso32_so_1_size; 116*98c8b625SKonstantin Belousov 1177332c129SKonstantin Belousov #define AOUT32_PS_STRINGS \ 1187332c129SKonstantin Belousov (AOUT32_USRSTACK - sizeof(struct freebsd32_ps_strings)) 119481af8b9SKonstantin Belousov #define AOUT32_MINUSER FREEBSD32_MINUSER 1207332c129SKonstantin Belousov 1217332c129SKonstantin Belousov extern const char *freebsd32_syscallnames[]; 1227332c129SKonstantin Belousov extern u_long ia32_maxssiz; 1237332c129SKonstantin Belousov 124*98c8b625SKonstantin Belousov static int aout_szsigcode; 125*98c8b625SKonstantin Belousov 1267332c129SKonstantin Belousov struct sysentvec aout_sysvec = { 1277332c129SKonstantin Belousov .sv_size = FREEBSD32_SYS_MAXSYSCALL, 1287332c129SKonstantin Belousov .sv_table = freebsd32_sysent, 1297332c129SKonstantin Belousov .sv_transtrap = NULL, 1307332c129SKonstantin Belousov .sv_fixup = aout_fixup, 1317332c129SKonstantin Belousov .sv_sendsig = ia32_sendsig, 132*98c8b625SKonstantin Belousov .sv_sigcode = _binary_elf_vdso32_so_1_start, 133*98c8b625SKonstantin Belousov .sv_szsigcode = &aout_szsigcode, 1347332c129SKonstantin Belousov .sv_name = "FreeBSD a.out", 1357332c129SKonstantin Belousov .sv_coredump = NULL, 1367332c129SKonstantin Belousov .sv_imgact_try = NULL, 1377332c129SKonstantin Belousov .sv_minsigstksz = MINSIGSTKSZ, 138481af8b9SKonstantin Belousov .sv_minuser = AOUT32_MINUSER, 1397332c129SKonstantin Belousov .sv_maxuser = AOUT32_USRSTACK, 1407332c129SKonstantin Belousov .sv_usrstack = AOUT32_USRSTACK, 1417332c129SKonstantin Belousov .sv_psstrings = AOUT32_PS_STRINGS, 1427332c129SKonstantin Belousov .sv_stackprot = VM_PROT_ALL, 1437332c129SKonstantin Belousov .sv_copyout_strings = freebsd32_copyout_strings, 1447332c129SKonstantin Belousov .sv_setregs = ia32_setregs, 1457332c129SKonstantin Belousov .sv_fixlimit = ia32_fixlimit, 1467332c129SKonstantin Belousov .sv_maxssiz = &ia32_maxssiz, 1477332c129SKonstantin Belousov .sv_flags = SV_ABI_FREEBSD | SV_AOUT | SV_IA32 | SV_ILP32, 1487332c129SKonstantin Belousov .sv_set_syscall_retval = ia32_set_syscall_retval, 1497332c129SKonstantin Belousov .sv_fetch_syscall_args = ia32_fetch_syscall_args, 1507332c129SKonstantin Belousov .sv_syscallnames = freebsd32_syscallnames, 15128a66fc3SKonstantin Belousov .sv_onexec_old = exec_onexec_old, 15228a66fc3SKonstantin Belousov .sv_onexit = exit_onexit, 153de8374dfSDmitry Chagin .sv_set_fork_retval = x86_set_fork_retval, 1547332c129SKonstantin Belousov }; 155*98c8b625SKonstantin Belousov 156*98c8b625SKonstantin Belousov static void 157*98c8b625SKonstantin Belousov aout_sysent(void *arg __unused) 158*98c8b625SKonstantin Belousov { 159*98c8b625SKonstantin Belousov aout_szsigcode = (int)(uintptr_t)&_binary_elf_vdso32_so_1_size; 160*98c8b625SKonstantin Belousov } 161*98c8b625SKonstantin Belousov SYSINIT(aout_sysent, SI_SUB_EXEC, SI_ORDER_ANY, aout_sysent, NULL); 1627332c129SKonstantin Belousov #else 1639da5257eSKonstantin Belousov #error "Only ia32 arch is supported" 1647332c129SKonstantin Belousov #endif 1657332c129SKonstantin Belousov 166b9e91a85SBruce Evans static int 16731174518SJohn Baldwin aout_fixup(uintptr_t *stack_base, struct image_params *imgp) 168f36ba452SJake Burkholder { 169f36ba452SJake Burkholder 17031174518SJohn Baldwin *stack_base -= sizeof(uint32_t); 17131174518SJohn Baldwin if (suword32((void *)*stack_base, imgp->args->argc) != 0) 17231174518SJohn Baldwin return (EFAULT); 17331174518SJohn Baldwin return (0); 174f36ba452SJake Burkholder } 175f36ba452SJake Burkholder 176f36ba452SJake Burkholder static int 1777332c129SKonstantin Belousov exec_aout_imgact(struct image_params *imgp) 178cfefd687SGarrett Wollman { 179290e05ddSKonstantin Belousov const struct exec *a_out; 1805856e12eSJohn Dyson struct vmspace *vmspace; 1812f33b2c0SAlan Cox vm_map_t map; 1821616db3cSJohn Dyson vm_object_t object; 1831616db3cSJohn Dyson vm_offset_t text_end, data_end; 184ede8dc43SBruce Evans unsigned long virtual_offset; 185a316d390SJohn Dyson unsigned long file_offset; 186cfefd687SGarrett Wollman unsigned long bss_size; 187bb56ec4aSPoul-Henning Kamp int error; 188cfefd687SGarrett Wollman 189290e05ddSKonstantin Belousov a_out = (const struct exec *)imgp->image_header; 190290e05ddSKonstantin Belousov 1911e1e0b44SSøren Schmidt /* 1921e1e0b44SSøren Schmidt * Linux and *BSD binaries look very much alike, 1931e1e0b44SSøren Schmidt * only the machine id is different: 194d3628763SRodney W. Grimes * 0x64 for Linux, 0x86 for *BSD, 0x00 for BSDI. 195185dc761SPeter Wemm * NetBSD is in network byte order.. ugh. 1961e1e0b44SSøren Schmidt */ 197f4dc9a40SWarner Losh if (((a_out->a_midmag >> 16) & 0xff) != 0x86 && 198f4dc9a40SWarner Losh ((a_out->a_midmag >> 16) & 0xff) != 0 && 199f4dc9a40SWarner Losh ((((int)ntohl(a_out->a_midmag)) >> 16) & 0xff) != 0x86) 200290e05ddSKonstantin Belousov return (-1); 2011e1e0b44SSøren Schmidt 202cfefd687SGarrett Wollman /* 203cfefd687SGarrett Wollman * Set file/virtual offset based on a.out variant. 204cfefd687SGarrett Wollman * We do two cases: host byte order and network byte order 205cfefd687SGarrett Wollman * (for NetBSD compatibility) 206cfefd687SGarrett Wollman */ 207f4dc9a40SWarner Losh switch ((int)(a_out->a_midmag & 0xffff)) { 208cfefd687SGarrett Wollman case ZMAGIC: 209cfefd687SGarrett Wollman virtual_offset = 0; 210cfefd687SGarrett Wollman if (a_out->a_text) { 211f8845af0SPoul-Henning Kamp file_offset = PAGE_SIZE; 212cfefd687SGarrett Wollman } else { 213cfefd687SGarrett Wollman /* Bill's "screwball mode" */ 214cfefd687SGarrett Wollman file_offset = 0; 215cfefd687SGarrett Wollman } 216cfefd687SGarrett Wollman break; 217cfefd687SGarrett Wollman case QMAGIC: 218f8845af0SPoul-Henning Kamp virtual_offset = PAGE_SIZE; 219cfefd687SGarrett Wollman file_offset = 0; 2204fe88fe6SJohn Polstra /* Pass PS_STRINGS for BSD/OS binaries only. */ 2214fe88fe6SJohn Polstra if (N_GETMID(*a_out) == MID_ZERO) 222397df744SBrooks Davis imgp->ps_strings = (void *)aout_sysvec.sv_psstrings; 223cfefd687SGarrett Wollman break; 224cfefd687SGarrett Wollman default: 225cfefd687SGarrett Wollman /* NetBSD compatibility */ 226f4dc9a40SWarner Losh switch ((int)(ntohl(a_out->a_midmag) & 0xffff)) { 227cfefd687SGarrett Wollman case ZMAGIC: 228cfefd687SGarrett Wollman case QMAGIC: 229f8845af0SPoul-Henning Kamp virtual_offset = PAGE_SIZE; 230cfefd687SGarrett Wollman file_offset = 0; 231cfefd687SGarrett Wollman break; 232cfefd687SGarrett Wollman default: 233cfefd687SGarrett Wollman return (-1); 234cfefd687SGarrett Wollman } 235cfefd687SGarrett Wollman } 236cfefd687SGarrett Wollman 237f8845af0SPoul-Henning Kamp bss_size = roundup(a_out->a_bss, PAGE_SIZE); 238cfefd687SGarrett Wollman 239cfefd687SGarrett Wollman /* 240cfefd687SGarrett Wollman * Check various fields in header for validity/bounds. 241cfefd687SGarrett Wollman */ 242cfefd687SGarrett Wollman if (/* entry point must lay with text region */ 243cfefd687SGarrett Wollman a_out->a_entry < virtual_offset || 244cfefd687SGarrett Wollman a_out->a_entry >= virtual_offset + a_out->a_text || 245cfefd687SGarrett Wollman 246cfefd687SGarrett Wollman /* text and data size must each be page rounded */ 2477332c129SKonstantin Belousov a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK 2487332c129SKonstantin Belousov 2497332c129SKonstantin Belousov #ifdef __amd64__ 2507332c129SKonstantin Belousov || 2517332c129SKonstantin Belousov /* overflows */ 2527332c129SKonstantin Belousov virtual_offset + a_out->a_text + a_out->a_data + bss_size > UINT_MAX 2537332c129SKonstantin Belousov #endif 2547332c129SKonstantin Belousov ) 255cfefd687SGarrett Wollman return (-1); 256cfefd687SGarrett Wollman 257cfefd687SGarrett Wollman /* text + data can't exceed file size */ 258c52007c2SDavid Greenman if (a_out->a_data + a_out->a_text > imgp->attr->va_size) 259cfefd687SGarrett Wollman return (EFAULT); 260cfefd687SGarrett Wollman 261cfefd687SGarrett Wollman /* 262cfefd687SGarrett Wollman * text/data/bss must not exceed limits 263cfefd687SGarrett Wollman */ 26491d5354aSJohn Baldwin PROC_LOCK(imgp->proc); 265cfefd687SGarrett Wollman if (/* text can't exceed maximum text size */ 266cbc89bfbSPaul Saab a_out->a_text > maxtsiz || 267cfefd687SGarrett Wollman 268cfefd687SGarrett Wollman /* data + bss can't exceed rlimit */ 269f6f6d240SMateusz Guzik a_out->a_data + bss_size > lim_cur_proc(imgp->proc, RLIMIT_DATA) || 2701ba5ad42SEdward Tomasz Napierala racct_set(imgp->proc, RACCT_DATA, a_out->a_data + bss_size) != 0) { 27191d5354aSJohn Baldwin PROC_UNLOCK(imgp->proc); 272cfefd687SGarrett Wollman return (ENOMEM); 27391d5354aSJohn Baldwin } 27491d5354aSJohn Baldwin PROC_UNLOCK(imgp->proc); 275cfefd687SGarrett Wollman 276cfefd687SGarrett Wollman /* 27760bb3943SAlan Cox * Avoid a possible deadlock if the current address space is destroyed 27860bb3943SAlan Cox * and that address space maps the locked vnode. In the common case, 27960bb3943SAlan Cox * the locked vnode's v_usecount is decremented but remains greater 28060bb3943SAlan Cox * than zero. Consequently, the vnode lock is not needed by vrele(). 28160bb3943SAlan Cox * However, in cases where the vnode lock is external, such as nullfs, 28260bb3943SAlan Cox * v_usecount may become zero. 28360bb3943SAlan Cox */ 284b249ce48SMateusz Guzik VOP_UNLOCK(imgp->vp); 28560bb3943SAlan Cox 28660bb3943SAlan Cox /* 287cfefd687SGarrett Wollman * Destroy old process VM and create a new one (with a new stack) 288cfefd687SGarrett Wollman */ 28989b57fcfSKonstantin Belousov error = exec_new_vmspace(imgp, &aout_sysvec); 290cfefd687SGarrett Wollman 29178022527SKonstantin Belousov vn_lock(imgp->vp, LK_SHARED | LK_RETRY); 29289b57fcfSKonstantin Belousov if (error) 29389b57fcfSKonstantin Belousov return (error); 29460bb3943SAlan Cox 295cfefd687SGarrett Wollman /* 2965856e12eSJohn Dyson * The vm space can be changed by exec_new_vmspace 2975856e12eSJohn Dyson */ 2985856e12eSJohn Dyson vmspace = imgp->proc->p_vmspace; 2995856e12eSJohn Dyson 3000b2ed1aeSJeff Roberson object = imgp->object; 3012f33b2c0SAlan Cox map = &vmspace->vm_map; 3022f33b2c0SAlan Cox vm_map_lock(map); 3031616db3cSJohn Dyson vm_object_reference(object); 3041616db3cSJohn Dyson 3051616db3cSJohn Dyson text_end = virtual_offset + a_out->a_text; 3060a91231dSAlan Cox error = vm_map_insert(map, object, 3071616db3cSJohn Dyson file_offset, 3081616db3cSJohn Dyson virtual_offset, text_end, 3091616db3cSJohn Dyson VM_PROT_READ | VM_PROT_EXECUTE, VM_PROT_ALL, 31078022527SKonstantin Belousov MAP_COPY_ON_WRITE | MAP_PREFAULT | MAP_VN_EXEC); 3112f33b2c0SAlan Cox if (error) { 3122f33b2c0SAlan Cox vm_map_unlock(map); 31341634e2eSAlan Cox vm_object_deallocate(object); 314cfefd687SGarrett Wollman return (error); 3152f33b2c0SAlan Cox } 31678022527SKonstantin Belousov VOP_SET_TEXT_CHECKED(imgp->vp); 3171616db3cSJohn Dyson data_end = text_end + a_out->a_data; 3181616db3cSJohn Dyson if (a_out->a_data) { 3191616db3cSJohn Dyson vm_object_reference(object); 3200a91231dSAlan Cox error = vm_map_insert(map, object, 3211616db3cSJohn Dyson file_offset + a_out->a_text, 3221616db3cSJohn Dyson text_end, data_end, 3231616db3cSJohn Dyson VM_PROT_ALL, VM_PROT_ALL, 32478022527SKonstantin Belousov MAP_COPY_ON_WRITE | MAP_PREFAULT | MAP_VN_EXEC); 3252f33b2c0SAlan Cox if (error) { 3262f33b2c0SAlan Cox vm_map_unlock(map); 32741634e2eSAlan Cox vm_object_deallocate(object); 3281616db3cSJohn Dyson return (error); 3291616db3cSJohn Dyson } 33078022527SKonstantin Belousov VOP_SET_TEXT_CHECKED(imgp->vp); 3312f33b2c0SAlan Cox } 332cfefd687SGarrett Wollman 3331616db3cSJohn Dyson if (bss_size) { 3340a91231dSAlan Cox error = vm_map_insert(map, NULL, 0, 3351616db3cSJohn Dyson data_end, data_end + bss_size, 3361616db3cSJohn Dyson VM_PROT_ALL, VM_PROT_ALL, 0); 3372f33b2c0SAlan Cox if (error) { 3382f33b2c0SAlan Cox vm_map_unlock(map); 339cfefd687SGarrett Wollman return (error); 34068940ac1SDavid Greenman } 3412f33b2c0SAlan Cox } 3422f33b2c0SAlan Cox vm_map_unlock(map); 343cfefd687SGarrett Wollman 344cfefd687SGarrett Wollman /* Fill in process VM information */ 345cfefd687SGarrett Wollman vmspace->vm_tsize = a_out->a_text >> PAGE_SHIFT; 346cfefd687SGarrett Wollman vmspace->vm_dsize = (a_out->a_data + bss_size) >> PAGE_SHIFT; 3477cd99438SBruce Evans vmspace->vm_taddr = (caddr_t) (uintptr_t) virtual_offset; 3487cd99438SBruce Evans vmspace->vm_daddr = (caddr_t) (uintptr_t) 3497cd99438SBruce Evans (virtual_offset + a_out->a_text); 350cfefd687SGarrett Wollman 351cfefd687SGarrett Wollman /* Fill in image_params */ 352c52007c2SDavid Greenman imgp->interpreted = 0; 353c52007c2SDavid Greenman imgp->entry_addr = a_out->a_entry; 354cfefd687SGarrett Wollman 355c52007c2SDavid Greenman imgp->proc->p_sysent = &aout_sysvec; 356c0e5de7dSDavid Greenman 357cfefd687SGarrett Wollman return (0); 358cfefd687SGarrett Wollman } 35992d91f76SGarrett Wollman 36092d91f76SGarrett Wollman /* 36192d91f76SGarrett Wollman * Tell kern_execve.c about it, with a little help from the linker. 36292d91f76SGarrett Wollman */ 363b7feabf9SEd Maste static struct execsw aout_execsw = { 364b7feabf9SEd Maste .ex_imgact = exec_aout_imgact, 365b7feabf9SEd Maste .ex_name = "a.out" 366b7feabf9SEd Maste }; 367aa855a59SPeter Wemm EXEC_SET(aout, aout_execsw); 368