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/alpha/linux/linux_sysvec.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1994-1996 Søren Schmidt
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer 
   10  *    in this position and unchanged.
   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  * 3. The name of the author may not be used to endorse or promote products
   15  *    derived from this software without specific prior written permission
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  *
   28  * $FreeBSD: releng/5.1/sys/alpha/linux/linux_sysvec.c 112716 2003-03-27 18:18:35Z jhb $
   29  */
   30 
   31 /* XXX we use functions that might not exist. */
   32 #include "opt_compat.h"
   33 
   34 #ifndef COMPAT_43
   35 #error "Unable to compile Linux-emulator due to missing COMPAT_43 option!"
   36 #endif
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/exec.h>
   41 #include <sys/imgact.h>
   42 #include <sys/imgact_aout.h>
   43 #include <sys/imgact_elf.h>
   44 #include <sys/kernel.h>
   45 #include <sys/lock.h>
   46 #include <sys/malloc.h>
   47 #include <sys/module.h>
   48 #include <sys/mutex.h>
   49 #include <sys/proc.h>
   50 #include <sys/signalvar.h>
   51 #include <sys/sysent.h>
   52 
   53 #include <vm/vm.h>
   54 #include <vm/vm_param.h>
   55 #include <vm/vm_page.h>
   56 #include <vm/vm_extern.h>
   57 
   58 #include <machine/cpu.h>
   59 #include <machine/md_var.h>
   60 
   61 #include <alpha/linux/linux.h>
   62 #include <alpha/linux/linux_proto.h>
   63 #include <compat/linux/linux_mib.h>
   64 #include <compat/linux/linux_util.h>
   65 #undef szsigcode
   66 
   67 MODULE_VERSION(linux, 1);
   68 MODULE_DEPEND(linux, osf1, 1, 1, 1);
   69 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
   70 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
   71 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);
   72 
   73 MALLOC_DEFINE(M_LINUX, "linux", "Linux mode structures");
   74 
   75 #if BYTE_ORDER == LITTLE_ENDIAN
   76 #define SHELLMAGIC      0x2123 /* #! */
   77 #else
   78 #define SHELLMAGIC      0x2321
   79 #endif
   80 
   81 SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
   82 
   83 void osendsig(sig_t catcher, int sig, sigset_t *mask, u_long code);
   84 
   85 static int      elf_linux_fixup(register_t **stack_base,
   86     struct image_params *iparams);
   87 static int      exec_linux_imgact_try(struct image_params *iparams);
   88 
   89 static int
   90 elf_linux_fixup(register_t **stack_base, struct image_params *imgp)
   91 {
   92         Elf64_Auxargs *args;
   93         register_t *pos;
   94 
   95         KASSERT(curthread->td_proc == imgp->proc &&
   96             (curthread->td_proc->p_flag & P_THREADED) == 0,
   97             ("unsafe elf_linux_fixup(), should be curproc"));
   98         args = (Elf64_Auxargs *)imgp->auxargs;
   99         pos = *stack_base + (imgp->argc + imgp->envc + 2);
  100 
  101         if (args->trace)
  102                 AUXARGS_ENTRY(pos, AT_DEBUG, 1);
  103         if (args->execfd != -1)
  104                 AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
  105         AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
  106         AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
  107         AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
  108         AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
  109         AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
  110         AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
  111         AUXARGS_ENTRY(pos, AT_BASE, args->base);
  112         AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_ucred->cr_ruid);
  113         AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_ucred->cr_svuid);
  114         AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_ucred->cr_rgid);
  115         AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_ucred->cr_svgid);
  116         AUXARGS_ENTRY(pos, AT_NULL, 0);
  117         
  118         free(imgp->auxargs, M_TEMP);      
  119         imgp->auxargs = NULL;
  120 
  121         (*stack_base)--;
  122         **stack_base = (register_t)imgp->argc;
  123         return 0;
  124 }
  125 
  126 /*
  127  * If a linux binary is exec'ing something, try this image activator 
  128  * first.  We override standard shell script execution in order to
  129  * be able to modify the interpreter path.  We only do this if a linux
  130  * binary is doing the exec, so we do not create an EXEC module for it.
  131  */
  132 static int
  133 exec_linux_imgact_try(imgp)
  134         struct image_params *imgp;
  135 {
  136         const char *head;
  137         int error;
  138 
  139         head = (const char *)imgp->image_header;
  140         error = -1;
  141 
  142         /*
  143          * The interpreter for shell scripts run from a linux binary needs
  144          * to be located in /compat/linux if possible in order to recursively
  145          * maintain linux path emulation.
  146          */
  147         if (((const short *)head)[0] == SHELLMAGIC) {
  148                 /*
  149                  * Run our normal shell image activator.  If it succeeds
  150                  * attempt to use the alternate path for the interpreter.  If
  151                  * an alternate path is found, use our stringspace to store it.
  152                  */
  153                 if ((error = exec_shell_imgact(imgp)) == 0) {
  154                         char *rpath = NULL;
  155 
  156                         linux_emul_find(FIRST_THREAD_IN_PROC(imgp->proc), NULL,
  157                             imgp->interpreter_name, &rpath, 0);
  158                         if (rpath != imgp->interpreter_name) {
  159                                 int len = strlen(rpath) + 1;
  160 
  161                                 if (len <= MAXSHELLCMDLEN) {
  162                                         memcpy(imgp->interpreter_name, rpath,
  163                                             len);
  164                                 }
  165                                 free(rpath, M_TEMP);
  166                         }
  167                 }
  168         }
  169         return(error);
  170 }
  171 
  172 /*
  173  * To maintain OSF/1 compat, linux uses BSD signals & errnos on their
  174  * alpha port.  This greatly simplfies things for us.
  175  */
  176 
  177 struct sysentvec elf_linux_sysvec = {
  178         LINUX_SYS_MAXSYSCALL,
  179         linux_sysent,
  180         0,
  181         0,
  182         NULL,
  183         0,
  184         NULL,
  185         NULL,
  186         elf_linux_fixup,
  187         osendsig,
  188         linux_sigcode,
  189         &linux_szsigcode,
  190         NULL,
  191         "Linux ELF",
  192         elf64_coredump,
  193         exec_linux_imgact_try,
  194         LINUX_MINSIGSTKSZ,
  195         PAGE_SIZE,
  196         VM_MIN_ADDRESS,
  197         VM_MAXUSER_ADDRESS,
  198         USRSTACK,
  199         PS_STRINGS,
  200         VM_PROT_ALL,
  201         exec_copyout_strings,
  202         exec_setregs
  203 };
  204 
  205 static Elf64_Brandinfo linux_brand = {
  206                                         ELFOSABI_LINUX,
  207                                         EM_ALPHA,
  208                                         "Linux",
  209                                         "/compat/linux",
  210                                         "/lib/ld-linux.so.1",
  211                                         &elf_linux_sysvec
  212                                  };
  213 
  214 static Elf64_Brandinfo linux_glibc2brand = {
  215                                         ELFOSABI_LINUX,
  216                                         EM_ALPHA,
  217                                         "Linux",
  218                                         "/compat/linux",
  219                                         "/lib/ld-linux.so.2",
  220                                         &elf_linux_sysvec
  221                                  };
  222 
  223 Elf64_Brandinfo *linux_brandlist[] = {
  224                                         &linux_brand,
  225                                         &linux_glibc2brand,
  226                                         NULL
  227                                 };
  228 
  229 static int
  230 linux_elf_modevent(module_t mod, int type, void *data)
  231 {
  232         Elf64_Brandinfo **brandinfo;
  233         int error;
  234         struct linux_ioctl_handler **lihp;
  235 
  236         error = 0;
  237 
  238         switch(type) {
  239         case MOD_LOAD:
  240                 for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
  241                     ++brandinfo)
  242                         if (elf64_insert_brand_entry(*brandinfo) < 0)
  243                                 error = EINVAL;
  244                 if (error == 0) {
  245                         SET_FOREACH(lihp, linux_ioctl_handler_set)
  246                                 linux_ioctl_register_handler(*lihp);
  247                         if (bootverbose)
  248                                 printf("Linux ELF exec handler installed\n");
  249                 } else
  250                         printf("cannot insert Linux ELF brand handler\n");
  251                 break;
  252         case MOD_UNLOAD:
  253                 for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
  254                     ++brandinfo)
  255                         if (elf64_brand_inuse(*brandinfo))
  256                                 error = EBUSY;
  257                 if (error == 0) {
  258                         for (brandinfo = &linux_brandlist[0];
  259                             *brandinfo != NULL; ++brandinfo)
  260                                 if (elf64_remove_brand_entry(*brandinfo) < 0)
  261                                         error = EINVAL;
  262                 }
  263                 if (error == 0) {
  264                         SET_FOREACH(lihp, linux_ioctl_handler_set)
  265                                 linux_ioctl_unregister_handler(*lihp);
  266                         if (bootverbose)
  267                                 printf("Linux ELF exec handler removed\n");
  268                         linux_mib_destroy();
  269                 } else
  270                         printf("Could not deinstall ELF interpreter entry\n");
  271                 break;
  272         default:
  273                 break;
  274         }
  275         return error;
  276 }
  277 
  278 static moduledata_t linux_elf_mod = {
  279         "linuxelf",
  280         linux_elf_modevent,
  281         0
  282 };
  283 
  284 DUMMY(rt_sigreturn);
  285 
  286 DECLARE_MODULE(linuxelf, linux_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY);

Cache object: 1cecba0deedc93b949364525f721a0d0


[ 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.