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/svr4_32/svr4_32_ipc.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 /*      $NetBSD: svr4_32_ipc.c,v 1.11 2006/07/28 13:02:21 hannken Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 1995 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: svr4_32_ipc.c,v 1.11 2006/07/28 13:02:21 hannken Exp $");
   41 
   42 #if defined(_KERNEL_OPT)
   43 #include "opt_sysv.h"
   44 #endif
   45 
   46 #include <sys/param.h>
   47 #include <sys/kernel.h>
   48 #include <sys/shm.h>
   49 #include <sys/msg.h>
   50 #include <sys/sem.h>
   51 #include <sys/proc.h>
   52 #include <sys/uio.h>
   53 #include <sys/time.h>
   54 #include <sys/malloc.h>
   55 #include <sys/mman.h>
   56 #include <sys/systm.h>
   57 #include <sys/stat.h>
   58 
   59 #include <sys/mount.h>
   60 #include <sys/sa.h>
   61 #include <sys/syscallargs.h>
   62 
   63 #include <compat/svr4_32/svr4_32_types.h>
   64 #include <compat/svr4_32/svr4_32_signal.h>
   65 #include <compat/svr4_32/svr4_32_lwp.h>
   66 #include <compat/svr4_32/svr4_32_ucontext.h>
   67 #include <compat/svr4_32/svr4_32_syscallargs.h>
   68 #include <compat/svr4_32/svr4_32_util.h>
   69 #include <compat/svr4_32/svr4_32_ipc.h>
   70 
   71 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
   72 static void svr4_32_to_bsd_ipc_perm __P((const struct svr4_32_ipc_perm *,
   73                                       struct ipc_perm *));
   74 static void bsd_to_svr4_32_ipc_perm __P((const struct ipc_perm *,
   75                                       struct svr4_32_ipc_perm *));
   76 #endif
   77 
   78 #ifdef SYSVSEM
   79 static void bsd_to_svr4_32_semid_ds __P((const struct semid_ds *,
   80                                       struct svr4_32_semid_ds *));
   81 static void svr4_32_to_bsd_semid_ds __P((const struct svr4_32_semid_ds *,
   82                                       struct semid_ds *));
   83 static int svr4_32_semop __P((struct lwp *, void *, register_t *));
   84 static int svr4_32_semget __P((struct lwp *, void *, register_t *));
   85 static int svr4_32_semctl __P((struct lwp *, void *, register_t *));
   86 #endif
   87 
   88 #ifdef SYSVMSG
   89 static void bsd_to_svr4_32_msqid_ds __P((const struct msqid_ds *,
   90                                       struct svr4_32_msqid_ds *));
   91 static void svr4_32_to_bsd_msqid_ds __P((const struct svr4_32_msqid_ds *,
   92                                       struct msqid_ds *));
   93 static int svr4_32_msgsnd __P((struct lwp *, void *, register_t *));
   94 static int svr4_32_msgrcv __P((struct lwp *, void *, register_t *));
   95 static int svr4_32_msgget __P((struct lwp *, void *, register_t *));
   96 static int svr4_32_msgctl __P((struct lwp *, void *, register_t *));
   97 #endif
   98 
   99 #ifdef SYSVSHM
  100 static void bsd_to_svr4_32_shmid_ds __P((const struct shmid_ds *,
  101                                       struct svr4_32_shmid_ds *));
  102 static void svr4_32_to_bsd_shmid_ds __P((const struct svr4_32_shmid_ds *,
  103                                       struct shmid_ds *));
  104 static int svr4_32_shmat __P((struct lwp *, void *, register_t *));
  105 static int svr4_32_shmdt __P((struct lwp *, void *, register_t *));
  106 static int svr4_32_shmget __P((struct lwp *, void *, register_t *));
  107 static int svr4_32_shmctl __P((struct lwp *, void *, register_t *));
  108 #endif
  109 
  110 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
  111 
  112 static void
  113 svr4_32_to_bsd_ipc_perm(spp, bpp)
  114         const struct svr4_32_ipc_perm *spp;
  115         struct ipc_perm *bpp;
  116 {
  117         bpp->_key = spp->key;
  118         bpp->uid = spp->uid;
  119         bpp->gid = spp->gid;
  120         bpp->cuid = spp->cuid;
  121         bpp->cgid = spp->cgid;
  122         bpp->mode = spp->mode;
  123         bpp->_seq = spp->seq;
  124 }
  125 
  126 static void
  127 bsd_to_svr4_32_ipc_perm(bpp, spp)
  128         const struct ipc_perm *bpp;
  129         struct svr4_32_ipc_perm *spp;
  130 {
  131         spp->key = bpp->_key;
  132         spp->uid = bpp->uid;
  133         spp->gid = bpp->gid;
  134         spp->cuid = bpp->cuid;
  135         spp->cgid = bpp->cgid;
  136         spp->mode = bpp->mode;
  137         spp->seq = bpp->_seq;
  138 }
  139 #endif
  140 
  141 #ifdef SYSVSEM
  142 static void
  143 bsd_to_svr4_32_semid_ds(bds, sds)
  144         const struct semid_ds *bds;
  145         struct svr4_32_semid_ds *sds;
  146 {
  147         bsd_to_svr4_32_ipc_perm(&bds->sem_perm, &sds->sem_perm);
  148         sds->sem_base = (svr4_32_semp)(u_long)bds->_sem_base;
  149         sds->sem_nsems = bds->sem_nsems;
  150         sds->sem_otime = bds->sem_otime;
  151         sds->sem_ctime = bds->sem_ctime;
  152 }
  153 
  154 static void
  155 svr4_32_to_bsd_semid_ds(sds, bds)
  156         const struct svr4_32_semid_ds *sds;
  157         struct semid_ds *bds;
  158 {
  159         svr4_32_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
  160         bds->_sem_base = (struct __sem *)(u_long)sds->sem_base;
  161         bds->sem_nsems = sds->sem_nsems;
  162         bds->sem_otime = sds->sem_otime;
  163         bds->sem_ctime = sds->sem_ctime;
  164 }
  165 
  166 struct svr4_32_sys_semctl_args {
  167         syscallarg(int) what;
  168         syscallarg(int) semid;
  169         syscallarg(int) semnum;
  170         syscallarg(int) cmd;
  171         syscallarg(union netbsd32_semun) arg;
  172 };
  173 
  174 static int
  175 svr4_32_semctl(l, v, retval)
  176         struct lwp *l;
  177         void *v;
  178         register_t *retval;
  179 {
  180         struct svr4_32_sys_semctl_args *uap = v;
  181         struct semid_ds sembuf;
  182         struct svr4_32_semid_ds ssembuf;
  183         int cmd, error;
  184         void *pass_arg = NULL;
  185 
  186         cmd = SCARG(uap, cmd);
  187 
  188         switch (cmd) {
  189         case SVR4_IPC_SET:
  190                 pass_arg = &sembuf;
  191                 cmd = IPC_SET;
  192                 break;
  193 
  194         case SVR4_IPC_STAT:
  195                 pass_arg = &sembuf;
  196                 cmd = IPC_STAT;
  197                 break;
  198 
  199         case SVR4_IPC_RMID:
  200                 cmd = IPC_RMID;
  201                 break;
  202 
  203         case SVR4_SEM_GETVAL:
  204                 cmd = GETVAL;
  205                 break;
  206 
  207         case SVR4_SEM_GETPID:
  208                 cmd = GETPID;
  209                 break;
  210 
  211         case SVR4_SEM_GETNCNT:
  212                 cmd = GETNCNT;
  213                 break;
  214 
  215         case SVR4_SEM_GETZCNT:
  216                 cmd = GETZCNT;
  217                 break;
  218 
  219         case SVR4_SEM_GETALL:
  220                 pass_arg = &SCARG(uap, arg);
  221                 cmd = GETALL;
  222                 break;
  223 
  224         case SVR4_SEM_SETVAL:
  225                 pass_arg = &SCARG(uap, arg);
  226                 cmd = SETVAL;
  227                 break;
  228 
  229         case SVR4_SEM_SETALL:
  230                 pass_arg = &SCARG(uap, arg);
  231                 cmd = SETALL;
  232                 break;
  233 
  234         default:
  235                 return (EINVAL);
  236         }
  237 
  238         if (cmd == IPC_SET) {
  239                 error = copyin((caddr_t)(u_long)SCARG(uap, arg).buf,
  240                                &ssembuf, sizeof(ssembuf));
  241                 if (error)
  242                         return (error);
  243                 svr4_32_to_bsd_semid_ds(&ssembuf, &sembuf);
  244         }
  245 
  246         error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
  247             pass_arg, retval);
  248 
  249         if (error == 0 && cmd == IPC_STAT) {
  250                 bsd_to_svr4_32_semid_ds(&sembuf, &ssembuf);
  251                 error = copyout(&ssembuf, (caddr_t)(u_long)SCARG(uap, arg).buf,
  252                                 sizeof(ssembuf));
  253         }
  254 
  255         return (error);
  256 }
  257 
  258 struct svr4_32_sys_semget_args {
  259         syscallarg(int) what;
  260         syscallarg(svr4_key_t) key;
  261         syscallarg(int) nsems;
  262         syscallarg(int) semflg;
  263 };
  264 
  265 static int
  266 svr4_32_semget(l, v, retval)
  267         struct lwp *l;
  268         void *v;
  269         register_t *retval;
  270 {
  271         struct svr4_32_sys_semget_args *uap = v;
  272         struct sys_semget_args ap;
  273 
  274         SCARG(&ap, key) = SCARG(uap, key);
  275         SCARG(&ap, nsems) = SCARG(uap, nsems);
  276         SCARG(&ap, semflg) = SCARG(uap, semflg);
  277 
  278         return sys_semget(l, &ap, retval);
  279 }
  280 
  281 struct svr4_32_sys_semop_args {
  282         syscallarg(int) what;
  283         syscallarg(int) semid;
  284         syscallarg(svr4_32_sembufp) sops;
  285         syscallarg(u_int) nsops;
  286 };
  287 
  288 static int
  289 svr4_32_semop(l, v, retval)
  290         struct lwp *l;
  291         void *v;
  292         register_t *retval;
  293 {
  294         struct svr4_32_sys_semop_args *uap = v;
  295         struct sys_semop_args ap;
  296 
  297         SCARG(&ap, semid) = SCARG(uap, semid);
  298         /* These are the same */
  299         SCARG(&ap, sops) = (struct sembuf *)(u_long)SCARG(uap, sops);
  300         SCARG(&ap, nsops) = SCARG(uap, nsops);
  301 
  302         return sys_semop(l, &ap, retval);
  303 }
  304 
  305 int
  306 svr4_32_sys_semsys(l, v, retval)
  307         struct lwp *l;
  308         void *v;
  309         register_t *retval;
  310 {
  311         struct svr4_32_sys_semsys_args *uap = v;
  312 
  313         DPRINTF(("svr4_32_semsys(%d)\n", SCARG(uap, what)));
  314 
  315         switch (SCARG(uap, what)) {
  316         case SVR4_semctl:
  317                 return svr4_32_semctl(l, v, retval);
  318         case SVR4_semget:
  319                 return svr4_32_semget(l, v, retval);
  320         case SVR4_semop:
  321                 return svr4_32_semop(l, v, retval);
  322         default:
  323                 return EINVAL;
  324         }
  325 }
  326 #endif
  327 
  328 #ifdef SYSVMSG
  329 static void
  330 bsd_to_svr4_32_msqid_ds(bds, sds)
  331         const struct msqid_ds *bds;
  332         struct svr4_32_msqid_ds *sds;
  333 {
  334         bsd_to_svr4_32_ipc_perm(&bds->msg_perm, &sds->msg_perm);
  335         sds->msg_first = (svr4_32_msgp)(u_long)bds->_msg_first;
  336         sds->msg_last = (svr4_32_msgp)(u_long)bds->_msg_last;
  337         sds->msg_cbytes = bds->_msg_cbytes;
  338         sds->msg_qnum = bds->msg_qnum;
  339         sds->msg_qbytes = bds->msg_qbytes;
  340         sds->msg_lspid = bds->msg_lspid;
  341         sds->msg_lrpid = bds->msg_lrpid;
  342         sds->msg_stime = bds->msg_stime;
  343         sds->msg_rtime = bds->msg_rtime;
  344         sds->msg_ctime = bds->msg_ctime;
  345 
  346 #if 0
  347         /* XXX What to put here? */
  348         sds->msg_cv = 0;
  349         sds->msg_qnum_cv = 0;
  350 #endif
  351 }
  352 
  353 static void
  354 svr4_32_to_bsd_msqid_ds(sds, bds)
  355         const struct svr4_32_msqid_ds *sds;
  356         struct msqid_ds *bds;
  357 {
  358         svr4_32_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
  359         bds->_msg_first = (struct __msg *)(u_long)sds->msg_first;
  360         bds->_msg_last = (struct __msg *)(u_long)sds->msg_last;
  361         bds->_msg_cbytes = sds->msg_cbytes;
  362         bds->msg_qnum = sds->msg_qnum;
  363         bds->msg_qbytes = sds->msg_qbytes;
  364         bds->msg_lspid = sds->msg_lspid;
  365         bds->msg_lrpid = sds->msg_lrpid;
  366         bds->msg_stime = sds->msg_stime;
  367         bds->msg_rtime = sds->msg_rtime;
  368         bds->msg_ctime = sds->msg_ctime;
  369 
  370 #if 0
  371         XXX sds->msg_cv
  372         XXX sds->msg_qnum_cv
  373 #endif
  374 }
  375 
  376 struct svr4_32_sys_msgsnd_args {
  377         syscallarg(int) what;
  378         syscallarg(int) msqid;
  379         syscallarg(netbsd32_voidp) msgp;
  380         syscallarg(netbsd32_size_t) msgsz;
  381         syscallarg(int) msgflg;
  382 };
  383 
  384 static int
  385 svr4_32_msgsnd(l, v, retval)
  386         struct lwp *l;
  387         void *v;
  388         register_t *retval;
  389 {
  390         struct svr4_32_sys_msgsnd_args *uap = v;
  391         struct sys_msgsnd_args ap;
  392 
  393         SCARG(&ap, msqid) = SCARG(uap, msqid);
  394         SCARG(&ap, msgp) = (void *)(u_long)SCARG(uap, msgp);
  395         SCARG(&ap, msgsz) = SCARG(uap, msgsz);
  396         SCARG(&ap, msgflg) = SCARG(uap, msgflg);
  397 
  398         return sys_msgsnd(l, &ap, retval);
  399 }
  400 
  401 struct svr4_32_sys_msgrcv_args {
  402         syscallarg(int) what;
  403         syscallarg(int) msqid;
  404         syscallarg(netbsd32_voidp) msgp;
  405         syscallarg(netbsd32_size_t) msgsz;
  406         syscallarg(netbsd32_long) msgtyp;
  407         syscallarg(int) msgflg;
  408 };
  409 
  410 static int
  411 svr4_32_msgrcv(l, v, retval)
  412         struct lwp *l;
  413         void *v;
  414         register_t *retval;
  415 {
  416         struct svr4_32_sys_msgrcv_args *uap = v;
  417         struct sys_msgrcv_args ap;
  418 
  419         SCARG(&ap, msqid) = SCARG(uap, msqid);
  420         SCARG(&ap, msgp) = (void *)(u_long)SCARG(uap, msgp);
  421         SCARG(&ap, msgsz) = SCARG(uap, msgsz);
  422         SCARG(&ap, msgtyp) = SCARG(uap, msgtyp);
  423         SCARG(&ap, msgflg) = SCARG(uap, msgflg);
  424 
  425         return sys_msgrcv(l, &ap, retval);
  426 }
  427 
  428 struct svr4_32_sys_msgget_args {
  429         syscallarg(int) what;
  430         syscallarg(svr4_key_t) key;
  431         syscallarg(int) msgflg;
  432 };
  433 
  434 static int
  435 svr4_32_msgget(l, v, retval)
  436         struct lwp *l;
  437         void *v;
  438         register_t *retval;
  439 {
  440         struct svr4_32_sys_msgget_args *uap = v;
  441         struct sys_msgget_args ap;
  442 
  443         SCARG(&ap, key) = SCARG(uap, key);
  444         SCARG(&ap, msgflg) = SCARG(uap, msgflg);
  445 
  446         return sys_msgget(l, &ap, retval);
  447 }
  448 
  449 struct svr4_32_sys_msgctl_args {
  450         syscallarg(int) what;
  451         syscallarg(int) msqid;
  452         syscallarg(int) cmd;
  453         syscallarg(svr4_32_msqid_dsp) buf;
  454 };
  455 
  456 static int
  457 svr4_32_msgctl(l, v, retval)
  458         struct lwp *l;
  459         void *v;
  460         register_t *retval;
  461 {
  462         int error;
  463         struct svr4_32_sys_msgctl_args *uap = v;
  464         struct proc *p = l->l_proc;
  465         struct sys___msgctl13_args ap;
  466         struct svr4_32_msqid_ds ss;
  467         struct msqid_ds bs;
  468         caddr_t sg = stackgap_init(p, 0);
  469 
  470         SCARG(&ap, msqid) = SCARG(uap, msqid);
  471         SCARG(&ap, cmd) = SCARG(uap, cmd);
  472         SCARG(&ap, buf) = stackgap_alloc(p, &sg, sizeof(bs));
  473 
  474         switch (SCARG(uap, cmd)) {
  475         case SVR4_IPC_STAT:
  476                 SCARG(&ap, cmd) = IPC_STAT;
  477                 if ((error = sys___msgctl13(l, &ap, retval)) != 0)
  478                         return error;
  479                 error = copyin(&bs, SCARG(&ap, buf), sizeof bs);
  480                 if (error)
  481                         return error;
  482                 bsd_to_svr4_32_msqid_ds(&bs, &ss);
  483                 return copyout(&ss, (caddr_t)(u_long)SCARG(uap, buf), sizeof ss);
  484 
  485         case SVR4_IPC_SET:
  486                 SCARG(&ap, cmd) = IPC_SET;
  487                 error = copyin((caddr_t)(u_long)SCARG(uap, buf), &ss, sizeof ss);
  488                 if (error)
  489                         return error;
  490                 svr4_32_to_bsd_msqid_ds(&ss, &bs);
  491                 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
  492                 if (error)
  493                         return error;
  494                 return sys___msgctl13(l, &ap, retval);
  495 
  496         case SVR4_IPC_RMID:
  497                 SCARG(&ap, cmd) = IPC_RMID;
  498                 error = copyin((caddr_t)(u_long)SCARG(uap, buf), &ss, sizeof ss);
  499                 if (error)
  500                         return error;
  501                 svr4_32_to_bsd_msqid_ds(&ss, &bs);
  502                 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
  503                 if (error)
  504                         return error;
  505                 return sys___msgctl13(l, &ap, retval);
  506 
  507         default:
  508                 return EINVAL;
  509         }
  510 }
  511 
  512 int
  513 svr4_32_sys_msgsys(l, v, retval)
  514         struct lwp *l;
  515         void *v;
  516         register_t *retval;
  517 {
  518         struct svr4_32_sys_msgsys_args *uap = v;
  519 
  520         DPRINTF(("svr4_32_msgsys(%d)\n", SCARG(uap, what)));
  521 
  522         switch (SCARG(uap, what)) {
  523         case SVR4_msgsnd:
  524                 return svr4_32_msgsnd(l, v, retval);
  525         case SVR4_msgrcv:
  526                 return svr4_32_msgrcv(l, v, retval);
  527         case SVR4_msgget:
  528                 return svr4_32_msgget(l, v, retval);
  529         case SVR4_msgctl:
  530                 return svr4_32_msgctl(l, v, retval);
  531         default:
  532                 return EINVAL;
  533         }
  534 }
  535 #endif
  536 
  537 #ifdef SYSVSHM
  538 
  539 static void
  540 bsd_to_svr4_32_shmid_ds(bds, sds)
  541         const struct shmid_ds *bds;
  542         struct svr4_32_shmid_ds *sds;
  543 {
  544         bsd_to_svr4_32_ipc_perm(&bds->shm_perm, &sds->shm_perm);
  545         sds->shm_segsz = bds->shm_segsz;
  546         sds->shm_lkcnt = 0;
  547         sds->shm_lpid = bds->shm_lpid;
  548         sds->shm_cpid = bds->shm_cpid;
  549         sds->shm_amp = (netbsd32_caddr_t)(u_long)bds->_shm_internal;
  550         sds->shm_nattch = bds->shm_nattch;
  551         sds->shm_cnattch = 0;
  552         sds->shm_atime = bds->shm_atime;
  553         sds->shm_pad1 = 0;
  554         sds->shm_dtime = bds->shm_dtime;
  555         sds->shm_pad2 = 0;
  556         sds->shm_ctime = bds->shm_ctime;
  557         sds->shm_pad3 = 0;
  558 }
  559 
  560 static void
  561 svr4_32_to_bsd_shmid_ds(sds, bds)
  562         const struct svr4_32_shmid_ds *sds;
  563         struct shmid_ds *bds;
  564 {
  565         svr4_32_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
  566         bds->shm_segsz = sds->shm_segsz;
  567         bds->shm_lpid = sds->shm_lpid;
  568         bds->shm_cpid = sds->shm_cpid;
  569         bds->_shm_internal = (void *)(u_long)sds->shm_amp;
  570         bds->shm_nattch = sds->shm_nattch;
  571         bds->shm_atime = sds->shm_atime;
  572         bds->shm_dtime = sds->shm_dtime;
  573         bds->shm_ctime = sds->shm_ctime;
  574 }
  575 
  576 struct svr4_32_sys_shmat_args {
  577         syscallarg(int) what;
  578         syscallarg(int) shmid;
  579         syscallarg(netbsd32_voidp) shmaddr;
  580         syscallarg(int) shmflg;
  581 };
  582 
  583 static int
  584 svr4_32_shmat(l, v, retval)
  585         struct lwp *l;
  586         void *v;
  587         register_t *retval;
  588 {
  589         struct svr4_32_sys_shmat_args *uap = v;
  590         struct sys_shmat_args ap;
  591 
  592         SCARG(&ap, shmid) = SCARG(uap, shmid);
  593         SCARG(&ap, shmaddr) = (void *)(u_long)SCARG(uap, shmaddr);
  594         SCARG(&ap, shmflg) = SCARG(uap, shmflg);
  595 
  596         return sys_shmat(l, &ap, retval);
  597 }
  598 
  599 struct svr4_32_sys_shmdt_args {
  600         syscallarg(int) what;
  601         syscallarg(netbsd32_voidp) shmaddr;
  602 };
  603 
  604 static int
  605 svr4_32_shmdt(l, v, retval)
  606         struct lwp *l;
  607         void *v;
  608         register_t *retval;
  609 {
  610         struct svr4_32_sys_shmdt_args *uap = v;
  611         struct sys_shmdt_args ap;
  612 
  613         SCARG(&ap, shmaddr) = (void *)(u_long)SCARG(uap, shmaddr);
  614 
  615         return sys_shmdt(l, &ap, retval);
  616 }
  617 
  618 struct svr4_32_sys_shmget_args {
  619         syscallarg(int) what;
  620         syscallarg(netbsd32_key_t) key;
  621         syscallarg(int) size;
  622         syscallarg(int) shmflg;
  623 };
  624 
  625 static int
  626 svr4_32_shmget(l, v, retval)
  627         struct lwp *l;
  628         void *v;
  629         register_t *retval;
  630 {
  631         struct svr4_32_sys_shmget_args *uap = v;
  632         struct sys_shmget_args ap;
  633 
  634         SCARG(&ap, key) = SCARG(uap, key);
  635         SCARG(&ap, size) = SCARG(uap, size);
  636         SCARG(&ap, shmflg) = SCARG(uap, shmflg);
  637 
  638         return sys_shmget(l, &ap, retval);
  639 }
  640 
  641 struct svr4_32_sys_shmctl_args {
  642         syscallarg(int) what;
  643         syscallarg(int) shmid;
  644         syscallarg(int) cmd;
  645         syscallarg(svr4_32_shmid_dsp) buf;
  646 };
  647 
  648 int
  649 svr4_32_shmctl(l, v, retval)
  650         struct lwp *l;
  651         void *v;
  652         register_t *retval;
  653 {
  654         struct svr4_32_sys_shmctl_args *uap = v;
  655         int error;
  656         struct proc *p = l->l_proc;
  657         caddr_t sg = stackgap_init(p, 0);
  658         struct sys___shmctl13_args ap;
  659         struct shmid_ds bs;
  660         struct svr4_32_shmid_ds ss;
  661 
  662         SCARG(&ap, shmid) = SCARG(uap, shmid);
  663 
  664         if (SCARG(uap, buf)) {
  665                 SCARG(&ap, buf) = stackgap_alloc(p, &sg, sizeof (struct shmid_ds));
  666                 switch (SCARG(uap, cmd)) {
  667                 case SVR4_IPC_SET:
  668                 case SVR4_IPC_RMID:
  669                 case SVR4_SHM_LOCK:
  670                 case SVR4_SHM_UNLOCK:
  671                         error = copyin((caddr_t)(u_long)SCARG(uap, buf),
  672                                        (caddr_t)&ss, sizeof ss);
  673                         if (error)
  674                                 return error;
  675                         svr4_32_to_bsd_shmid_ds(&ss, &bs);
  676                         error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
  677                         if (error)
  678                                 return error;
  679                         break;
  680                 default:
  681                         break;
  682                 }
  683         }
  684         else
  685                 SCARG(&ap, buf) = 0;
  686 
  687 
  688         switch (SCARG(uap, cmd)) {
  689         case SVR4_IPC_STAT:
  690                 SCARG(&ap, cmd) = IPC_STAT;
  691                 if ((error = sys___shmctl13(l, &ap, retval)) != 0)
  692                         return error;
  693                 if (!SCARG(uap, buf))
  694                         return 0;
  695                 error = copyin(&bs, SCARG(&ap, buf), sizeof bs);
  696                 if (error)
  697                         return error;
  698                 bsd_to_svr4_32_shmid_ds(&bs, &ss);
  699                 return copyout(&ss, (caddr_t)(u_long)SCARG(uap, buf), sizeof ss);
  700 
  701         case SVR4_IPC_SET:
  702                 SCARG(&ap, cmd) = IPC_SET;
  703                 return sys___shmctl13(l, &ap, retval);
  704 
  705         case SVR4_IPC_RMID:
  706         case SVR4_SHM_LOCK:
  707         case SVR4_SHM_UNLOCK:
  708                 switch (SCARG(uap, cmd)) {
  709                 case SVR4_IPC_RMID:
  710                         SCARG(&ap, cmd) = IPC_RMID;
  711                         break;
  712                 case SVR4_SHM_LOCK:
  713                         SCARG(&ap, cmd) = SHM_LOCK;
  714                         break;
  715                 case SVR4_SHM_UNLOCK:
  716                         SCARG(&ap, cmd) = SHM_UNLOCK;
  717                         break;
  718                 default:
  719                         return EINVAL;
  720                 }
  721                 return sys___shmctl13(l, &ap, retval);
  722 
  723         default:
  724                 return EINVAL;
  725         }
  726 }
  727 
  728 int
  729 svr4_32_sys_shmsys(l, v, retval)
  730         struct lwp *l;
  731         void *v;
  732         register_t *retval;
  733 {
  734         struct svr4_32_sys_shmsys_args *uap = v;
  735 
  736         DPRINTF(("svr4_32_shmsys(%d)\n", SCARG(uap, what)));
  737 
  738         switch (SCARG(uap, what)) {
  739         case SVR4_shmat:
  740                 return svr4_32_shmat(l, v, retval);
  741         case SVR4_shmdt:
  742                 return svr4_32_shmdt(l, v, retval);
  743         case SVR4_shmget:
  744                 return svr4_32_shmget(l, v, retval);
  745         case SVR4_shmctl:
  746                 return svr4_32_shmctl(l, v, retval);
  747         default:
  748                 return ENOSYS;
  749         }
  750 }
  751 #endif /* SYSVSHM */

Cache object: 76f6c7a783b811561529e8d3d1e84920


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