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

Cache object: b0632235160103d0434a748032942ff0


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