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/svr4_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 /*
    2  * $FreeBSD: releng/5.0/sys/compat/svr4/svr4_ipc.c 108086 2002-12-19 09:40:13Z alfred $
    3  *      Derived from:
    4  *      $NetBSD: svr4_ipc.c,v 1.7 1998/10/19 22:43:00 tron Exp $        */
    5 
    6 /*-
    7  * Original copyright:
    8  *
    9  * Copyright (c) 1995 The NetBSD Foundation, Inc.
   10  * All rights reserved.
   11  *
   12  * This code is derived from software contributed to The NetBSD Foundation
   13  * by Christos Zoulas.
   14  *
   15  * Redistribution and use in source and binary forms, with or without
   16  * modification, are permitted provided that the following conditions
   17  * are met:
   18  * 1. Redistributions of source code must retain the above copyright
   19  *    notice, this list of conditions and the following disclaimer.
   20  * 2. Redistributions in binary form must reproduce the above copyright
   21  *    notice, this list of conditions and the following disclaimer in the
   22  *    documentation and/or other materials provided with the distribution.
   23  * 3. All advertising materials mentioning features or use of this software
   24  *    must display the following acknowledgement:
   25  *        This product includes software developed by the NetBSD
   26  *        Foundation, Inc. and its contributors.
   27  * 4. Neither the name of The NetBSD Foundation nor the names of its
   28  *    contributors may be used to endorse or promote products derived
   29  *    from this software without specific prior written permission.
   30  *
   31  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   32  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   33  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   34  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   35  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   36  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   37  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   39  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   40  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   41  * POSSIBILITY OF SUCH DAMAGE.
   42  */
   43 
   44 /*
   45  * Portions of this code have been derived from software contributed
   46  * to the FreeBSD Project by Mark Newton.
   47  *
   48  * Copyright (c) 1999 Mark Newton
   49  * All rights reserved.
   50  * 
   51  * Redistribution and use in source and binary forms, with or without
   52  * modification, are permitted provided that the following conditions
   53  * are met:
   54  * 1. Redistributions of source code must retain the above copyright
   55  *    notice, this list of conditions and the following disclaimer.
   56  * 2. Redistributions in binary form must reproduce the above copyright
   57  *    notice, this list of conditions and the following disclaimer in the
   58  *    documentation and/or other materials provided with the distribution.
   59  * 3. The name of the author may not be used to endorse or promote products
   60  *    derived from this software without specific prior written permission
   61  *
   62  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   63  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   64  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   65  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   66  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   67  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   68  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   69  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   70  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   71  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   72  *
   73  * XXX- This code is presently a no-op on FreeBSD (and isn't compiled due
   74  * to preprocessor conditionals).  A nice project for a kernel hacking 
   75  * novice might be to MakeItGo, but I have more important fish to fry
   76  * at present.
   77  *
   78  */
   79 
   80 #include <sys/types.h>
   81 #include <sys/param.h>
   82 #include <sys/proc.h>
   83 #include <sys/time.h>
   84 
   85 #include <compat/svr4/svr4.h>
   86 #include <compat/svr4/svr4_types.h>
   87 #include <compat/svr4/svr4_signal.h>
   88 #include <compat/svr4/svr4_proto.h>
   89 #include <compat/svr4/svr4_util.h>
   90 #include <compat/svr4/svr4_ipc.h>
   91 
   92 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
   93 static void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *,
   94                                       struct ipc_perm *);
   95 static void bsd_to_svr4_ipc_perm(const struct ipc_perm *,
   96                                       struct svr4_ipc_perm *);
   97 #endif
   98 
   99 #ifdef SYSVSEM
  100 static void bsd_to_svr4_semid_ds(const struct semid_ds *,
  101                                       struct svr4_semid_ds *);
  102 static void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *,
  103                                       struct semid_ds *);
  104 static int svr4_setsemun(caddr_t *sgp, union semun **argp,
  105                               union semun *usp);
  106 static int svr4_semop(struct proc *, void *, register_t *);
  107 static int svr4_semget(struct proc *, void *, register_t *);
  108 static int svr4_semctl(struct proc *, void *, register_t *);
  109 #endif
  110 
  111 #ifdef SYSVMSG
  112 static void bsd_to_svr4_msqid_ds(const struct msqid_ds *,
  113                                       struct svr4_msqid_ds *);
  114 static void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *,
  115                                       struct msqid_ds *);
  116 static int svr4_msgsnd(struct proc *, void *, register_t *);
  117 static int svr4_msgrcv(struct proc *, void *, register_t *);
  118 static int svr4_msgget(struct proc *, void *, register_t *);
  119 static int svr4_msgctl(struct proc *, void *, register_t *);
  120 #endif
  121 
  122 #ifdef SYSVSHM
  123 static void bsd_to_svr4_shmid_ds(const struct shmid_ds *,
  124                                       struct svr4_shmid_ds *);
  125 static void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *,
  126                                       struct shmid_ds *);
  127 static int svr4_shmat(struct proc *, void *, register_t *);
  128 static int svr4_shmdt(struct proc *, void *, register_t *);
  129 static int svr4_shmget(struct proc *, void *, register_t *);
  130 static int svr4_shmctl(struct proc *, void *, register_t *);
  131 #endif
  132 
  133 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
  134 
  135 static void
  136 svr4_to_bsd_ipc_perm(spp, bpp)
  137         const struct svr4_ipc_perm *spp;
  138         struct ipc_perm *bpp;
  139 {
  140         bpp->key = spp->key;
  141         bpp->uid = spp->uid;
  142         bpp->gid = spp->gid;
  143         bpp->cuid = spp->cuid;
  144         bpp->cgid = spp->cgid;
  145         bpp->mode = spp->mode;
  146         bpp->seq = spp->seq;
  147 }
  148 
  149 static void
  150 bsd_to_svr4_ipc_perm(bpp, spp)
  151         const struct ipc_perm *bpp;
  152         struct svr4_ipc_perm *spp;
  153 {
  154         spp->key = bpp->key;
  155         spp->uid = bpp->uid;
  156         spp->gid = bpp->gid;
  157         spp->cuid = bpp->cuid;
  158         spp->cgid = bpp->cgid;
  159         spp->mode = bpp->mode;
  160         spp->seq = bpp->seq;
  161 }
  162 #endif
  163 
  164 #ifdef SYSVSEM
  165 static void
  166 bsd_to_svr4_semid_ds(bds, sds)
  167         const struct semid_ds *bds;
  168         struct svr4_semid_ds *sds;
  169 {
  170         bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
  171         sds->sem_base = (struct svr4_sem *) bds->sem_base;
  172         sds->sem_nsems = bds->sem_nsems;
  173         sds->sem_otime = bds->sem_otime;
  174         sds->sem_pad1 = bds->sem_pad1;
  175         sds->sem_ctime = bds->sem_ctime;
  176         sds->sem_pad2 = bds->sem_pad2;
  177 }
  178 
  179 static void
  180 svr4_to_bsd_semid_ds(sds, bds)
  181         const struct svr4_semid_ds *sds;
  182         struct semid_ds *bds;
  183 {
  184         svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
  185         bds->sem_base = (struct sem *) bds->sem_base;
  186         bds->sem_nsems = sds->sem_nsems;
  187         bds->sem_otime = sds->sem_otime;
  188         bds->sem_pad1 = sds->sem_pad1;
  189         bds->sem_ctime = sds->sem_ctime;
  190         bds->sem_pad2 = sds->sem_pad2;
  191 }
  192 
  193 static int
  194 svr4_setsemun(sgp, argp, usp)
  195         caddr_t *sgp;
  196         union semun **argp;
  197         union semun *usp;
  198 {
  199         *argp = stackgap_alloc(sgp, sizeof(union semun));
  200         return copyout((caddr_t)usp, *argp, sizeof(union semun));
  201 }
  202 
  203 struct svr4_sys_semctl_args {
  204         syscallarg(int) what;
  205         syscallarg(int) semid;
  206         syscallarg(int) semnum;
  207         syscallarg(int) cmd;
  208         syscallarg(union semun) arg;
  209 };
  210 
  211 static int
  212 svr4_semctl(p, v, retval)
  213         struct proc *p;
  214         void *v;
  215         register_t *retval;
  216 {
  217         int error;
  218         struct svr4_sys_semctl_args *uap = v;
  219         struct sys___semctl_args ap;
  220         struct svr4_semid_ds ss;
  221         struct semid_ds bs, *bsp;
  222         caddr_t sg = stackgap_init();
  223 
  224         ap.semid = uap->semid;
  225         ap.semnum = uap->semnum;
  226 
  227         switch (uap->cmd) {
  228         case SVR4_SEM_GETZCNT:
  229         case SVR4_SEM_GETNCNT:
  230         case SVR4_SEM_GETPID:
  231         case SVR4_SEM_GETVAL:
  232                 switch (uap->cmd) {
  233                 case SVR4_SEM_GETZCNT:
  234                         ap.cmd = GETZCNT;
  235                         break;
  236                 case SVR4_SEM_GETNCNT:
  237                         ap.cmd = GETNCNT;
  238                         break;
  239                 case SVR4_SEM_GETPID:
  240                         ap.cmd = GETPID;
  241                         break;
  242                 case SVR4_SEM_GETVAL:
  243                         ap.cmd = GETVAL;
  244                         break;
  245                 }
  246                 return sys___semctl(p, &ap, retval);
  247 
  248         case SVR4_SEM_SETVAL:
  249                 error = svr4_setsemun(&sg, &ap.arg, &uap->arg);
  250                 if (error)
  251                         return error;
  252                 ap.cmd = SETVAL;
  253                 return sys___semctl(p, &ap, retval);
  254 
  255         case SVR4_SEM_GETALL:
  256                 error = svr4_setsemun(&sg, &ap.arg, &uap->arg);
  257                 if (error)
  258                         return error;
  259                 ap.cmd = GETVAL;
  260                 return sys___semctl(p, &ap, retval);
  261 
  262         case SVR4_SEM_SETALL:
  263                 error = svr4_setsemun(&sg, &ap.arg, &uap->arg);
  264                 if (error)
  265                         return error;
  266                 ap.cmd = SETVAL;
  267                 return sys___semctl(p, &ap, retval);
  268 
  269         case SVR4_IPC_STAT:
  270                 ap.cmd = IPC_STAT;
  271                 bsp = stackgap_alloc(&sg, sizeof(bs));
  272                 error = svr4_setsemun(&sg, &ap.arg,
  273                                       (union semun *)&bsp);
  274                 if (error)
  275                         return error;
  276                 if ((error = sys___semctl(p, &ap, retval)) != 0)
  277                         return error;
  278                 error = copyin((caddr_t)bsp, (caddr_t)&bs, sizeof(bs));
  279                 if (error)
  280                         return error;
  281                 bsd_to_svr4_semid_ds(&bs, &ss);
  282                 return copyout(&ss, uap->arg.buf, sizeof(ss));
  283 
  284         case SVR4_IPC_SET:
  285                 ap.cmd = IPC_SET;
  286                 bsp = stackgap_alloc(&sg, sizeof(bs));
  287                 error = svr4_setsemun(&sg, &ap.arg,
  288                                       (union semun *)&bsp);
  289                 if (error)
  290                         return error;
  291                 error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss);
  292                 if (error)
  293                         return error;
  294                 svr4_to_bsd_semid_ds(&ss, &bs);
  295                 error = copyout(&bs, bsp, sizeof(bs));
  296                 if (error)
  297                         return error;
  298                 return sys___semctl(p, &ap, retval);
  299 
  300         case SVR4_IPC_RMID:
  301                 ap.cmd = IPC_RMID;
  302                 bsp = stackgap_alloc(&sg, sizeof(bs));
  303                 error = svr4_setsemun(&sg, &ap.arg,
  304                                       (union semun *)&bsp);
  305                 if (error)
  306                         return error;
  307                 error = copyin(uap->arg.buf, &ss, sizeof ss);
  308                 if (error)
  309                         return error;
  310                 svr4_to_bsd_semid_ds(&ss, &bs);
  311                 error = copyout(&bs, bsp, sizeof(bs));
  312                 if (error)
  313                         return error;
  314                 return sys___semctl(p, &ap, retval);
  315 
  316         default:
  317                 return EINVAL;
  318         }
  319 }
  320 
  321 struct svr4_sys_semget_args {
  322         syscallarg(int) what;
  323         syscallarg(svr4_key_t) key;
  324         syscallarg(int) nsems;
  325         syscallarg(int) semflg;
  326 };
  327 
  328 static int
  329 svr4_semget(p, v, retval)
  330         struct proc *p;
  331         void *v;
  332         register_t *retval;
  333 {
  334         struct svr4_sys_semget_args *uap = v;
  335         struct sys_semget_args ap;
  336 
  337         ap.key = uap->key;
  338         ap.nsems = uap->nsems;
  339         ap.semflg = uap->semflg;
  340 
  341         return sys_semget(p, &ap, retval);
  342 }
  343 
  344 struct svr4_sys_semop_args {
  345         syscallarg(int) what;
  346         syscallarg(int) semid;
  347         syscallarg(struct svr4_sembuf *) sops;
  348         syscallarg(u_int) nsops;
  349 };
  350 
  351 static int
  352 svr4_semop(p, v, retval)
  353         struct proc *p;
  354         void *v;
  355         register_t *retval;
  356 {
  357         struct svr4_sys_semop_args *uap = v;
  358         struct sys_semop_args ap;
  359 
  360         ap.semid = uap->semid;
  361         /* These are the same */
  362         ap.sops = (struct sembuf *) uap->sops;
  363         ap.nsops = uap->nsops;
  364 
  365         return sys_semop(p, &ap, retval);
  366 }
  367 
  368 int
  369 svr4_sys_semsys(p, v, retval)
  370         struct proc *p;
  371         void *v;
  372         register_t *retval;
  373 {
  374         struct svr4_sys_semsys_args *uap = v;
  375 
  376         DPRINTF(("svr4_semsys(%d)\n", uap->what));
  377 
  378         switch (uap->what) {
  379         case SVR4_semctl:
  380                 return svr4_semctl(p, v, retval);
  381         case SVR4_semget:
  382                 return svr4_semget(p, v, retval);
  383         case SVR4_semop:
  384                 return svr4_semop(p, v, retval);
  385         default:
  386                 return EINVAL;
  387         }
  388 }
  389 #endif
  390 
  391 #ifdef SYSVMSG
  392 static void
  393 bsd_to_svr4_msqid_ds(bds, sds)
  394         const struct msqid_ds *bds;
  395         struct svr4_msqid_ds *sds;
  396 {
  397         bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
  398         sds->msg_first = (struct svr4_msg *) bds->msg_first;
  399         sds->msg_last = (struct svr4_msg *) bds->msg_last;
  400         sds->msg_cbytes = bds->msg_cbytes;
  401         sds->msg_qnum = bds->msg_qnum;
  402         sds->msg_qbytes = bds->msg_qbytes;
  403         sds->msg_lspid = bds->msg_lspid;
  404         sds->msg_lrpid = bds->msg_lrpid;
  405         sds->msg_stime = bds->msg_stime;
  406         sds->msg_pad1 = bds->msg_pad1;
  407         sds->msg_rtime = bds->msg_rtime;
  408         sds->msg_pad2 = bds->msg_pad2;
  409         sds->msg_ctime = bds->msg_ctime;
  410         sds->msg_pad3 = bds->msg_pad3;
  411 
  412         /* use the padding for the rest of the fields */
  413         {
  414                 const short *pad = (const short *) bds->msg_pad4;
  415                 sds->msg_cv = pad[0];
  416                 sds->msg_qnum_cv = pad[1];
  417         }
  418 }
  419 
  420 static void
  421 svr4_to_bsd_msqid_ds(sds, bds)
  422         const struct svr4_msqid_ds *sds;
  423         struct msqid_ds *bds;
  424 {
  425         svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
  426         bds->msg_first = (struct msg *) sds->msg_first;
  427         bds->msg_last = (struct msg *) sds->msg_last;
  428         bds->msg_cbytes = sds->msg_cbytes;
  429         bds->msg_qnum = sds->msg_qnum;
  430         bds->msg_qbytes = sds->msg_qbytes;
  431         bds->msg_lspid = sds->msg_lspid;
  432         bds->msg_lrpid = sds->msg_lrpid;
  433         bds->msg_stime = sds->msg_stime;
  434         bds->msg_pad1 = sds->msg_pad1;
  435         bds->msg_rtime = sds->msg_rtime;
  436         bds->msg_pad2 = sds->msg_pad2;
  437         bds->msg_ctime = sds->msg_ctime;
  438         bds->msg_pad3 = sds->msg_pad3;
  439 
  440         /* use the padding for the rest of the fields */
  441         {
  442                 short *pad = (short *) bds->msg_pad4;
  443                 pad[0] = sds->msg_cv;
  444                 pad[1] = sds->msg_qnum_cv;
  445         }
  446 }
  447 
  448 struct svr4_sys_msgsnd_args {
  449         syscallarg(int) what;
  450         syscallarg(int) msqid;
  451         syscallarg(void *) msgp;
  452         syscallarg(size_t) msgsz;
  453         syscallarg(int) msgflg;
  454 };
  455 
  456 static int
  457 svr4_msgsnd(p, v, retval)
  458         struct proc *p;
  459         void *v;
  460         register_t *retval;
  461 {
  462         struct svr4_sys_msgsnd_args *uap = v;
  463         struct sys_msgsnd_args ap;
  464 
  465         ap.msqid = uap->msqid;
  466         ap.msgp = uap->msgp;
  467         ap.msgsz = uap->msgsz;
  468         ap.msgflg = uap->msgflg;
  469 
  470         return sys_msgsnd(p, &ap, retval);
  471 }
  472 
  473 struct svr4_sys_msgrcv_args {
  474         syscallarg(int) what;
  475         syscallarg(int) msqid;
  476         syscallarg(void *) msgp;
  477         syscallarg(size_t) msgsz;
  478         syscallarg(long) msgtyp;
  479         syscallarg(int) msgflg;
  480 };
  481 
  482 static int
  483 svr4_msgrcv(p, v, retval)
  484         struct proc *p;
  485         void *v;
  486         register_t *retval;
  487 {
  488         struct svr4_sys_msgrcv_args *uap = v;
  489         struct sys_msgrcv_args ap;
  490 
  491         ap.msqid = uap->msqid;
  492         ap.msgp = uap->msgp;
  493         ap.msgsz = uap->msgsz;
  494         ap.msgtyp = uap->msgtyp;
  495         ap.msgflg = uap->msgflg;
  496 
  497         return sys_msgrcv(p, &ap, retval);
  498 }
  499         
  500 struct svr4_sys_msgget_args {
  501         syscallarg(int) what;
  502         syscallarg(svr4_key_t) key;
  503         syscallarg(int) msgflg;
  504 };
  505 
  506 static int
  507 svr4_msgget(p, v, retval)
  508         struct proc *p;
  509         void *v;
  510         register_t *retval;
  511 {
  512         struct svr4_sys_msgget_args *uap = v;
  513         struct sys_msgget_args ap;
  514 
  515         ap.key = uap->key;
  516         ap.msgflg = uap->msgflg;
  517 
  518         return sys_msgget(p, &ap, retval);
  519 }
  520 
  521 struct svr4_sys_msgctl_args {
  522         syscallarg(int) what;
  523         syscallarg(int) msqid;
  524         syscallarg(int) cmd;
  525         syscallarg(struct svr4_msqid_ds *) buf;
  526 };
  527 
  528 static int
  529 svr4_msgctl(p, v, retval)
  530         struct proc *p;
  531         void *v;
  532         register_t *retval;
  533 {
  534         int error;
  535         struct svr4_sys_msgctl_args *uap = v;
  536         struct sys_msgctl_args ap;
  537         struct svr4_msqid_ds ss;
  538         struct msqid_ds bs;
  539         caddr_t sg = stackgap_init();
  540 
  541         ap.msqid = uap->msqid;
  542         ap.cmd = uap->cmd;
  543         ap.buf = stackgap_alloc(&sg, sizeof(bs));
  544 
  545         switch (uap->cmd) {
  546         case SVR4_IPC_STAT:
  547                 ap.cmd = IPC_STAT;
  548                 if ((error = sys_msgctl(p, &ap, retval)) != 0)
  549                         return error;
  550                 error = copyin(&bs, ap.buf, sizeof bs);
  551                 if (error)
  552                         return error;
  553                 bsd_to_svr4_msqid_ds(&bs, &ss);
  554                 return copyout(&ss, uap->buf, sizeof ss);
  555 
  556         case SVR4_IPC_SET:
  557                 ap.cmd = IPC_SET;
  558                 error = copyin(uap->buf, &ss, sizeof ss);
  559                 if (error)
  560                         return error;
  561                 svr4_to_bsd_msqid_ds(&ss, &bs);
  562                 error = copyout(&bs, ap.buf, sizeof bs);
  563                 if (error)
  564                         return error;
  565                 return sys_msgctl(p, &ap, retval);
  566 
  567         case SVR4_IPC_RMID:
  568                 ap.cmd = IPC_RMID;
  569                 error = copyin(uap->buf, &ss, sizeof ss);
  570                 if (error)
  571                         return error;
  572                 svr4_to_bsd_msqid_ds(&ss, &bs);
  573                 error = copyout(&bs, ap.buf, sizeof bs);
  574                 if (error)
  575                         return error;
  576                 return sys_msgctl(p, &ap, retval);
  577 
  578         default:
  579                 return EINVAL;
  580         }
  581 }
  582 
  583 int
  584 svr4_sys_msgsys(p, v, retval)
  585         struct proc *p;
  586         void *v;
  587         register_t *retval;
  588 {
  589         struct svr4_sys_msgsys_args *uap = v;
  590 
  591         DPRINTF(("svr4_msgsys(%d)\n", uap->what));
  592 
  593         switch (uap->what) {
  594         case SVR4_msgsnd:
  595                 return svr4_msgsnd(p, v, retval);
  596         case SVR4_msgrcv:
  597                 return svr4_msgrcv(p, v, retval);
  598         case SVR4_msgget:
  599                 return svr4_msgget(p, v, retval);
  600         case SVR4_msgctl:
  601                 return svr4_msgctl(p, v, retval);
  602         default:
  603                 return EINVAL;
  604         }
  605 }
  606 #endif
  607 
  608 #ifdef SYSVSHM
  609 
  610 static void
  611 bsd_to_svr4_shmid_ds(bds, sds)
  612         const struct shmid_ds *bds;
  613         struct svr4_shmid_ds *sds;
  614 {
  615         bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
  616         sds->shm_segsz = bds->shm_segsz;
  617         sds->shm_lkcnt = 0;
  618         sds->shm_lpid = bds->shm_lpid;
  619         sds->shm_cpid = bds->shm_cpid;
  620         sds->shm_amp = bds->shm_internal;
  621         sds->shm_nattch = bds->shm_nattch;
  622         sds->shm_cnattch = 0;
  623         sds->shm_atime = bds->shm_atime;
  624         sds->shm_pad1 = 0;
  625         sds->shm_dtime = bds->shm_dtime;
  626         sds->shm_pad2 = 0;
  627         sds->shm_ctime = bds->shm_ctime;
  628         sds->shm_pad3 = 0;
  629 }
  630 
  631 static void
  632 svr4_to_bsd_shmid_ds(sds, bds)
  633         const struct svr4_shmid_ds *sds;
  634         struct shmid_ds *bds;
  635 {
  636         svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
  637         bds->shm_segsz = sds->shm_segsz;
  638         bds->shm_lpid = sds->shm_lpid;
  639         bds->shm_cpid = sds->shm_cpid;
  640         bds->shm_internal = sds->shm_amp;
  641         bds->shm_nattch = sds->shm_nattch;
  642         bds->shm_atime = sds->shm_atime;
  643         bds->shm_dtime = sds->shm_dtime;
  644         bds->shm_ctime = sds->shm_ctime;
  645 }
  646 
  647 struct svr4_sys_shmat_args {
  648         syscallarg(int) what;
  649         syscallarg(int) shmid;
  650         syscallarg(void *) shmaddr;
  651         syscallarg(int) shmflg;
  652 };
  653 
  654 static int
  655 svr4_shmat(p, v, retval)
  656         struct proc *p;
  657         void *v;
  658         register_t *retval;
  659 {
  660         struct svr4_sys_shmat_args *uap = v;
  661         struct sys_shmat_args ap;
  662 
  663         ap.shmid = uap->shmid;
  664         ap.shmaddr = uap->shmaddr;
  665         ap.shmflg = uap->shmflg;
  666 
  667         return sys_shmat(p, &ap, retval);
  668 }
  669 
  670 struct svr4_sys_shmdt_args {
  671         syscallarg(int) what;
  672         syscallarg(void *) shmaddr;
  673 };
  674 
  675 static int
  676 svr4_shmdt(p, v, retval)
  677         struct proc *p;
  678         void *v;
  679         register_t *retval;
  680 {
  681         struct svr4_sys_shmdt_args *uap = v;
  682         struct sys_shmdt_args ap;
  683 
  684         ap.shmaddr = uap->shmaddr;
  685 
  686         return sys_shmdt(p, &ap, retval);
  687 }
  688 
  689 struct svr4_sys_shmget_args {
  690         syscallarg(int) what;
  691         syscallarg(key_t) key;
  692         syscallarg(int) size;
  693         syscallarg(int) shmflg;
  694 };
  695 
  696 static int
  697 svr4_shmget(p, v, retval)
  698         struct proc *p;
  699         void *v;
  700         register_t *retval;
  701 {
  702         struct svr4_sys_shmget_args *uap = v;
  703         struct sys_shmget_args ap;
  704 
  705         ap.key = uap->key;
  706         ap.size = uap->size;
  707         ap.shmflg = uap->shmflg;
  708 
  709         return sys_shmget(p, &ap, retval);
  710 }
  711 
  712 struct svr4_sys_shmctl_args {
  713         syscallarg(int) what;
  714         syscallarg(int) shmid;
  715         syscallarg(int) cmd;
  716         syscallarg(struct svr4_shmid_ds *) buf;
  717 };
  718 
  719 int
  720 svr4_shmctl(p, v, retval)
  721         struct proc *p;
  722         void *v;
  723         register_t *retval;
  724 {
  725         struct svr4_sys_shmctl_args *uap = v;
  726         int error;
  727         caddr_t sg = stackgap_init();
  728         struct sys_shmctl_args ap;
  729         struct shmid_ds bs;
  730         struct svr4_shmid_ds ss;
  731 
  732         ap.shmid = uap->shmid;
  733 
  734         if (uap->buf != NULL) {
  735                 ap.buf = stackgap_alloc(&sg, sizeof (struct shmid_ds));
  736                 switch (uap->cmd) {
  737                 case SVR4_IPC_SET:
  738                 case SVR4_IPC_RMID:
  739                 case SVR4_SHM_LOCK:
  740                 case SVR4_SHM_UNLOCK:
  741                         error = copyin(uap->buf, (caddr_t) &ss,
  742                             sizeof ss);
  743                         if (error)
  744                                 return error;
  745                         svr4_to_bsd_shmid_ds(&ss, &bs);
  746                         error = copyout(&bs, ap.buf, sizeof bs);
  747                         if (error)
  748                                 return error;
  749                         break;
  750                 default:
  751                         break;
  752                 }
  753         }
  754         else
  755                 ap.buf = NULL;
  756 
  757 
  758         switch (uap->cmd) {
  759         case SVR4_IPC_STAT:
  760                 ap.cmd = IPC_STAT;
  761                 if ((error = sys_shmctl(p, &ap, retval)) != 0)
  762                         return error;
  763                 if (uap->buf == NULL)
  764                         return 0;
  765                 error = copyin(&bs, ap.buf, sizeof bs);
  766                 if (error)
  767                         return error;
  768                 bsd_to_svr4_shmid_ds(&bs, &ss);
  769                 return copyout(&ss, uap->buf, sizeof ss);
  770 
  771         case SVR4_IPC_SET:
  772                 ap.cmd = IPC_SET;
  773                 return sys_shmctl(p, &ap, retval);
  774 
  775         case SVR4_IPC_RMID:
  776         case SVR4_SHM_LOCK:
  777         case SVR4_SHM_UNLOCK:
  778                 switch (uap->cmd) {
  779                 case SVR4_IPC_RMID:
  780                         ap.cmd = IPC_RMID;
  781                         break;
  782                 case SVR4_SHM_LOCK:
  783                         ap.cmd = SHM_LOCK;
  784                         break;
  785                 case SVR4_SHM_UNLOCK:
  786                         ap.cmd = SHM_UNLOCK;
  787                         break;
  788                 default:
  789                         return EINVAL;
  790                 }
  791                 return sys_shmctl(p, &ap, retval);
  792 
  793         default:
  794                 return EINVAL;
  795         }
  796 }
  797 
  798 int
  799 svr4_sys_shmsys(p, v, retval)
  800         struct proc *p;
  801         void *v;
  802         register_t *retval;
  803 {
  804         struct svr4_sys_shmsys_args *uap = v;
  805 
  806         DPRINTF(("svr4_shmsys(%d)\n", uap->what));
  807 
  808         switch (uap->what) {
  809         case SVR4_shmat:
  810                 return svr4_shmat(p, v, retval);
  811         case SVR4_shmdt:
  812                 return svr4_shmdt(p, v, retval);
  813         case SVR4_shmget:
  814                 return svr4_shmget(p, v, retval);
  815         case SVR4_shmctl:
  816                 return svr4_shmctl(p, v, retval);
  817         default:
  818                 return ENOSYS;
  819         }
  820 }
  821 #endif /* SYSVSHM */

Cache object: b17fd04ff88d8385f38f1603dcc1f8ea


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