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_msg.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 Steven Wallace
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. The name of the author may not be used to endorse or promote products
   11  *    derived from this software without specific prior written permission
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   23  */
   24 
   25 #include <sys/cdefs.h>
   26 __FBSDID("$FreeBSD: releng/6.3/sys/i386/ibcs2/ibcs2_msg.c 142504 2005-02-25 20:15:11Z sam $");
   27 
   28 /*
   29  * IBCS2 message compatibility module.
   30  *
   31  */
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/syscallsubr.h>
   36 #include <sys/sysproto.h>
   37 
   38 #include <i386/ibcs2/ibcs2_types.h>
   39 #include <i386/ibcs2/ibcs2_signal.h>
   40 #include <i386/ibcs2/ibcs2_util.h>
   41 #include <i386/ibcs2/ibcs2_poll.h>
   42 #include <i386/ibcs2/ibcs2_proto.h>
   43 
   44 
   45 int
   46 ibcs2_getmsg(td, uap)
   47         struct thread *td;
   48         struct ibcs2_getmsg_args *uap;
   49 {
   50         return 0; /* fake */
   51 }
   52 
   53 int
   54 ibcs2_putmsg(td, uap)
   55         struct thread *td;
   56         struct ibcs2_putmsg_args *uap;
   57 {
   58         return 0; /* fake */
   59 }
   60 
   61 
   62 int
   63 ibcs2_poll(td, uap)
   64         struct thread *td;
   65         struct ibcs2_poll_args *uap;
   66 {
   67         int error, i, nfds;
   68         fd_set *readfds, *writefds, *exceptfds;
   69         struct timeval timeout, *tp;
   70         struct ibcs2_poll conv;
   71         caddr_t sg = stackgap_init();
   72 
   73         if (uap->nfds > FD_SETSIZE)
   74                 return EINVAL;
   75         readfds   = stackgap_alloc(&sg, sizeof(fd_set *));
   76         writefds  = stackgap_alloc(&sg, sizeof(fd_set *));
   77         exceptfds = stackgap_alloc(&sg, sizeof(fd_set *));
   78 
   79         FD_ZERO(readfds);
   80         FD_ZERO(writefds);
   81         FD_ZERO(exceptfds);
   82         if (uap->timeout == -1)
   83                 tp = NULL;
   84         else {
   85                 timeout.tv_usec = (uap->timeout % 1000)*1000;
   86                 timeout.tv_sec  = uap->timeout / 1000;
   87                 tp = &timeout;
   88         }
   89 
   90         nfds = 0;
   91         for (i = 0; i < uap->nfds; i++) {
   92                 if ((error = copyin(uap->fds + i*sizeof(struct ibcs2_poll),
   93                                    &conv, sizeof(conv))) != 0)
   94                         return error;
   95                 conv.revents = 0;
   96                 if (conv.fd < 0 || conv.fd >= FD_SETSIZE)
   97                         continue;
   98                 if (conv.fd >= nfds)
   99                         nfds = conv.fd + 1;
  100                 if (conv.events & IBCS2_READPOLL)
  101                         FD_SET(conv.fd, readfds);
  102                 if (conv.events & IBCS2_WRITEPOLL)
  103                         FD_SET(conv.fd, writefds);
  104                 FD_SET(conv.fd, exceptfds);
  105         }
  106         error = kern_select(td, nfds, readfds, writefds, exceptfds, tp);
  107         if (error != 0)
  108                 return error;
  109         if (td->td_retval[0] == 0)
  110                 return 0;
  111         td->td_retval[0] = 0;
  112         for (td->td_retval[0] = 0, i = 0; i < uap->nfds; i++) {
  113                 copyin(uap->fds + i*sizeof(struct ibcs2_poll),
  114                        &conv, sizeof(conv));
  115                 conv.revents = 0;
  116                 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
  117                         /* should check for open as well */
  118                         conv.revents |= IBCS2_POLLNVAL;
  119                 else {
  120                         if (FD_ISSET(conv.fd, readfds))
  121                                 conv.revents |= IBCS2_POLLIN;
  122                         if (FD_ISSET(conv.fd, writefds))
  123                                 conv.revents |= IBCS2_POLLOUT;
  124                         if (FD_ISSET(conv.fd, exceptfds))
  125                                 conv.revents |= IBCS2_POLLERR;
  126                         if (conv.revents)
  127                                 ++td->td_retval[0];
  128                 }
  129                 if ((error = copyout(&conv,
  130                                     uap->fds + i*sizeof(struct ibcs2_poll),
  131                                     sizeof(conv))) != 0)
  132                         return error;
  133         }
  134         return 0;
  135 }

Cache object: d23d34a3f5573a606e8dd05b925e10b8


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