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.7 2003/10/21 09:02:50 petrov 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.7 2003/10/21 09:02:50 petrov 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 proc *p = l->l_proc;
  182         struct semid_ds sembuf;
  183         struct svr4_32_semid_ds ssembuf;
  184         int cmd, error;
  185         void *pass_arg = NULL;
  186 
  187         cmd = SCARG(uap, cmd);
  188 
  189         switch (cmd) {
  190         case SVR4_IPC_SET:
  191                 pass_arg = &sembuf;
  192                 cmd = IPC_SET;
  193                 break;
  194 
  195         case SVR4_IPC_STAT:
  196                 pass_arg = &sembuf;
  197                 cmd = IPC_STAT;
  198                 break;
  199 
  200         case SVR4_IPC_RMID:
  201                 cmd = IPC_RMID;
  202                 break;
  203 
  204         case SVR4_SEM_GETVAL:
  205                 cmd = GETVAL;
  206                 break;
  207 
  208         case SVR4_SEM_GETPID:
  209                 cmd = GETPID;
  210                 break;
  211 
  212         case SVR4_SEM_GETNCNT:
  213                 cmd = GETNCNT;
  214                 break;
  215 
  216         case SVR4_SEM_GETZCNT:
  217                 cmd = GETZCNT;
  218                 break;
  219 
  220         case SVR4_SEM_GETALL:
  221                 pass_arg = &SCARG(uap, arg);
  222                 cmd = GETALL;
  223                 break;
  224 
  225         case SVR4_SEM_SETVAL:
  226                 pass_arg = &SCARG(uap, arg);
  227                 cmd = SETVAL;
  228                 break;
  229 
  230         case SVR4_SEM_SETALL:
  231                 pass_arg = &SCARG(uap, arg);
  232                 cmd = SETALL;
  233                 break;
  234 
  235         default:
  236                 return (EINVAL);
  237         }
  238 
  239         if (cmd == IPC_SET) {
  240                 error = copyin((caddr_t)(u_long)SCARG(uap, arg).buf, 
  241                                &ssembuf, sizeof(ssembuf));
  242                 if (error)
  243                         return (error);
  244                 svr4_32_to_bsd_semid_ds(&ssembuf, &sembuf);
  245         }
  246 
  247         error = semctl1(p, SCARG(uap, semid), SCARG(uap, semnum), cmd,
  248             pass_arg, retval);
  249 
  250         if (error == 0 && cmd == IPC_STAT) {
  251                 bsd_to_svr4_32_semid_ds(&sembuf, &ssembuf);
  252                 error = copyout(&ssembuf, (caddr_t)(u_long)SCARG(uap, arg).buf, 
  253                                 sizeof(ssembuf));
  254         }
  255 
  256         return (error);
  257 }
  258 
  259 struct svr4_32_sys_semget_args {
  260         syscallarg(int) what;
  261         syscallarg(svr4_key_t) key;
  262         syscallarg(int) nsems;
  263         syscallarg(int) semflg;
  264 };
  265 
  266 static int
  267 svr4_32_semget(l, v, retval)
  268         struct lwp *l;
  269         void *v;
  270         register_t *retval;
  271 {
  272         struct svr4_32_sys_semget_args *uap = v;
  273         struct sys_semget_args ap;
  274 
  275         SCARG(&ap, key) = SCARG(uap, key);
  276         SCARG(&ap, nsems) = SCARG(uap, nsems);
  277         SCARG(&ap, semflg) = SCARG(uap, semflg);
  278 
  279         return sys_semget(l, &ap, retval);
  280 }
  281 
  282 struct svr4_32_sys_semop_args {
  283         syscallarg(int) what;
  284         syscallarg(int) semid;
  285         syscallarg(svr4_32_sembufp) sops;
  286         syscallarg(u_int) nsops;
  287 };
  288 
  289 static int
  290 svr4_32_semop(l, v, retval)
  291         struct lwp *l;
  292         void *v;
  293         register_t *retval;
  294 {
  295         struct svr4_32_sys_semop_args *uap = v;
  296         struct sys_semop_args ap;
  297 
  298         SCARG(&ap, semid) = SCARG(uap, semid);
  299         /* These are the same */
  300         SCARG(&ap, sops) = (struct sembuf *)(u_long)SCARG(uap, sops);
  301         SCARG(&ap, nsops) = SCARG(uap, nsops);
  302 
  303         return sys_semop(l, &ap, retval);
  304 }
  305 
  306 int
  307 svr4_32_sys_semsys(l, v, retval)
  308         struct lwp *l;
  309         void *v;
  310         register_t *retval;
  311 {
  312         struct svr4_32_sys_semsys_args *uap = v;
  313 
  314         DPRINTF(("svr4_32_semsys(%d)\n", SCARG(uap, what)));
  315 
  316         switch (SCARG(uap, what)) {
  317         case SVR4_semctl:
  318                 return svr4_32_semctl(l, v, retval);
  319         case SVR4_semget:
  320                 return svr4_32_semget(l, v, retval);
  321         case SVR4_semop:
  322                 return svr4_32_semop(l, v, retval);
  323         default:
  324                 return EINVAL;
  325         }
  326 }
  327 #endif
  328 
  329 #ifdef SYSVMSG
  330 static void
  331 bsd_to_svr4_32_msqid_ds(bds, sds)
  332         const struct msqid_ds *bds;
  333         struct svr4_32_msqid_ds *sds;
  334 {
  335         bsd_to_svr4_32_ipc_perm(&bds->msg_perm, &sds->msg_perm);
  336         sds->msg_first = (svr4_32_msgp)(u_long)bds->_msg_first;
  337         sds->msg_last = (svr4_32_msgp)(u_long)bds->_msg_last;
  338         sds->msg_cbytes = bds->_msg_cbytes;
  339         sds->msg_qnum = bds->msg_qnum;
  340         sds->msg_qbytes = bds->msg_qbytes;
  341         sds->msg_lspid = bds->msg_lspid;
  342         sds->msg_lrpid = bds->msg_lrpid;
  343         sds->msg_stime = bds->msg_stime;
  344         sds->msg_rtime = bds->msg_rtime;
  345         sds->msg_ctime = bds->msg_ctime;
  346 
  347 #if 0
  348         /* XXX What to put here? */
  349         sds->msg_cv = 0;
  350         sds->msg_qnum_cv = 0;
  351 #endif
  352 }
  353 
  354 static void
  355 svr4_32_to_bsd_msqid_ds(sds, bds)
  356         const struct svr4_32_msqid_ds *sds;
  357         struct msqid_ds *bds;
  358 {
  359         svr4_32_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
  360         bds->_msg_first = (struct __msg *)(u_long)sds->msg_first;
  361         bds->_msg_last = (struct __msg *)(u_long)sds->msg_last;
  362         bds->_msg_cbytes = sds->msg_cbytes;
  363         bds->msg_qnum = sds->msg_qnum;
  364         bds->msg_qbytes = sds->msg_qbytes;
  365         bds->msg_lspid = sds->msg_lspid;
  366         bds->msg_lrpid = sds->msg_lrpid;
  367         bds->msg_stime = sds->msg_stime;
  368         bds->msg_rtime = sds->msg_rtime;
  369         bds->msg_ctime = sds->msg_ctime;
  370 
  371 #if 0
  372         XXX sds->msg_cv
  373         XXX sds->msg_qnum_cv
  374 #endif
  375 }
  376 
  377 struct svr4_32_sys_msgsnd_args {
  378         syscallarg(int) what;
  379         syscallarg(int) msqid;
  380         syscallarg(netbsd32_voidp) msgp;
  381         syscallarg(netbsd32_size_t) msgsz;
  382         syscallarg(int) msgflg;
  383 };
  384 
  385 static int
  386 svr4_32_msgsnd(l, v, retval)
  387         struct lwp *l;
  388         void *v;
  389         register_t *retval;
  390 {
  391         struct svr4_32_sys_msgsnd_args *uap = v;
  392         struct sys_msgsnd_args ap;
  393 
  394         SCARG(&ap, msqid) = SCARG(uap, msqid);
  395         SCARG(&ap, msgp) = (void *)(u_long)SCARG(uap, msgp);
  396         SCARG(&ap, msgsz) = SCARG(uap, msgsz);
  397         SCARG(&ap, msgflg) = SCARG(uap, msgflg);
  398 
  399         return sys_msgsnd(l, &ap, retval);
  400 }
  401 
  402 struct svr4_32_sys_msgrcv_args {
  403         syscallarg(int) what;
  404         syscallarg(int) msqid;
  405         syscallarg(netbsd32_voidp) msgp;
  406         syscallarg(netbsd32_size_t) msgsz;
  407         syscallarg(netbsd32_long) msgtyp;
  408         syscallarg(int) msgflg;
  409 };
  410 
  411 static int
  412 svr4_32_msgrcv(l, v, retval)
  413         struct lwp *l;
  414         void *v;
  415         register_t *retval;
  416 {
  417         struct svr4_32_sys_msgrcv_args *uap = v;
  418         struct sys_msgrcv_args ap;
  419 
  420         SCARG(&ap, msqid) = SCARG(uap, msqid);
  421         SCARG(&ap, msgp) = (void *)(u_long)SCARG(uap, msgp);
  422         SCARG(&ap, msgsz) = SCARG(uap, msgsz);
  423         SCARG(&ap, msgtyp) = SCARG(uap, msgtyp);
  424         SCARG(&ap, msgflg) = SCARG(uap, msgflg);
  425 
  426         return sys_msgrcv(l, &ap, retval);
  427 }
  428         
  429 struct svr4_32_sys_msgget_args {
  430         syscallarg(int) what;
  431         syscallarg(svr4_key_t) key;
  432         syscallarg(int) msgflg;
  433 };
  434 
  435 static int
  436 svr4_32_msgget(l, v, retval)
  437         struct lwp *l;
  438         void *v;
  439         register_t *retval;
  440 {
  441         struct svr4_32_sys_msgget_args *uap = v;
  442         struct sys_msgget_args ap;
  443 
  444         SCARG(&ap, key) = SCARG(uap, key);
  445         SCARG(&ap, msgflg) = SCARG(uap, msgflg);
  446 
  447         return sys_msgget(l, &ap, retval);
  448 }
  449 
  450 struct svr4_32_sys_msgctl_args {
  451         syscallarg(int) what;
  452         syscallarg(int) msqid;
  453         syscallarg(int) cmd;
  454         syscallarg(svr4_32_msqid_dsp) buf;
  455 };
  456 
  457 static int
  458 svr4_32_msgctl(l, v, retval)
  459         struct lwp *l;
  460         void *v;
  461         register_t *retval;
  462 {
  463         int error;
  464         struct svr4_32_sys_msgctl_args *uap = v;
  465         struct proc *p = l->l_proc;
  466         struct sys___msgctl13_args ap;
  467         struct svr4_32_msqid_ds ss;
  468         struct msqid_ds bs;
  469         caddr_t sg = stackgap_init(p, 0);
  470 
  471         SCARG(&ap, msqid) = SCARG(uap, msqid);
  472         SCARG(&ap, cmd) = SCARG(uap, cmd);
  473         SCARG(&ap, buf) = stackgap_alloc(p, &sg, sizeof(bs));
  474 
  475         switch (SCARG(uap, cmd)) {
  476         case SVR4_IPC_STAT:
  477                 SCARG(&ap, cmd) = IPC_STAT;
  478                 if ((error = sys___msgctl13(l, &ap, retval)) != 0)
  479                         return error;
  480                 error = copyin(&bs, SCARG(&ap, buf), sizeof bs);
  481                 if (error)
  482                         return error;
  483                 bsd_to_svr4_32_msqid_ds(&bs, &ss);
  484                 return copyout(&ss, (caddr_t)(u_long)SCARG(uap, buf), sizeof ss);
  485 
  486         case SVR4_IPC_SET:
  487                 SCARG(&ap, cmd) = IPC_SET;
  488                 error = copyin((caddr_t)(u_long)SCARG(uap, buf), &ss, sizeof ss);
  489                 if (error)
  490                         return error;
  491                 svr4_32_to_bsd_msqid_ds(&ss, &bs);
  492                 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
  493                 if (error)
  494                         return error;
  495                 return sys___msgctl13(l, &ap, retval);
  496 
  497         case SVR4_IPC_RMID:
  498                 SCARG(&ap, cmd) = IPC_RMID;
  499                 error = copyin((caddr_t)(u_long)SCARG(uap, buf), &ss, sizeof ss);
  500                 if (error)
  501                         return error;
  502                 svr4_32_to_bsd_msqid_ds(&ss, &bs);
  503                 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
  504                 if (error)
  505                         return error;
  506                 return sys___msgctl13(l, &ap, retval);
  507 
  508         default:
  509                 return EINVAL;
  510         }
  511 }
  512 
  513 int
  514 svr4_32_sys_msgsys(l, v, retval)
  515         struct lwp *l;
  516         void *v;
  517         register_t *retval;
  518 {
  519         struct svr4_32_sys_msgsys_args *uap = v;
  520 
  521         DPRINTF(("svr4_32_msgsys(%d)\n", SCARG(uap, what)));
  522 
  523         switch (SCARG(uap, what)) {
  524         case SVR4_msgsnd:
  525                 return svr4_32_msgsnd(l, v, retval);
  526         case SVR4_msgrcv:
  527                 return svr4_32_msgrcv(l, v, retval);
  528         case SVR4_msgget:
  529                 return svr4_32_msgget(l, v, retval);
  530         case SVR4_msgctl:
  531                 return svr4_32_msgctl(l, v, retval);
  532         default:
  533                 return EINVAL;
  534         }
  535 }
  536 #endif
  537 
  538 #ifdef SYSVSHM
  539 
  540 static void
  541 bsd_to_svr4_32_shmid_ds(bds, sds)
  542         const struct shmid_ds *bds;
  543         struct svr4_32_shmid_ds *sds;
  544 {
  545         bsd_to_svr4_32_ipc_perm(&bds->shm_perm, &sds->shm_perm);
  546         sds->shm_segsz = bds->shm_segsz;
  547         sds->shm_lkcnt = 0;
  548         sds->shm_lpid = bds->shm_lpid;
  549         sds->shm_cpid = bds->shm_cpid;
  550         sds->shm_amp = (netbsd32_caddr_t)(u_long)bds->_shm_internal;
  551         sds->shm_nattch = bds->shm_nattch;
  552         sds->shm_cnattch = 0;
  553         sds->shm_atime = bds->shm_atime;
  554         sds->shm_pad1 = 0;
  555         sds->shm_dtime = bds->shm_dtime;
  556         sds->shm_pad2 = 0;
  557         sds->shm_ctime = bds->shm_ctime;
  558         sds->shm_pad3 = 0;
  559 }
  560 
  561 static void
  562 svr4_32_to_bsd_shmid_ds(sds, bds)
  563         const struct svr4_32_shmid_ds *sds;
  564         struct shmid_ds *bds;
  565 {
  566         svr4_32_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
  567         bds->shm_segsz = sds->shm_segsz;
  568         bds->shm_lpid = sds->shm_lpid;
  569         bds->shm_cpid = sds->shm_cpid;
  570         bds->_shm_internal = (void *)(u_long)sds->shm_amp;
  571         bds->shm_nattch = sds->shm_nattch;
  572         bds->shm_atime = sds->shm_atime;
  573         bds->shm_dtime = sds->shm_dtime;
  574         bds->shm_ctime = sds->shm_ctime;
  575 }
  576 
  577 struct svr4_32_sys_shmat_args {
  578         syscallarg(int) what;
  579         syscallarg(int) shmid;
  580         syscallarg(netbsd32_voidp) shmaddr;
  581         syscallarg(int) shmflg;
  582 };
  583 
  584 static int
  585 svr4_32_shmat(l, v, retval)
  586         struct lwp *l;
  587         void *v;
  588         register_t *retval;
  589 {
  590         struct svr4_32_sys_shmat_args *uap = v;
  591         struct sys_shmat_args ap;
  592 
  593         SCARG(&ap, shmid) = SCARG(uap, shmid);
  594         SCARG(&ap, shmaddr) = (void *)(u_long)SCARG(uap, shmaddr);
  595         SCARG(&ap, shmflg) = SCARG(uap, shmflg);
  596 
  597         return sys_shmat(l, &ap, retval);
  598 }
  599 
  600 struct svr4_32_sys_shmdt_args {
  601         syscallarg(int) what;
  602         syscallarg(netbsd32_voidp) shmaddr;
  603 };
  604 
  605 static int
  606 svr4_32_shmdt(l, v, retval)
  607         struct lwp *l;
  608         void *v;
  609         register_t *retval;
  610 {
  611         struct svr4_32_sys_shmdt_args *uap = v;
  612         struct sys_shmdt_args ap;
  613 
  614         SCARG(&ap, shmaddr) = (void *)(u_long)SCARG(uap, shmaddr);
  615 
  616         return sys_shmdt(l, &ap, retval);
  617 }
  618 
  619 struct svr4_32_sys_shmget_args {
  620         syscallarg(int) what;
  621         syscallarg(netbsd32_key_t) key;
  622         syscallarg(int) size;
  623         syscallarg(int) shmflg;
  624 };
  625 
  626 static int
  627 svr4_32_shmget(l, v, retval)
  628         struct lwp *l;
  629         void *v;
  630         register_t *retval;
  631 {
  632         struct svr4_32_sys_shmget_args *uap = v;
  633         struct sys_shmget_args ap;
  634 
  635         SCARG(&ap, key) = SCARG(uap, key);
  636         SCARG(&ap, size) = SCARG(uap, size);
  637         SCARG(&ap, shmflg) = SCARG(uap, shmflg);
  638 
  639         return sys_shmget(l, &ap, retval);
  640 }
  641 
  642 struct svr4_32_sys_shmctl_args {
  643         syscallarg(int) what;
  644         syscallarg(int) shmid;
  645         syscallarg(int) cmd;
  646         syscallarg(svr4_32_shmid_dsp) buf;
  647 };
  648 
  649 int
  650 svr4_32_shmctl(l, v, retval)
  651         struct lwp *l;
  652         void *v;
  653         register_t *retval;
  654 {
  655         struct svr4_32_sys_shmctl_args *uap = v;
  656         int error;
  657         struct proc *p = l->l_proc;
  658         caddr_t sg = stackgap_init(p, 0);
  659         struct sys___shmctl13_args ap;
  660         struct shmid_ds bs;
  661         struct svr4_32_shmid_ds ss;
  662 
  663         SCARG(&ap, shmid) = SCARG(uap, shmid);
  664 
  665         if (SCARG(uap, buf)) {
  666                 SCARG(&ap, buf) = stackgap_alloc(p, &sg, sizeof (struct shmid_ds));
  667                 switch (SCARG(uap, cmd)) {
  668                 case SVR4_IPC_SET:
  669                 case SVR4_IPC_RMID:
  670                 case SVR4_SHM_LOCK:
  671                 case SVR4_SHM_UNLOCK:
  672                         error = copyin((caddr_t)(u_long)SCARG(uap, buf), 
  673                                        (caddr_t)&ss, sizeof ss);
  674                         if (error)
  675                                 return error;
  676                         svr4_32_to_bsd_shmid_ds(&ss, &bs);
  677                         error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
  678                         if (error)
  679                                 return error;
  680                         break;
  681                 default:
  682                         break;
  683                 }
  684         }
  685         else
  686                 SCARG(&ap, buf) = 0;
  687 
  688 
  689         switch (SCARG(uap, cmd)) {
  690         case SVR4_IPC_STAT:
  691                 SCARG(&ap, cmd) = IPC_STAT;
  692                 if ((error = sys___shmctl13(l, &ap, retval)) != 0)
  693                         return error;
  694                 if (!SCARG(uap, buf))
  695                         return 0;
  696                 error = copyin(&bs, SCARG(&ap, buf), sizeof bs);
  697                 if (error)
  698                         return error;
  699                 bsd_to_svr4_32_shmid_ds(&bs, &ss);
  700                 return copyout(&ss, (caddr_t)(u_long)SCARG(uap, buf), sizeof ss);
  701 
  702         case SVR4_IPC_SET:
  703                 SCARG(&ap, cmd) = IPC_SET;
  704                 return sys___shmctl13(l, &ap, retval);
  705 
  706         case SVR4_IPC_RMID:
  707         case SVR4_SHM_LOCK:
  708         case SVR4_SHM_UNLOCK:
  709                 switch (SCARG(uap, cmd)) {
  710                 case SVR4_IPC_RMID:
  711                         SCARG(&ap, cmd) = IPC_RMID;
  712                         break;
  713                 case SVR4_SHM_LOCK:
  714                         SCARG(&ap, cmd) = SHM_LOCK;
  715                         break;
  716                 case SVR4_SHM_UNLOCK:
  717                         SCARG(&ap, cmd) = SHM_UNLOCK;
  718                         break;
  719                 default:
  720                         return EINVAL;
  721                 }
  722                 return sys___shmctl13(l, &ap, retval);
  723 
  724         default:
  725                 return EINVAL;
  726         }
  727 }
  728 
  729 int
  730 svr4_32_sys_shmsys(l, v, retval)
  731         struct lwp *l;
  732         void *v;
  733         register_t *retval;
  734 {
  735         struct svr4_32_sys_shmsys_args *uap = v;
  736 
  737         DPRINTF(("svr4_32_shmsys(%d)\n", SCARG(uap, what)));
  738 
  739         switch (SCARG(uap, what)) {
  740         case SVR4_shmat:
  741                 return svr4_32_shmat(l, v, retval);
  742         case SVR4_shmdt:
  743                 return svr4_32_shmdt(l, v, retval);
  744         case SVR4_shmget:
  745                 return svr4_32_shmget(l, v, retval);
  746         case SVR4_shmctl:
  747                 return svr4_32_shmctl(l, v, retval);
  748         default:
  749                 return ENOSYS;
  750         }
  751 }
  752 #endif /* SYSVSHM */

Cache object: 5e3df64e74aa5a7e3fd1cbd9900171cc


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