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/netbsd32/netbsd32_compat_14.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: netbsd32_compat_14.c,v 1.21 2007/12/20 23:03:01 dsl Exp $      */
    2 
    3 /*
    4  * Copyright (c) 1999 Eduardo E. Horvath
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. The name of the author may not be used to endorse or promote products
   16  *    derived from this software without specific prior written permission.
   17  *
   18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
   25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28  * SUCH DAMAGE.
   29  */
   30 
   31 #include <sys/cdefs.h>
   32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_14.c,v 1.21 2007/12/20 23:03:01 dsl Exp $");
   33 
   34 #include <sys/param.h>
   35 #include <sys/ipc.h>
   36 #include <sys/systm.h>
   37 #include <sys/signal.h>
   38 #include <sys/proc.h>
   39 #include <sys/mount.h>
   40 #include <sys/msg.h>
   41 #include <sys/sem.h>
   42 #include <sys/shm.h>
   43 
   44 #ifndef SYSVMSG
   45 #define SYSVMSG
   46 #endif
   47 #ifndef SYSVSEM
   48 #define SYSVSEM
   49 #endif
   50 #ifndef SYSVSHM
   51 #define SYSVSHM
   52 #endif
   53 
   54 #include <sys/syscallargs.h>
   55 #include <compat/netbsd32/netbsd32.h>
   56 #include <compat/netbsd32/netbsd32_syscallargs.h>
   57 #include <compat/sys/shm.h>
   58 
   59 static inline void
   60 netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14 *, struct ipc_perm *);
   61 static inline void
   62 native_to_netbsd32_ipc_perm14(struct ipc_perm *, struct netbsd32_ipc_perm14 *);
   63 static inline void
   64 native_to_netbsd32_msqid_ds14(struct msqid_ds *, struct netbsd32_msqid_ds14 *);
   65 static inline void
   66 netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14 *, struct msqid_ds *);
   67 static inline void
   68 native_to_netbsd32_semid_ds14(struct semid_ds *, struct netbsd32_semid_ds14 *);
   69 static inline void
   70 netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14 *, struct semid_ds *);
   71 static inline void
   72 netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14 *, struct shmid_ds *);
   73 static inline void
   74 native_to_netbsd32_shmid_ds14(struct shmid_ds *, struct netbsd32_shmid_ds14 *);
   75 
   76 static inline void
   77 netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14 *operm, struct ipc_perm *perm)
   78 {
   79 
   80 #define CVT(x)  perm->x = operm->x
   81         CVT(uid);
   82         CVT(gid);
   83         CVT(cuid);
   84         CVT(cgid);
   85         CVT(mode);
   86 #undef CVT
   87 }
   88 
   89 static inline void
   90 native_to_netbsd32_ipc_perm14(struct ipc_perm *perm, struct netbsd32_ipc_perm14 *operm)
   91 {
   92 
   93 #define CVT(x)  operm->x = perm->x
   94         CVT(uid);
   95         CVT(gid);
   96         CVT(cuid);
   97         CVT(cgid);
   98         CVT(mode);
   99 #undef CVT
  100 
  101         /*
  102          * Not part of the API, but some programs might look at it.
  103          */
  104         operm->seq = perm->_seq;
  105         operm->key = (key_t)perm->_key;
  106 }
  107 
  108 static inline void
  109 netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14 *omsqbuf, struct msqid_ds *msqbuf)
  110 {
  111 
  112         netbsd32_ipc_perm14_to_native(&omsqbuf->msg_perm, &msqbuf->msg_perm);
  113 
  114 #define CVT(x)  msqbuf->x = omsqbuf->x
  115         CVT(msg_qnum);
  116         CVT(msg_qbytes);
  117         CVT(msg_lspid);
  118         CVT(msg_lrpid);
  119         CVT(msg_stime);
  120         CVT(msg_rtime);
  121         CVT(msg_ctime);
  122 #undef CVT
  123 }
  124 
  125 static inline void
  126 native_to_netbsd32_msqid_ds14(struct msqid_ds *msqbuf, struct netbsd32_msqid_ds14 *omsqbuf)
  127 {
  128 
  129         native_to_netbsd32_ipc_perm14(&msqbuf->msg_perm, &omsqbuf->msg_perm);
  130 
  131 #define CVT(x)  omsqbuf->x = msqbuf->x
  132         CVT(msg_qnum);
  133         CVT(msg_qbytes);
  134         CVT(msg_lspid);
  135         CVT(msg_lrpid);
  136         CVT(msg_stime);
  137         CVT(msg_rtime);
  138         CVT(msg_ctime);
  139 #undef CVT
  140 
  141         /*
  142          * Not part of the API, but some programs might look at it.
  143          */
  144         omsqbuf->msg_cbytes = msqbuf->_msg_cbytes;
  145 }
  146 
  147 static inline void
  148 netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14 *osembuf, struct semid_ds *sembuf)
  149 {
  150 
  151         netbsd32_ipc_perm14_to_native(&osembuf->sem_perm, &sembuf->sem_perm);
  152 
  153 #define CVT(x)  sembuf->x = osembuf->x
  154         CVT(sem_nsems);
  155         CVT(sem_otime);
  156         CVT(sem_ctime);
  157 #undef CVT
  158 }
  159 
  160 static inline void
  161 native_to_netbsd32_semid_ds14(struct semid_ds *sembuf, struct netbsd32_semid_ds14 *osembuf)
  162 {
  163 
  164         native_to_netbsd32_ipc_perm14(&sembuf->sem_perm, &osembuf->sem_perm);
  165 
  166 #define CVT(x)  osembuf->x = sembuf->x
  167         CVT(sem_nsems);
  168         CVT(sem_otime);
  169         CVT(sem_ctime);
  170 #undef CVT
  171 }
  172 
  173 static inline void
  174 netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14 *oshmbuf, struct shmid_ds *shmbuf)
  175 {
  176 
  177         netbsd32_ipc_perm14_to_native(&oshmbuf->shm_perm, &shmbuf->shm_perm);
  178 
  179 #define CVT(x)  shmbuf->x = oshmbuf->x
  180         CVT(shm_segsz);
  181         CVT(shm_lpid);
  182         CVT(shm_cpid);
  183         CVT(shm_nattch);
  184         CVT(shm_atime);
  185         CVT(shm_dtime);
  186         CVT(shm_ctime);
  187 #undef CVT
  188 }
  189 
  190 static inline void
  191 native_to_netbsd32_shmid_ds14(struct shmid_ds *shmbuf, struct netbsd32_shmid_ds14 *oshmbuf)
  192 {
  193 
  194         native_to_netbsd32_ipc_perm14(&shmbuf->shm_perm, &oshmbuf->shm_perm);
  195 
  196 #define CVT(x)  oshmbuf->x = shmbuf->x
  197         CVT(shm_segsz);
  198         CVT(shm_lpid);
  199         CVT(shm_cpid);
  200         CVT(shm_nattch);
  201         CVT(shm_atime);
  202         CVT(shm_dtime);
  203         CVT(shm_ctime);
  204 #undef CVT
  205 }
  206 
  207 /*
  208  * the compat_14 system calls
  209  */
  210 int
  211 compat_14_netbsd32_msgctl(struct lwp *l, const struct compat_14_netbsd32_msgctl_args *uap, register_t *retval)
  212 {
  213         /* {
  214                 syscallarg(int) msqid;
  215                 syscallarg(int) cmd;
  216                 syscallarg(struct msqid_ds14 *) buf;
  217         } */
  218         struct msqid_ds msqbuf;
  219         struct netbsd32_msqid_ds14 omsqbuf;
  220         int cmd, error;
  221 
  222         cmd = SCARG(uap, cmd);
  223 
  224         if (cmd == IPC_SET) {
  225                 error = copyin(SCARG_P32(uap, buf),
  226                     &omsqbuf, sizeof(omsqbuf));
  227                 if (error)
  228                         return (error);
  229                 netbsd32_msqid_ds14_to_native(&omsqbuf, &msqbuf);
  230         }
  231 
  232         error = msgctl1(l, SCARG(uap, msqid), cmd,
  233             (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
  234 
  235         if (error == 0 && cmd == IPC_STAT) {
  236                 native_to_netbsd32_msqid_ds14(&msqbuf, &omsqbuf);
  237                 error = copyout(&omsqbuf,
  238                     SCARG_P32(uap, buf), sizeof(omsqbuf));
  239         }
  240 
  241         return (error);
  242 }
  243 
  244 int
  245 compat_14_netbsd32___semctl(struct lwp *l, const struct compat_14_netbsd32___semctl_args *uap, register_t *retval)
  246 {
  247         /* {
  248                 syscallarg(int) semid;
  249                 syscallarg(int) semnum;
  250                 syscallarg(int) cmd;
  251                 syscallarg(union __semun *) arg;
  252         } */
  253         union __semun arg;
  254         struct semid_ds sembuf;
  255         struct netbsd32_semid_ds14 osembuf;
  256         int cmd, error;
  257         void *pass_arg = NULL;
  258 
  259         cmd = SCARG(uap, cmd);
  260 
  261         switch (cmd) {
  262         case IPC_SET:
  263         case IPC_STAT:
  264                 pass_arg = &sembuf;
  265                 break;
  266 
  267         case GETALL:
  268         case SETVAL:
  269         case SETALL:
  270                 pass_arg = &arg;
  271                 break;
  272         }
  273 
  274         if (pass_arg != NULL) {
  275                 error = copyin(NETBSD32IPTR64(SCARG(uap, arg)), &arg,
  276                     sizeof(arg));
  277                 if (error)
  278                         return (error);
  279                 if (cmd == IPC_SET) {
  280                         error = copyin(arg.buf, &osembuf, sizeof(osembuf));
  281                         if (error)
  282                                 return (error);
  283                         netbsd32_semid_ds14_to_native(&osembuf, &sembuf);
  284                 }
  285         }
  286 
  287         error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
  288             pass_arg, retval);
  289 
  290         if (error == 0 && cmd == IPC_STAT) {
  291                 native_to_netbsd32_semid_ds14(&sembuf, &osembuf);
  292                 error = copyout(&osembuf, arg.buf, sizeof(osembuf));
  293         }
  294 
  295         return (error);
  296 }
  297 
  298 int
  299 compat_14_netbsd32_shmctl(struct lwp *l, const struct compat_14_netbsd32_shmctl_args *uap, register_t *retval)
  300 {
  301         /* {
  302                 syscallarg(int) shmid;
  303                 syscallarg(int) cmd;
  304                 syscallarg(struct netbsd32_shmid_ds14 *) buf;
  305         } */
  306         struct shmid_ds shmbuf;
  307         struct netbsd32_shmid_ds14 oshmbuf;
  308         int cmd, error;
  309 
  310         cmd = SCARG(uap, cmd);
  311 
  312         if (cmd == IPC_SET) {
  313                 error = copyin(SCARG_P32(uap, buf), &oshmbuf, sizeof(oshmbuf));
  314                 if (error)
  315                         return (error);
  316                 netbsd32_shmid_ds14_to_native(&oshmbuf, &shmbuf);
  317         }
  318 
  319         error = shmctl1(l, SCARG(uap, shmid), cmd,
  320             (cmd == IPC_SET || cmd == IPC_STAT) ? &shmbuf : NULL);
  321 
  322         if (error == 0 && cmd == IPC_STAT) {
  323                 native_to_netbsd32_shmid_ds14(&shmbuf, &oshmbuf);
  324                 error = copyout(&oshmbuf, SCARG_P32(uap, buf), sizeof(oshmbuf));
  325         }
  326 
  327         return (error);
  328 }

Cache object: 6b0b4f41d44865ff6708bb8c9100fb5c


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