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 * $FreeBSD: src/sys/i386/ibcs2/ibcs2_msg.c,v 1.1.4.1 1999/09/05 08:11:27 peter Exp $
25 */
26
27 /*
28 * IBCS2 message compatibility module.
29 *
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/sysproto.h>
35 #include <sys/kernel.h>
36
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>
42
43
44 int
45 ibcs2_getmsg(p, uap, retval)
46 struct proc *p;
47 struct ibcs2_getmsg_args *uap;
48 int *retval;
49 {
50 return 0; /* fake */
51 }
52
53 int
54 ibcs2_putmsg(p, uap, retval)
55 struct proc *p;
56 struct ibcs2_putmsg_args *uap;
57 int *retval;
58 {
59 return 0; /* fake */
60 }
61
62
63 int
64 ibcs2_poll(p, uap, retval)
65 struct proc *p;
66 struct ibcs2_poll_args *uap;
67 int *retval;
68 {
69 int error, i;
70 fd_set *readfds, *writefds, *exceptfds;
71 struct timeval *timeout;
72 struct ibcs2_poll conv;
73 struct select_args tmp_select;
74 caddr_t sg = stackgap_init();
75
76 if (uap->nfds > FD_SETSIZE)
77 return EINVAL;
78 readfds = stackgap_alloc(&sg, sizeof(fd_set *));
79 writefds = stackgap_alloc(&sg, sizeof(fd_set *));
80 exceptfds = stackgap_alloc(&sg, sizeof(fd_set *));
81 timeout = stackgap_alloc(&sg, sizeof(struct timeval *));
82
83 FD_ZERO(readfds);
84 FD_ZERO(writefds);
85 FD_ZERO(exceptfds);
86 if (uap->timeout == -1)
87 timeout = NULL;
88 else {
89 timeout->tv_usec = (uap->timeout % 1000)*1000;
90 timeout->tv_sec = uap->timeout / 1000;
91 }
92
93 tmp_select.nd = 0;
94 tmp_select.in = readfds;
95 tmp_select.ou = writefds;
96 tmp_select.ex = exceptfds;
97 tmp_select.tv = timeout;
98
99 for (i = 0; i < uap->nfds; i++) {
100 if (error = copyin(uap->fds + i*sizeof(struct ibcs2_poll),
101 &conv, sizeof(conv)))
102 return error;
103 conv.revents = 0;
104 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
105 continue;
106 if (conv.fd >= tmp_select.nd)
107 tmp_select.nd = conv.fd + 1;
108 if (conv.events & IBCS2_READPOLL)
109 FD_SET(conv.fd, readfds);
110 if (conv.events & IBCS2_WRITEPOLL)
111 FD_SET(conv.fd, writefds);
112 FD_SET(conv.fd, exceptfds);
113 }
114 if (error = select(p, &tmp_select, retval))
115 return error;
116 if (*retval == 0)
117 return 0;
118 *retval = 0;
119 for (*retval = 0, i = 0; i < uap->nfds; i++) {
120 copyin(uap->fds + i*sizeof(struct ibcs2_poll),
121 &conv, sizeof(conv));
122 conv.revents = 0;
123 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
124 /* should check for open as well */
125 conv.revents |= IBCS2_POLLNVAL;
126 else {
127 if (FD_ISSET(conv.fd, readfds))
128 conv.revents |= IBCS2_POLLIN;
129 if (FD_ISSET(conv.fd, writefds))
130 conv.revents |= IBCS2_POLLOUT;
131 if (FD_ISSET(conv.fd, exceptfds))
132 conv.revents |= IBCS2_POLLERR;
133 if (conv.revents)
134 ++*retval;
135 }
136 if (error = copyout(&conv,
137 uap->fds + i*sizeof(struct ibcs2_poll),
138 sizeof(conv)))
139 return error;
140 }
141 return 0;
142 }
Cache object: 071ccbf2eba09402dd4445777d20e624
|