Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / emulation / ibcs2 / i386 / ibcs2_msg.c
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.7 1999/08/28 00:43:59 peter Exp $
25  * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_msg.c,v 1.2 2003/06/17 04:28:35 dillon Exp $
26  */
27
28 /*
29  * IBCS2 message compatibility module.
30  *
31  */
32
33 #include <sys/param.h>
34 #include <sys/systm.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_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)
46         struct proc *p;
47         struct ibcs2_getmsg_args *uap;
48 {
49         return 0; /* fake */
50 }
51
52 int
53 ibcs2_putmsg(p, uap)
54         struct proc *p;
55         struct ibcs2_putmsg_args *uap;
56 {
57         return 0; /* fake */
58 }
59
60
61 int
62 ibcs2_poll(p, uap)
63         struct proc *p;
64         struct ibcs2_poll_args *uap;
65 {
66         int error, i;
67         fd_set *readfds, *writefds, *exceptfds;
68         struct timeval *timeout;
69         struct ibcs2_poll conv;
70         struct select_args tmp_select;
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         timeout   = stackgap_alloc(&sg, sizeof(struct timeval *));
79
80         FD_ZERO(readfds);
81         FD_ZERO(writefds);
82         FD_ZERO(exceptfds);
83         if (uap->timeout == -1)
84                 timeout = NULL;
85         else {
86                 timeout->tv_usec = (uap->timeout % 1000)*1000;
87                 timeout->tv_sec  = uap->timeout / 1000;
88         }
89
90         tmp_select.nd = 0;
91         tmp_select.in = readfds;
92         tmp_select.ou = writefds;
93         tmp_select.ex = exceptfds;
94         tmp_select.tv = timeout;
95
96         for (i = 0; i < uap->nfds; i++) {
97                 if ((error = copyin(uap->fds + i*sizeof(struct ibcs2_poll),
98                                    &conv, sizeof(conv))) != 0)
99                         return error;
100                 conv.revents = 0;
101                 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
102                         continue;
103                 if (conv.fd >= tmp_select.nd)
104                         tmp_select.nd = conv.fd + 1;
105                 if (conv.events & IBCS2_READPOLL)
106                         FD_SET(conv.fd, readfds);
107                 if (conv.events & IBCS2_WRITEPOLL)
108                         FD_SET(conv.fd, writefds);
109                 FD_SET(conv.fd, exceptfds);
110         }
111         if ((error = select(p, &tmp_select)) != 0)
112                 return error;
113         if (p->p_retval[0] == 0)
114                 return 0;
115         p->p_retval[0] = 0;
116         for (p->p_retval[0] = 0, i = 0; i < uap->nfds; i++) {
117                 copyin(uap->fds + i*sizeof(struct ibcs2_poll),
118                        &conv, sizeof(conv));
119                 conv.revents = 0;
120                 if (conv.fd < 0 || conv.fd > FD_SETSIZE)
121                         /* should check for open as well */
122                         conv.revents |= IBCS2_POLLNVAL;
123                 else {
124                         if (FD_ISSET(conv.fd, readfds))
125                                 conv.revents |= IBCS2_POLLIN;
126                         if (FD_ISSET(conv.fd, writefds))
127                                 conv.revents |= IBCS2_POLLOUT;
128                         if (FD_ISSET(conv.fd, exceptfds))
129                                 conv.revents |= IBCS2_POLLERR;
130                         if (conv.revents)
131                                 ++p->p_retval[0];
132                 }
133                 if ((error = copyout(&conv,
134                                     uap->fds + i*sizeof(struct ibcs2_poll),
135                                     sizeof(conv))) != 0)
136                         return error;
137         }
138         return 0;
139 }