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/i386/ibcs2/ibcs2_ipc.c

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

    1 /*-
    2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 1995 Scott Bartram
    5  * Copyright (c) 1995 Steven Wallace
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. The name of the author may not be used to endorse or promote products
   14  *    derived from this software without specific prior written permission
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: stable/12/sys/i386/ibcs2/ibcs2_ipc.c 331327 2018-03-21 23:17:26Z emaste $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/limits.h>
   34 #include <sys/msg.h>
   35 #include <sys/sem.h>
   36 #include <sys/shm.h>
   37 #include <sys/syscallsubr.h>
   38 #include <sys/sysproto.h>
   39 
   40 #include <i386/ibcs2/ibcs2_types.h>
   41 #include <i386/ibcs2/ibcs2_signal.h>
   42 #include <i386/ibcs2/ibcs2_proto.h>
   43 #include <i386/ibcs2/ibcs2_util.h>
   44 #include <i386/ibcs2/ibcs2_ipc.h>
   45 
   46 #define IBCS2_IPC_RMID  0
   47 #define IBCS2_IPC_SET   1
   48 #define IBCS2_IPC_STAT  2
   49 #define IBCS2_SETVAL    8
   50 
   51 
   52 
   53 static void cvt_msqid2imsqid(struct msqid_ds *, struct ibcs2_msqid_ds *);
   54 static void cvt_imsqid2msqid(struct ibcs2_msqid_ds *, struct msqid_ds *);
   55 #ifdef unused
   56 static void cvt_sem2isem(struct sem *, struct ibcs2_sem *);
   57 static void cvt_isem2sem(struct ibcs2_sem *, struct sem *);
   58 #endif
   59 static void cvt_semid2isemid(struct semid_ds *, struct ibcs2_semid_ds *);
   60 static void cvt_isemid2semid(struct ibcs2_semid_ds *, struct semid_ds *);
   61 static void cvt_shmid2ishmid(struct shmid_ds *, struct ibcs2_shmid_ds *);
   62 static void cvt_ishmid2shmid(struct ibcs2_shmid_ds *, struct shmid_ds *);
   63 static void cvt_perm2iperm(struct ipc_perm *, struct ibcs2_ipc_perm *);
   64 static void cvt_iperm2perm(struct ibcs2_ipc_perm *, struct ipc_perm *);
   65 
   66 
   67 /*
   68  * iBCS2 msgsys call
   69  */
   70 
   71 static void
   72 cvt_msqid2imsqid(bp, ibp)
   73 struct msqid_ds *bp;
   74 struct ibcs2_msqid_ds *ibp;
   75 {
   76         memset(ibp, 0, sizeof(*ibp));
   77         cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
   78         ibp->msg_cbytes = (u_short)bp->msg_cbytes;
   79         ibp->msg_qnum = (u_short)bp->msg_qnum;
   80         ibp->msg_qbytes = (u_short)bp->msg_qbytes;
   81         ibp->msg_lspid = (u_short)bp->msg_lspid;
   82         ibp->msg_lrpid = (u_short)bp->msg_lrpid;
   83         ibp->msg_stime = bp->msg_stime;
   84         ibp->msg_rtime = bp->msg_rtime;
   85         ibp->msg_ctime = bp->msg_ctime;
   86         return;
   87 }
   88 
   89 static void
   90 cvt_imsqid2msqid(ibp, bp)
   91 struct ibcs2_msqid_ds *ibp;
   92 struct msqid_ds *bp;
   93 {
   94         cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
   95         bp->msg_cbytes = ibp->msg_cbytes;
   96         bp->msg_qnum = ibp->msg_qnum;
   97         bp->msg_qbytes = ibp->msg_qbytes;
   98         bp->msg_lspid = ibp->msg_lspid;
   99         bp->msg_lrpid = ibp->msg_lrpid;
  100         bp->msg_stime = ibp->msg_stime;
  101         bp->msg_rtime = ibp->msg_rtime;
  102         bp->msg_ctime = ibp->msg_ctime;
  103         return;
  104 }
  105 
  106 struct ibcs2_msgget_args {
  107         int what;
  108         ibcs2_key_t key;
  109         int msgflg;
  110 };
  111 
  112 static int
  113 ibcs2_msgget(struct thread *td, void *v)
  114 {
  115         struct ibcs2_msgget_args *uap = v;
  116         struct msgget_args ap;
  117 
  118         ap.key = uap->key;
  119         ap.msgflg = uap->msgflg;
  120         return sys_msgget(td, &ap);
  121 }
  122 
  123 struct ibcs2_msgctl_args {
  124         int what;
  125         int msqid;
  126         int cmd;
  127         struct ibcs2_msqid_ds *buf;
  128 };
  129 
  130 static int
  131 ibcs2_msgctl(struct thread *td, void *v)
  132 {
  133         struct ibcs2_msgctl_args *uap = v;
  134         struct ibcs2_msqid_ds is;
  135         struct msqid_ds bs;
  136         int error;
  137 
  138         memset(&is, 0, sizeof(is));
  139 
  140         switch (uap->cmd) {
  141         case IBCS2_IPC_STAT:
  142                 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
  143                 if (!error) {
  144                         cvt_msqid2imsqid(&bs, &is);
  145                         error = copyout(&is, uap->buf, sizeof(is));
  146                 }
  147                 return (error);
  148         case IBCS2_IPC_SET:
  149                 error = copyin(uap->buf, &is, sizeof(is));
  150                 if (error)
  151                         return (error);
  152                 cvt_imsqid2msqid(&is, &bs);
  153                 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
  154         case IBCS2_IPC_RMID:
  155                 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
  156         }
  157         return (EINVAL);
  158 }
  159 
  160 struct ibcs2_msgrcv_args {
  161         int what;
  162         int msqid;
  163         void *msgp;
  164         size_t msgsz;
  165         long msgtyp;
  166         int msgflg;
  167 };
  168 
  169 static int
  170 ibcs2_msgrcv(struct thread *td, void *v)
  171 {
  172         struct ibcs2_msgrcv_args *uap = v;
  173         struct msgrcv_args ap;
  174 
  175         ap.msqid = uap->msqid;
  176         ap.msgp = uap->msgp;
  177         ap.msgsz = uap->msgsz;
  178         ap.msgtyp = uap->msgtyp;
  179         ap.msgflg = uap->msgflg;
  180         return (sys_msgrcv(td, &ap));
  181 }
  182 
  183 struct ibcs2_msgsnd_args {
  184         int what;
  185         int msqid;
  186         void *msgp;
  187         size_t msgsz;
  188         int msgflg;
  189 };
  190 
  191 static int
  192 ibcs2_msgsnd(struct thread *td, void *v)
  193 {
  194         struct ibcs2_msgsnd_args *uap = v;
  195         struct msgsnd_args ap;
  196 
  197         ap.msqid = uap->msqid;
  198         ap.msgp = uap->msgp;
  199         ap.msgsz = uap->msgsz;
  200         ap.msgflg = uap->msgflg;
  201         return (sys_msgsnd(td, &ap));
  202 }
  203 
  204 int
  205 ibcs2_msgsys(td, uap)
  206         struct thread *td;
  207         struct ibcs2_msgsys_args *uap;
  208 {
  209         switch (uap->which) {
  210         case 0:
  211                 return (ibcs2_msgget(td, uap));
  212         case 1:
  213                 return (ibcs2_msgctl(td, uap));
  214         case 2:
  215                 return (ibcs2_msgrcv(td, uap));
  216         case 3:
  217                 return (ibcs2_msgsnd(td, uap));
  218         default:
  219                 return (EINVAL);
  220         }
  221 }
  222 
  223 /*
  224  * iBCS2 semsys call
  225  */
  226 #ifdef unused
  227 static void
  228 cvt_sem2isem(bp, ibp)
  229 struct sem *bp;
  230 struct ibcs2_sem *ibp;
  231 {
  232         ibp->semval = bp->semval;
  233         ibp->sempid = bp->sempid;
  234         ibp->semncnt = bp->semncnt;
  235         ibp->semzcnt = bp->semzcnt;
  236         return;
  237 }
  238 
  239 static void
  240 cvt_isem2sem(ibp, bp)
  241 struct ibcs2_sem *ibp;
  242 struct sem *bp;
  243 {
  244         bp->semval = ibp->semval;
  245         bp->sempid = ibp->sempid;
  246         bp->semncnt = ibp->semncnt;
  247         bp->semzcnt = ibp->semzcnt;
  248         return;
  249 }
  250 #endif
  251 
  252 static void
  253 cvt_iperm2perm(ipp, pp)
  254 struct ibcs2_ipc_perm *ipp;
  255 struct ipc_perm *pp;
  256 {
  257         pp->uid = ipp->uid;
  258         pp->gid = ipp->gid;
  259         pp->cuid = ipp->cuid;
  260         pp->cgid = ipp->cgid;
  261         pp->mode = ipp->mode;
  262         pp->seq = ipp->seq;
  263         pp->key = ipp->key;
  264 }
  265 
  266 static void
  267 cvt_perm2iperm(pp, ipp)
  268 struct ipc_perm *pp;
  269 struct ibcs2_ipc_perm *ipp;
  270 {
  271         ipp->uid = pp->uid;
  272         ipp->gid = pp->gid;
  273         ipp->cuid = pp->cuid;
  274         ipp->cgid = pp->cgid;
  275         ipp->mode = pp->mode;
  276         ipp->seq = pp->seq;
  277         ipp->key = pp->key;
  278 }
  279 
  280 static void
  281 cvt_semid2isemid(bp, ibp)
  282 struct semid_ds *bp;
  283 struct ibcs2_semid_ds *ibp;
  284 {
  285         memset(ibp, 0, sizeof(*ibp));
  286         cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
  287         ibp->sem_nsems = bp->sem_nsems;
  288         ibp->sem_otime = bp->sem_otime;
  289         ibp->sem_ctime = bp->sem_ctime;
  290         return;
  291 }
  292 
  293 static void
  294 cvt_isemid2semid(ibp, bp)
  295 struct ibcs2_semid_ds *ibp;
  296 struct semid_ds *bp;
  297 {
  298         cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
  299         bp->sem_nsems = ibp->sem_nsems;
  300         bp->sem_otime = ibp->sem_otime;
  301         bp->sem_ctime = ibp->sem_ctime;
  302         return;
  303 }
  304 
  305 struct ibcs2_semctl_args {
  306         int what;
  307         int semid;
  308         int semnum;
  309         int cmd;
  310         union semun arg;
  311 };
  312 
  313 static int
  314 ibcs2_semctl(struct thread *td, void *v)
  315 {
  316         struct ibcs2_semctl_args *uap = v;
  317         struct ibcs2_semid_ds is;
  318         struct semid_ds bs;
  319         union semun semun;
  320         register_t rval;
  321         int error;
  322 
  323         memset(&is, 0, sizeof(is));
  324 
  325         switch(uap->cmd) {
  326         case IBCS2_IPC_STAT:
  327                 semun.buf = &bs;
  328                 error = kern_semctl(td, uap->semid, uap->semnum, IPC_STAT,
  329                     &semun, &rval);
  330                 if (error)
  331                         return (error);
  332                 cvt_semid2isemid(&bs, &is);
  333                 error = copyout(&is, uap->arg.buf, sizeof(is));
  334                 if (error == 0)
  335                         td->td_retval[0] = rval;
  336                 return (error);
  337 
  338         case IBCS2_IPC_SET:
  339                 error = copyin(uap->arg.buf, &is, sizeof(is));
  340                 if (error)
  341                         return (error);
  342                 cvt_isemid2semid(&is, &bs);
  343                 semun.buf = &bs;
  344                 return (kern_semctl(td, uap->semid, uap->semnum, IPC_SET,
  345                     &semun, td->td_retval));
  346         }
  347 
  348         return (kern_semctl(td, uap->semid, uap->semnum, uap->cmd, &uap->arg,
  349             td->td_retval));
  350 }
  351 
  352 struct ibcs2_semget_args {
  353         int what;
  354         ibcs2_key_t key;
  355         int nsems;
  356         int semflg;
  357 };
  358 
  359 static int
  360 ibcs2_semget(struct thread *td, void *v)
  361 {
  362         struct ibcs2_semget_args *uap = v;
  363         struct semget_args ap;
  364 
  365         ap.key = uap->key;
  366         ap.nsems = uap->nsems;
  367         ap.semflg = uap->semflg;
  368         return (sys_semget(td, &ap));
  369 }
  370 
  371 struct ibcs2_semop_args {
  372         int what;
  373         int semid;
  374         struct sembuf *sops;
  375         size_t nsops;
  376 };
  377 
  378 static int
  379 ibcs2_semop(struct thread *td, void *v)
  380 {
  381         struct ibcs2_semop_args *uap = v;
  382         struct semop_args ap;
  383 
  384         ap.semid = uap->semid;
  385         ap.sops = uap->sops;
  386         ap.nsops = uap->nsops;
  387         return (sys_semop(td, &ap));
  388 }
  389 
  390 int
  391 ibcs2_semsys(td, uap)
  392         struct thread *td;
  393         struct ibcs2_semsys_args *uap;
  394 {
  395 
  396         switch (uap->which) {
  397         case 0:
  398                 return (ibcs2_semctl(td, uap));
  399         case 1:
  400                 return (ibcs2_semget(td, uap));
  401         case 2:
  402                 return (ibcs2_semop(td, uap));
  403         }
  404         return (EINVAL);
  405 }
  406 
  407 
  408 /*
  409  * iBCS2 shmsys call
  410  */
  411 
  412 static void
  413 cvt_shmid2ishmid(bp, ibp)
  414 struct shmid_ds *bp;
  415 struct ibcs2_shmid_ds *ibp;
  416 {
  417         cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
  418         ibp->shm_segsz = bp->shm_segsz;
  419         ibp->shm_lpid = bp->shm_lpid;
  420         ibp->shm_cpid = bp->shm_cpid;
  421         if (bp->shm_nattch > SHRT_MAX)
  422                 ibp->shm_nattch = SHRT_MAX;
  423         else
  424                 ibp->shm_nattch = bp->shm_nattch;
  425         ibp->shm_cnattch = 0;                   /* ignored anyway */
  426         ibp->shm_atime = bp->shm_atime;
  427         ibp->shm_dtime = bp->shm_dtime;
  428         ibp->shm_ctime = bp->shm_ctime;
  429         return;
  430 }
  431 
  432 static void
  433 cvt_ishmid2shmid(ibp, bp)
  434 struct ibcs2_shmid_ds *ibp;
  435 struct shmid_ds *bp;
  436 {
  437         cvt_iperm2perm(&ibp->shm_perm, &bp->shm_perm);
  438         bp->shm_segsz = ibp->shm_segsz;
  439         bp->shm_lpid = ibp->shm_lpid;
  440         bp->shm_cpid = ibp->shm_cpid;
  441         bp->shm_nattch = ibp->shm_nattch;
  442         bp->shm_atime = ibp->shm_atime;
  443         bp->shm_dtime = ibp->shm_dtime;
  444         bp->shm_ctime = ibp->shm_ctime;
  445         return;
  446 }
  447 
  448 struct ibcs2_shmat_args {
  449         int what;
  450         int shmid;
  451         const void *shmaddr;
  452         int shmflg;
  453 };
  454 
  455 static int
  456 ibcs2_shmat(struct thread *td, void *v)
  457 {
  458         struct ibcs2_shmat_args *uap = v;
  459         struct shmat_args ap;
  460 
  461         ap.shmid = uap->shmid;
  462         ap.shmaddr = uap->shmaddr;
  463         ap.shmflg = uap->shmflg;
  464         return (sys_shmat(td, &ap));
  465 }
  466 
  467 struct ibcs2_shmctl_args {
  468         int what;
  469         int shmid;
  470         int cmd;
  471         struct ibcs2_shmid_ds *buf;
  472 };
  473 
  474 static int
  475 ibcs2_shmctl(struct thread *td, void *v)
  476 {
  477         struct ibcs2_shmctl_args *uap = v;
  478         struct ibcs2_shmid_ds is;
  479         struct shmid_ds bs;
  480         int error;
  481 
  482         switch(uap->cmd) {
  483         case IBCS2_IPC_STAT:
  484                 error = kern_shmctl(td, uap->shmid, IPC_STAT, &bs, NULL);
  485                 if (error)
  486                         return (error);
  487                 cvt_shmid2ishmid(&bs, &is);
  488                 return (copyout(&is, uap->buf, sizeof(is)));
  489 
  490         case IBCS2_IPC_SET:
  491                 error = copyin(uap->buf, &is, sizeof(is));
  492                 if (error)
  493                         return (error);
  494                 cvt_ishmid2shmid(&is, &bs);
  495                 return (kern_shmctl(td, uap->shmid, IPC_SET, &bs, NULL));
  496 
  497         case IPC_INFO:
  498         case SHM_INFO:
  499         case SHM_STAT:
  500                 /* XXX: */
  501                 return (EINVAL);
  502         }
  503 
  504         return (kern_shmctl(td, uap->shmid, uap->cmd, NULL, NULL));
  505 }
  506 
  507 struct ibcs2_shmdt_args {
  508         int what;
  509         const void *shmaddr;
  510 };
  511 
  512 static int
  513 ibcs2_shmdt(struct thread *td, void *v)
  514 {
  515         struct ibcs2_shmdt_args *uap = v;
  516         struct shmdt_args ap;
  517 
  518         ap.shmaddr = uap->shmaddr;
  519         return (sys_shmdt(td, &ap));
  520 }
  521 
  522 struct ibcs2_shmget_args {
  523         int what;
  524         ibcs2_key_t key;
  525         size_t size;
  526         int shmflg;
  527 };
  528 
  529 static int
  530 ibcs2_shmget(struct thread *td, void *v)
  531 {
  532         struct ibcs2_shmget_args *uap = v;
  533         struct shmget_args ap;
  534 
  535         ap.key = uap->key;
  536         ap.size = uap->size;
  537         ap.shmflg = uap->shmflg;
  538         return (sys_shmget(td, &ap));
  539 }
  540 
  541 int
  542 ibcs2_shmsys(td, uap)
  543         struct thread *td;
  544         struct ibcs2_shmsys_args *uap;
  545 {
  546 
  547         switch (uap->which) {
  548         case 0:
  549                 return (ibcs2_shmat(td, uap));
  550         case 1:
  551                 return (ibcs2_shmctl(td, uap));
  552         case 2:
  553                 return (ibcs2_shmdt(td, uap));
  554         case 3:
  555                 return (ibcs2_shmget(td, uap));
  556         }
  557         return (EINVAL);
  558 }
  559 
  560 MODULE_DEPEND(ibcs2, sysvmsg, 1, 1, 1);
  561 MODULE_DEPEND(ibcs2, sysvsem, 1, 1, 1);
  562 MODULE_DEPEND(ibcs2, sysvshm, 1, 1, 1);

Cache object: 49769f0d88c21eed2c89ea003527fd3d


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