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>
36 #include <sys/filio.h>
38 #include <sys/signal.h>
39 #include <sys/filedesc.h>
41 #include <sys/malloc.h>
42 #include <sys/mutex.h>
43 #include <sys/resource.h>
44 #include <sys/resourcevar.h>
46 #include <sys/sysproto.h>
48 #include <compat/svr4/svr4.h>
49 #include <compat/svr4/svr4_types.h>
50 #include <compat/svr4/svr4_util.h>
51 #include <compat/svr4/svr4_signal.h>
52 #include <compat/svr4/svr4_proto.h>
53 #include <compat/svr4/svr4_ioctl.h>
54 #include <compat/svr4/svr4_filio.h>
56 /*#define GROTTY_READ_HACK*/
59 svr4_sys_poll(td, uap)
61 struct svr4_sys_poll_args *uap;
69 PROC_LOCK(td->td_proc);
70 if (uap->nfds > lim_cur(td->td_proc, RLIMIT_NOFILE) &&
71 uap->nfds > FD_SETSIZE) {
72 PROC_UNLOCK(td->td_proc);
75 PROC_UNLOCK(td->td_proc);
79 pa.timeout = uap->timeout;
81 siz = uap->nfds * sizeof(struct pollfd);
82 pfd = (struct pollfd *)malloc(siz, M_TEMP, M_WAITOK);
84 error = poll(td, (struct poll_args *)uap);
86 if ((cerr = copyin(uap->fds, pfd, siz)) != 0) {
91 for (idx = 0; idx < uap->nfds; idx++) {
92 /* POLLWRNORM already equals POLLOUT, so we don't worry about that */
93 if (pfd[idx].revents & (POLLOUT | POLLWRNORM | POLLWRBAND))
94 pfd[idx].revents |= (POLLOUT | POLLWRNORM | POLLWRBAND);
96 if ((cerr = copyout(pfd, uap->fds, siz)) != 0) {
98 goto done; /* yeah, I know it's the next line, but this way I won't
99 forget to update it if I add more code */
106 #if defined(READ_TEST)
108 svr4_sys_read(td, uap)
110 struct svr4_sys_read_args *uap;
114 struct socket *so = NULL;
121 ra.nbyte = uap->nbyte;
123 if (fget(td, uap->fd, &fp) != 0) {
124 DPRINTF(("Something fishy with the user-supplied file descriptor...\n"));
128 if (fp->f_type == DTYPE_SOCKET) {
130 DPRINTF(("fd %d is a socket\n", uap->fd));
131 if (so->so_state & SS_ASYNC) {
132 DPRINTF(("fd %d is an ASYNC socket!\n", uap->fd));
134 DPRINTF(("Here are its flags: 0x%x\n", so->so_state));
135 #if defined(GROTTY_READ_HACK)
136 so_state = so->so_state;
137 so->so_state &= ~SS_NBIO;
143 DPRINTF(("svr4_read(%d, 0x%0x, %d) = %d\n",
144 uap->fd, uap->buf, uap->nbyte, rv));
149 PROC_LOCK(td->td_proc);
150 ps = td->td_proc->p_sigacts;
151 mtx_lock(&ps->ps_mtx);
153 DPRINTF(("sigmask = 0x%x\n", td->td_sigmask));
154 DPRINTF(("sigignore = 0x%x\n", ps->ps_sigignore));
155 DPRINTF(("sigcaught = 0x%x\n", ps->ps_sigcatch));
156 DPRINTF(("siglist = 0x%x\n", td->td_siglist));
158 mtx_unlock(&ps->ps_mtx);
159 PROC_UNLOCK(td->td_proc);
163 #if defined(GROTTY_READ_HACK)
164 if (so) { /* We've already checked to see if this is a socket */
165 so->so_state = so_state;
172 #endif /* READ_TEST */
176 svr4_sys_write(td, uap)
178 struct svr4_sys_write_args *uap;
180 struct write_args wa;
186 wa.nbyte = uap->nbyte;
190 DPRINTF(("svr4_write(%d, 0x%0x, %d) = %d\n",
191 uap->fd, uap->buf, uap->nbyte, rv));
198 svr4_fil_ioctl(fp, td, retval, fd, cmd, data)
208 struct filedesc *fdp = td->td_proc->p_fd;
215 fdp->fd_ofileflags[fd] |= UF_EXCLOSE;
216 FILEDESC_XUNLOCK(fdp);
221 fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE;
222 FILEDESC_XUNLOCK(fdp);
230 if ((error = copyin(data, &num, sizeof(num))) != 0)
234 case SVR4_FIOGETOWN: cmd = FIOGETOWN; break;
235 case SVR4_FIOSETOWN: cmd = FIOSETOWN; break;
236 case SVR4_FIOASYNC: cmd = FIOASYNC; break;
237 case SVR4_FIONBIO: cmd = FIONBIO; break;
238 case SVR4_FIONREAD: cmd = FIONREAD; break;
242 if (cmd == FIOASYNC) DPRINTF(("FIOASYNC\n"));
244 error = fo_ioctl(fp, cmd, (caddr_t) &num, td->td_ucred, td);
249 return copyout(&num, data, sizeof(num));
252 DPRINTF(("Unknown svr4 filio %lx\n", cmd));
253 return 0; /* ENOSYS really */