root/compat/aout/compat_aout.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. aout_compat_setup
  2. aout_sys_open
  3. aout_sys_link
  4. aout_sys_unlink
  5. aout_sys_rename

    1 /*      $OpenBSD: compat_aout.c,v 1.2 2003/08/23 19:28:53 tedu Exp $ */
    2 
    3 /*
    4  * Copyright (c) 2003 Marc Espie
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. The name of the author may not be used to endorse or promote products
   13  *    derived from this software without specific prior written permission
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   25  *
   26  */
   27 #include <sys/param.h>
   28 #include <sys/syscall.h>
   29 #include <sys/signalvar.h>
   30 #include <sys/mount.h>
   31 #include <sys/syscallargs.h>
   32 #include <sys/fcntl.h>
   33 #include <compat/common/compat_util.h>
   34 
   35 void aout_compat_setup(struct exec_package *epp);
   36 
   37 extern char sigcode[], esigcode[];
   38 
   39 struct sysent aout_sysent[SYS_MAXSYSCALL];
   40 
   41 struct emul emul_aout = {
   42         "aout",
   43         NULL,
   44         sendsig,
   45         SYS_syscall,
   46         SYS_MAXSYSCALL,
   47         NULL,
   48 #ifdef SYSCALL_DEBUG
   49         syscallnames,
   50 #else
   51         NULL,
   52 #endif
   53         0,
   54         copyargs,
   55         setregs,
   56         NULL,
   57         sigcode,
   58         esigcode,
   59 };
   60 
   61 #ifdef  syscallarg
   62 #undef  syscallarg
   63 #endif
   64 
   65 #define syscallarg(x)                                                   \
   66         union {                                                         \
   67                 register_t pad;                                         \
   68                 struct { x datum; } le;                                 \
   69                 struct {                                                \
   70                         int8_t pad[ (sizeof (register_t) < sizeof (x))  \
   71                                 ? 0                                     \
   72                                 : sizeof (register_t) - sizeof (x)];    \
   73                         x datum;                                        \
   74                 } be;                                                   \
   75         }
   76 
   77 
   78 struct aout_sys_open_args {
   79         syscallarg(char *) path;
   80         syscallarg(int) flags;
   81         syscallarg(int) mode;
   82 };
   83 
   84 struct aout_sys_link_args {
   85         syscallarg(char *) path;
   86         syscallarg(char *) link;
   87 };
   88 
   89 struct aout_sys_unlink_args {
   90         syscallarg(char *) path;
   91 };
   92 
   93 struct aout_sys_rename_args {
   94         syscallarg(char *) from;
   95         syscallarg(char *) to;
   96 };
   97 
   98 int aout_sys_open(struct proc *, void *, register_t *);
   99 int aout_sys_link(struct proc *, void *, register_t *);
  100 int aout_sys_unlink(struct proc *, void *, register_t *);
  101 int aout_sys_rename(struct proc *, void *, register_t *);
  102 
  103 const char aout_path[] = "/emul/a.out";
  104 
  105 #define AOUT_CHECK_ALT_EXIST(p, sgp, path) \
  106     CHECK_ALT_EXIST(p, sgp, aout_path, path)
  107 
  108 #define  AOUT_CHECK_ALT_CREAT(p, sgp, path) \
  109     CHECK_ALT_CREAT(p, sgp, aout_path, path)
  110 
  111 /* XXX We just translate enough calls to allow ldconfig and ld.so to work. */
  112 
  113 void
  114 aout_compat_setup(struct exec_package *epp)
  115 {
  116         if (emul_aout.e_sysent == NULL) {
  117                 memcpy(aout_sysent, sysent, sizeof aout_sysent); 
  118                 aout_sysent[SYS_open].sy_call = aout_sys_open;
  119                 aout_sysent[SYS_link].sy_call = aout_sys_link;
  120                 aout_sysent[SYS_unlink].sy_call = aout_sys_unlink;
  121                 aout_sysent[SYS_rename].sy_call = aout_sys_rename;
  122                 emul_aout.e_sysent = aout_sysent;
  123         }
  124         epp->ep_emul = &emul_aout;
  125 }
  126 
  127 int
  128 aout_sys_open(p, v, retval)
  129         struct proc *p;
  130         void *v;
  131         register_t *retval;
  132 {
  133         struct aout_sys_open_args /* {
  134                 syscallarg(char *) path;
  135                 syscallarg(int) flags;
  136                 syscallarg(int) mode;
  137         } */ *uap = v;
  138         caddr_t sg = stackgap_init(p->p_emul);
  139 
  140         if (SCARG(uap, flags) & O_CREAT)
  141                 AOUT_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
  142         else
  143                 AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  144         return sys_open(p, uap, retval);
  145 }
  146 
  147 int
  148 aout_sys_link(p, v, retval)
  149         struct proc *p;
  150         void *v;
  151         register_t *retval;
  152 {
  153         struct aout_sys_link_args /* {
  154                 syscallarg(char *) path;
  155                 syscallarg(char *) link;
  156         } */ *uap = v;
  157         caddr_t sg = stackgap_init(p->p_emul);
  158 
  159         AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  160         AOUT_CHECK_ALT_CREAT(p, &sg, SCARG(uap, link));
  161         return sys_link(p, uap, retval);
  162 }
  163 
  164 int
  165 aout_sys_unlink(p, v, retval)
  166         struct proc *p;
  167         void *v;
  168         register_t *retval;
  169 {
  170         struct aout_sys_unlink_args /* {
  171                 syscallarg(char *) path;
  172         } */ *uap = v;
  173         caddr_t sg = stackgap_init(p->p_emul);
  174 
  175         AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  176         return sys_unlink(p, uap, retval);
  177 }
  178 
  179 
  180 int
  181 aout_sys_rename(p, v, retval)
  182         struct proc *p;
  183         void *v;
  184         register_t *retval;
  185 {
  186         struct aout_sys_rename_args /* {
  187                 syscallarg(char *) from;
  188                 syscallarg(char *) to;
  189         } */ *uap = v;
  190         caddr_t sg = stackgap_init(p->p_emul);
  191 
  192         AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
  193         AOUT_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
  194         return sys_rename(p, uap, retval);
  195 }

/* [<][>][^][v][top][bottom][index][help] */