The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/ia32/ia32_sysvec.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2002 Doug Rabson
    3  * Copyright (c) 2003 Peter Wemm
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    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.
   14  *
   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
   25  * SUCH DAMAGE.
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD$");
   30 
   31 #include "opt_compat.h"
   32 
   33 #define __ELF_WORD_SIZE 32
   34 
   35 #include <sys/param.h>
   36 #include <sys/exec.h>
   37 #include <sys/fcntl.h>
   38 #include <sys/imgact.h>
   39 #include <sys/kernel.h>
   40 #include <sys/lock.h>
   41 #include <sys/malloc.h>
   42 #include <sys/mutex.h>
   43 #include <sys/mman.h>
   44 #include <sys/namei.h>
   45 #include <sys/pioctl.h>
   46 #include <sys/proc.h>
   47 #include <sys/procfs.h>
   48 #include <sys/resourcevar.h>
   49 #include <sys/systm.h>
   50 #include <sys/signalvar.h>
   51 #include <sys/stat.h>
   52 #include <sys/sx.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>
   58 
   59 #include <vm/vm.h>
   60 #include <vm/vm_kern.h>
   61 #include <vm/vm_param.h>
   62 #include <vm/pmap.h>
   63 #include <vm/vm_map.h>
   64 #include <vm/vm_object.h>
   65 #include <vm/vm_extern.h>
   66 
   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>
   72 #ifdef __amd64__
   73 #include <machine/psl.h>
   74 #include <machine/segments.h>
   75 #include <machine/specialreg.h>
   76 #else
   77 #include <i386/include/psl.h>
   78 #include <i386/include/segments.h>
   79 #include <i386/include/specialreg.h>
   80 #endif
   81 #include <machine/frame.h>
   82 #include <machine/md_var.h>
   83 #include <machine/pcb.h>
   84 #include <machine/cpufunc.h>
   85 
   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);
   94 #endif
   95 
   96 static register_t *ia32_copyout_strings(struct image_params *imgp);
   97 static void ia32_fixlimit(struct rlimit *rl, int which);
   98 
   99 SYSCTL_NODE(_compat, OID_AUTO, ia32, CTLFLAG_RW, 0, "ia32 mode");
  100 
  101 static u_long   ia32_maxdsiz = IA32_MAXDSIZ;
  102 SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxdsiz, CTLFLAG_RW, &ia32_maxdsiz, 0, "");
  103 TUNABLE_ULONG("compat.ia32.maxdsiz", &ia32_maxdsiz);
  104 static u_long   ia32_maxssiz = IA32_MAXSSIZ;
  105 SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxssiz, CTLFLAG_RW, &ia32_maxssiz, 0, "");
  106 TUNABLE_ULONG("compat.ia32.maxssiz", &ia32_maxssiz);
  107 static u_long   ia32_maxvmem = IA32_MAXVMEM;
  108 SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxvmem, CTLFLAG_RW, &ia32_maxvmem, 0, "");
  109 TUNABLE_ULONG("compat.ia32.maxvmem", &ia32_maxvmem);
  110 
  111 struct sysentvec ia32_freebsd_sysvec = {
  112         .sv_size        = FREEBSD32_SYS_MAXSYSCALL,
  113         .sv_table       = freebsd32_sysent,
  114         .sv_mask        = 0,
  115         .sv_sigsize     = 0,
  116         .sv_sigtbl      = NULL,
  117         .sv_errsize     = 0,
  118         .sv_errtbl      = NULL,
  119         .sv_transtrap   = NULL,
  120         .sv_fixup       = elf32_freebsd_fixup,
  121         .sv_sendsig     = ia32_sendsig,
  122         .sv_sigcode     = ia32_sigcode,
  123         .sv_szsigcode   = &sz_ia32_sigcode,
  124         .sv_prepsyscall = NULL,
  125         .sv_name        = "FreeBSD ELF32",
  126         .sv_coredump    = elf32_coredump,
  127         .sv_imgact_try  = NULL,
  128         .sv_minsigstksz = MINSIGSTKSZ,
  129         .sv_pagesize    = IA32_PAGE_SIZE,
  130         .sv_minuser     = 0,
  131         .sv_maxuser     = FREEBSD32_USRSTACK,
  132         .sv_usrstack    = FREEBSD32_USRSTACK,
  133         .sv_psstrings   = FREEBSD32_PS_STRINGS,
  134         .sv_stackprot   = VM_PROT_ALL,
  135         .sv_copyout_strings     = ia32_copyout_strings,
  136         .sv_setregs     = ia32_setregs,
  137         .sv_fixlimit    = ia32_fixlimit,
  138         .sv_maxssiz     = &ia32_maxssiz
  139 };
  140 
  141 
  142 static Elf32_Brandinfo ia32_brand_info = {
  143         .brand          = ELFOSABI_FREEBSD,
  144         .machine        = EM_386,
  145         .compat_3_brand = "FreeBSD",
  146         .emul_path      = NULL,
  147         .interp_path    = "/libexec/ld-elf.so.1",
  148         .sysvec         = &ia32_freebsd_sysvec,
  149         .interp_newpath = "/libexec/ld-elf32.so.1",
  150         .brand_note     = &elf32_freebsd_brandnote,
  151         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  152 };
  153 
  154 SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY,
  155         (sysinit_cfunc_t) elf32_insert_brand_entry,
  156         &ia32_brand_info);
  157 
  158 static Elf32_Brandinfo ia32_brand_oinfo = {
  159         .brand          = ELFOSABI_FREEBSD,
  160         .machine        = EM_386,
  161         .compat_3_brand = "FreeBSD",
  162         .emul_path      = NULL,
  163         .interp_path    = "/usr/libexec/ld-elf.so.1",
  164         .sysvec         = &ia32_freebsd_sysvec,
  165         .interp_newpath = "/libexec/ld-elf32.so.1",
  166         .brand_note     = &elf32_freebsd_brandnote,
  167         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  168 };
  169 
  170 SYSINIT(oia32, SI_SUB_EXEC, SI_ORDER_ANY,
  171         (sysinit_cfunc_t) elf32_insert_brand_entry,
  172         &ia32_brand_oinfo);
  173 
  174 static Elf32_Brandinfo kia32_brand_info = {
  175         .brand          = ELFOSABI_FREEBSD,
  176         .machine        = EM_386,
  177         .compat_3_brand = "FreeBSD",
  178         .emul_path      = NULL,
  179         .interp_path    = "/lib/ld.so.1",
  180         .sysvec         = &ia32_freebsd_sysvec,
  181         .brand_note     = &elf32_kfreebsd_brandnote,
  182         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE_MANDATORY
  183 };
  184 
  185 SYSINIT(kia32, SI_SUB_EXEC, SI_ORDER_ANY,
  186         (sysinit_cfunc_t) elf32_insert_brand_entry,
  187         &kia32_brand_info);
  188 
  189 
  190 void
  191 elf32_dump_thread(struct thread *td __unused, void *dst __unused,
  192     size_t *off __unused)
  193 {
  194 }
  195 
  196 
  197 /* XXX may be freebsd32 MI */
  198 static register_t *
  199 ia32_copyout_strings(struct image_params *imgp)
  200 {
  201         int argc, envc;
  202         u_int32_t *vectp;
  203         char *stringp, *destp;
  204         u_int32_t *stack_base;
  205         struct freebsd32_ps_strings *arginfo;
  206         size_t execpath_len;
  207         int szsigcode;
  208 
  209         /*
  210          * Calculate string base and vector table pointers.
  211          * Also deal with signal trampoline code for this exec type.
  212          */
  213         if (imgp->execpath != NULL && imgp->auxargs != NULL)
  214                 execpath_len = strlen(imgp->execpath) + 1;
  215         else
  216                 execpath_len = 0;
  217         arginfo = (struct freebsd32_ps_strings *)FREEBSD32_PS_STRINGS;
  218         szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
  219         destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
  220                 roundup(execpath_len, sizeof(char *)) -
  221                 roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
  222 
  223         /*
  224          * install sigcode
  225          */
  226         if (szsigcode)
  227                 copyout(imgp->proc->p_sysent->sv_sigcode,
  228                         ((caddr_t)arginfo - szsigcode), szsigcode);
  229 
  230         /*
  231          * Copy the image path for the rtld.
  232          */
  233         if (execpath_len != 0) {
  234                 imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
  235                 copyout(imgp->execpath, (void *)imgp->execpathp,
  236                     execpath_len);
  237         }
  238 
  239         /*
  240          * If we have a valid auxargs ptr, prepare some room
  241          * on the stack.
  242          */
  243         if (imgp->auxargs) {
  244                 /*
  245                  * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
  246                  * lower compatibility.
  247                  */
  248                 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
  249                         : (AT_COUNT * 2);
  250                 /*
  251                  * The '+ 2' is for the null pointers at the end of each of
  252                  * the arg and env vector sets,and imgp->auxarg_size is room
  253                  * for argument of Runtime loader.
  254                  */
  255                 vectp = (u_int32_t *) (destp - (imgp->args->argc +
  256                     imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
  257                     sizeof(u_int32_t));
  258         } else
  259                 /*
  260                  * The '+ 2' is for the null pointers at the end of each of
  261                  * the arg and env vector sets
  262                  */
  263                 vectp = (u_int32_t *)
  264                         (destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t));
  265 
  266         /*
  267          * vectp also becomes our initial stack base
  268          */
  269         stack_base = vectp;
  270 
  271         stringp = imgp->args->begin_argv;
  272         argc = imgp->args->argc;
  273         envc = imgp->args->envc;
  274         /*
  275          * Copy out strings - arguments and environment.
  276          */
  277         copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
  278 
  279         /*
  280          * Fill in "ps_strings" struct for ps, w, etc.
  281          */
  282         suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
  283         suword32(&arginfo->ps_nargvstr, argc);
  284 
  285         /*
  286          * Fill in argument portion of vector table.
  287          */
  288         for (; argc > 0; --argc) {
  289                 suword32(vectp++, (u_int32_t)(intptr_t)destp);
  290                 while (*stringp++ != 0)
  291                         destp++;
  292                 destp++;
  293         }
  294 
  295         /* a null vector table pointer separates the argp's from the envp's */
  296         suword32(vectp++, 0);
  297 
  298         suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
  299         suword32(&arginfo->ps_nenvstr, envc);
  300 
  301         /*
  302          * Fill in environment portion of vector table.
  303          */
  304         for (; envc > 0; --envc) {
  305                 suword32(vectp++, (u_int32_t)(intptr_t)destp);
  306                 while (*stringp++ != 0)
  307                         destp++;
  308                 destp++;
  309         }
  310 
  311         /* end of vector table is a null pointer */
  312         suword32(vectp, 0);
  313 
  314         return ((register_t *)stack_base);
  315 }
  316 
  317 static void
  318 ia32_fixlimit(struct rlimit *rl, int which)
  319 {
  320 
  321         switch (which) {
  322         case RLIMIT_DATA:
  323                 if (ia32_maxdsiz != 0) {
  324                         if (rl->rlim_cur > ia32_maxdsiz)
  325                                 rl->rlim_cur = ia32_maxdsiz;
  326                         if (rl->rlim_max > ia32_maxdsiz)
  327                                 rl->rlim_max = ia32_maxdsiz;
  328                 }
  329                 break;
  330         case RLIMIT_STACK:
  331                 if (ia32_maxssiz != 0) {
  332                         if (rl->rlim_cur > ia32_maxssiz)
  333                                 rl->rlim_cur = ia32_maxssiz;
  334                         if (rl->rlim_max > ia32_maxssiz)
  335                                 rl->rlim_max = ia32_maxssiz;
  336                 }
  337                 break;
  338         case RLIMIT_VMEM:
  339                 if (ia32_maxvmem != 0) {
  340                         if (rl->rlim_cur > ia32_maxvmem)
  341                                 rl->rlim_cur = ia32_maxvmem;
  342                         if (rl->rlim_max > ia32_maxvmem)
  343                                 rl->rlim_max = ia32_maxvmem;
  344                 }
  345                 break;
  346         }
  347 }

Cache object: d9751743ae4d44687e488d0cc8d40cf8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.