2 * Copyright (c) 1995 Steven Wallace
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
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.
24 * $FreeBSD: src/sys/i386/ibcs2/ibcs2_msg.c,v 1.7 1999/08/28 00:43:59 peter Exp $
25 * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_msg.c,v 1.5 2003/07/30 00:19:13 dillon Exp $
29 * IBCS2 message compatibility module.
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/sysproto.h>
37 #include <i386/ibcs2/ibcs2_types.h>
38 #include <i386/ibcs2/ibcs2_signal.h>
39 #include <i386/ibcs2/ibcs2_util.h>
40 #include <i386/ibcs2/ibcs2_poll.h>
41 #include <i386/ibcs2/ibcs2_proto.h>
45 ibcs2_getmsg(struct ibcs2_getmsg_args *uap)
51 ibcs2_putmsg(struct ibcs2_putmsg_args *uap)
58 ibcs2_poll(struct ibcs2_poll_args *uap)
61 fd_set *readfds, *writefds, *exceptfds;
62 struct timeval *timeout;
63 struct ibcs2_poll conv;
64 struct select_args tmp_select;
65 caddr_t sg = stackgap_init();
67 if (uap->nfds > FD_SETSIZE)
69 readfds = stackgap_alloc(&sg, sizeof(fd_set *));
70 writefds = stackgap_alloc(&sg, sizeof(fd_set *));
71 exceptfds = stackgap_alloc(&sg, sizeof(fd_set *));
72 timeout = stackgap_alloc(&sg, sizeof(struct timeval *));
77 if (uap->timeout == -1)
80 timeout->tv_usec = (uap->timeout % 1000)*1000;
81 timeout->tv_sec = uap->timeout / 1000;
85 tmp_select.in = readfds;
86 tmp_select.ou = writefds;
87 tmp_select.ex = exceptfds;
88 tmp_select.tv = timeout;
90 for (i = 0; i < uap->nfds; i++) {
91 if ((error = copyin(uap->fds + i*sizeof(struct ibcs2_poll),
92 &conv, sizeof(conv))) != 0)
95 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
97 if (conv.fd >= tmp_select.nd)
98 tmp_select.nd = conv.fd + 1;
99 if (conv.events & IBCS2_READPOLL)
100 FD_SET(conv.fd, readfds);
101 if (conv.events & IBCS2_WRITEPOLL)
102 FD_SET(conv.fd, writefds);
103 FD_SET(conv.fd, exceptfds);
105 if ((error = select(&tmp_select)) != 0)
107 uap->sysmsg_result = tmp_select.sysmsg_result;
108 if (uap->sysmsg_result == 0)
110 uap->sysmsg_result = 0;
111 for (i = 0; i < uap->nfds; i++) {
112 copyin(uap->fds + i*sizeof(struct ibcs2_poll),
113 &conv, sizeof(conv));
115 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
116 /* should check for open as well */
117 conv.revents |= IBCS2_POLLNVAL;
119 if (FD_ISSET(conv.fd, readfds))
120 conv.revents |= IBCS2_POLLIN;
121 if (FD_ISSET(conv.fd, writefds))
122 conv.revents |= IBCS2_POLLOUT;
123 if (FD_ISSET(conv.fd, exceptfds))
124 conv.revents |= IBCS2_POLLERR;
126 ++uap->sysmsg_result;
128 if ((error = copyout(&conv,
129 uap->fds + i*sizeof(struct ibcs2_poll),