2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/capability.h>
37 #include <sys/filio.h>
39 #include <sys/signal.h>
40 #include <sys/filedesc.h>
42 #include <sys/malloc.h>
43 #include <sys/mutex.h>
45 #include <sys/sysproto.h>
47 #include <compat/svr4/svr4.h>
48 #include <compat/svr4/svr4_types.h>
49 #include <compat/svr4/svr4_util.h>
50 #include <compat/svr4/svr4_signal.h>
51 #include <compat/svr4/svr4_proto.h>
52 #include <compat/svr4/svr4_ioctl.h>
53 #include <compat/svr4/svr4_filio.h>
55 /*#define GROTTY_READ_HACK*/
58 svr4_sys_poll(td, uap)
60 struct svr4_sys_poll_args *uap;
68 if (uap->nfds > maxfilesperproc && uap->nfds > FD_SETSIZE)
73 pa.timeout = uap->timeout;
75 siz = uap->nfds * sizeof(struct pollfd);
76 pfd = (struct pollfd *)malloc(siz, M_TEMP, M_WAITOK);
78 error = sys_poll(td, (struct poll_args *)uap);
80 if ((cerr = copyin(uap->fds, pfd, siz)) != 0) {
85 for (idx = 0; idx < uap->nfds; idx++) {
86 /* POLLWRNORM already equals POLLOUT, so we don't worry about that */
87 if (pfd[idx].revents & (POLLOUT | POLLWRNORM | POLLWRBAND))
88 pfd[idx].revents |= (POLLOUT | POLLWRNORM | POLLWRBAND);
90 if ((cerr = copyout(pfd, uap->fds, siz)) != 0) {
92 goto done; /* yeah, I know it's the next line, but this way I won't
93 forget to update it if I add more code */
100 #if defined(READ_TEST)
102 svr4_sys_read(td, uap)
104 struct svr4_sys_read_args *uap;
109 struct socket *so = NULL;
116 ra.nbyte = uap->nbyte;
118 if (fget(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp) != 0) {
119 DPRINTF(("Something fishy with the user-supplied file descriptor...\n"));
123 if (fp->f_type == DTYPE_SOCKET) {
125 DPRINTF(("fd %d is a socket\n", uap->fd));
126 if (so->so_state & SS_ASYNC) {
127 DPRINTF(("fd %d is an ASYNC socket!\n", uap->fd));
129 DPRINTF(("Here are its flags: 0x%x\n", so->so_state));
130 #if defined(GROTTY_READ_HACK)
131 so_state = so->so_state;
132 so->so_state &= ~SS_NBIO;
138 DPRINTF(("svr4_read(%d, 0x%0x, %d) = %d\n",
139 uap->fd, uap->buf, uap->nbyte, rv));
144 PROC_LOCK(td->td_proc);
145 ps = td->td_proc->p_sigacts;
146 mtx_lock(&ps->ps_mtx);
148 DPRINTF(("sigmask = 0x%x\n", td->td_sigmask));
149 DPRINTF(("sigignore = 0x%x\n", ps->ps_sigignore));
150 DPRINTF(("sigcaught = 0x%x\n", ps->ps_sigcatch));
151 DPRINTF(("siglist = 0x%x\n", td->td_siglist));
153 mtx_unlock(&ps->ps_mtx);
154 PROC_UNLOCK(td->td_proc);
158 #if defined(GROTTY_READ_HACK)
159 if (so) { /* We've already checked to see if this is a socket */
160 so->so_state = so_state;
167 #endif /* READ_TEST */
171 svr4_sys_write(td, uap)
173 struct svr4_sys_write_args *uap;
175 struct write_args wa;
181 wa.nbyte = uap->nbyte;
185 DPRINTF(("svr4_write(%d, 0x%0x, %d) = %d\n",
186 uap->fd, uap->buf, uap->nbyte, rv));
193 svr4_fil_ioctl(fp, td, retval, fd, cmd, data)
201 struct filedesc *fdp = td->td_proc->p_fd;
202 struct filedescent *fde;
210 fde = &fdp->fd_ofiles[fd];
211 fde->fde_flags |= UF_EXCLOSE;
212 FILEDESC_XUNLOCK(fdp);
217 fde = &fdp->fd_ofiles[fd];
218 fde->fde_flags &= ~UF_EXCLOSE;
219 FILEDESC_XUNLOCK(fdp);
227 if ((error = copyin(data, &num, sizeof(num))) != 0)
231 case SVR4_FIOGETOWN: cmd = FIOGETOWN; break;
232 case SVR4_FIOSETOWN: cmd = FIOSETOWN; break;
233 case SVR4_FIOASYNC: cmd = FIOASYNC; break;
234 case SVR4_FIONBIO: cmd = FIONBIO; break;
235 case SVR4_FIONREAD: cmd = FIONREAD; break;
239 if (cmd == FIOASYNC) DPRINTF(("FIOASYNC\n"));
241 error = fo_ioctl(fp, cmd, (caddr_t) &num, td->td_ucred, td);
246 return copyout(&num, data, sizeof(num));
249 DPRINTF(("Unknown svr4 filio %lx\n", cmd));
250 return 0; /* ENOSYS really */