2005-01-05 22:34:37 +00:00
|
|
|
/*-
|
1999-01-30 06:29:48 +00:00
|
|
|
* Copyright (c) 1998 Mark Newton
|
|
|
|
* Copyright (c) 1994 Christos Zoulas
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-10 21:44:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-01-30 06:29:48 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filio.h>
|
2002-01-30 23:28:25 +00:00
|
|
|
#include <sys/lock.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/malloc.h>
|
2002-01-30 23:28:25 +00:00
|
|
|
#include <sys/mutex.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
|
2000-08-31 22:54:09 +00:00
|
|
|
#include <compat/svr4/svr4.h>
|
|
|
|
#include <compat/svr4/svr4_types.h>
|
|
|
|
#include <compat/svr4/svr4_util.h>
|
|
|
|
#include <compat/svr4/svr4_signal.h>
|
|
|
|
#include <compat/svr4/svr4_proto.h>
|
|
|
|
#include <compat/svr4/svr4_ioctl.h>
|
|
|
|
#include <compat/svr4/svr4_filio.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
/*#define GROTTY_READ_HACK*/
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_poll(td, uap)
|
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_poll_args *uap;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct poll_args pa;
|
|
|
|
struct pollfd *pfd;
|
|
|
|
int idx = 0, cerr;
|
|
|
|
u_long siz;
|
|
|
|
|
2010-07-17 15:52:11 +00:00
|
|
|
if (uap->nfds > maxfilesperproc && uap->nfds > FD_SETSIZE)
|
2004-02-04 21:52:57 +00:00
|
|
|
return (EINVAL);
|
2003-10-20 10:38:48 +00:00
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
pa.fds = uap->fds;
|
|
|
|
pa.nfds = uap->nfds;
|
|
|
|
pa.timeout = uap->timeout;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
siz = uap->nfds * sizeof(struct pollfd);
|
2003-02-19 05:47:46 +00:00
|
|
|
pfd = (struct pollfd *)malloc(siz, M_TEMP, M_WAITOK);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = poll(td, (struct poll_args *)uap);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
if ((cerr = copyin(uap->fds, pfd, siz)) != 0) {
|
1999-01-30 06:29:48 +00:00
|
|
|
error = cerr;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
for (idx = 0; idx < uap->nfds; idx++) {
|
1999-01-30 06:29:48 +00:00
|
|
|
/* POLLWRNORM already equals POLLOUT, so we don't worry about that */
|
|
|
|
if (pfd[idx].revents & (POLLOUT | POLLWRNORM | POLLWRBAND))
|
|
|
|
pfd[idx].revents |= (POLLOUT | POLLWRNORM | POLLWRBAND);
|
|
|
|
}
|
2002-12-14 01:56:26 +00:00
|
|
|
if ((cerr = copyout(pfd, uap->fds, siz)) != 0) {
|
1999-01-30 06:29:48 +00:00
|
|
|
error = cerr;
|
|
|
|
goto done; /* yeah, I know it's the next line, but this way I won't
|
|
|
|
forget to update it if I add more code */
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
free(pfd, M_TEMP);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(READ_TEST)
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_read(td, uap)
|
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_read_args *uap;
|
|
|
|
{
|
|
|
|
struct read_args ra;
|
|
|
|
struct file *fp;
|
|
|
|
struct socket *so = NULL;
|
|
|
|
int so_state;
|
|
|
|
sigset_t sigmask;
|
|
|
|
int rv;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ra.fd = uap->fd;
|
|
|
|
ra.buf = uap->buf;
|
|
|
|
ra.nbyte = uap->nbyte;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2002-01-14 00:13:45 +00:00
|
|
|
if (fget(td, uap->fd, &fp) != 0) {
|
1999-01-30 06:29:48 +00:00
|
|
|
DPRINTF(("Something fishy with the user-supplied file descriptor...\n"));
|
|
|
|
return EBADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp->f_type == DTYPE_SOCKET) {
|
2003-01-13 00:33:17 +00:00
|
|
|
so = fp->f_data;
|
2002-12-14 01:56:26 +00:00
|
|
|
DPRINTF(("fd %d is a socket\n", uap->fd));
|
2002-05-31 11:52:35 +00:00
|
|
|
if (so->so_state & SS_ASYNC) {
|
2002-12-14 01:56:26 +00:00
|
|
|
DPRINTF(("fd %d is an ASYNC socket!\n", uap->fd));
|
2002-05-20 05:41:09 +00:00
|
|
|
}
|
2002-05-31 11:52:35 +00:00
|
|
|
DPRINTF(("Here are its flags: 0x%x\n", so->so_state));
|
|
|
|
#if defined(GROTTY_READ_HACK)
|
|
|
|
so_state = so->so_state;
|
|
|
|
so->so_state &= ~SS_NBIO;
|
|
|
|
#endif
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
rv = read(td, &ra);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
DPRINTF(("svr4_read(%d, 0x%0x, %d) = %d\n",
|
2002-12-14 01:56:26 +00:00
|
|
|
uap->fd, uap->buf, uap->nbyte, rv));
|
1999-01-30 06:29:48 +00:00
|
|
|
if (rv == EAGAIN) {
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
#ifdef DEBUG_SVR4
|
|
|
|
struct sigacts *ps;
|
|
|
|
|
|
|
|
PROC_LOCK(td->td_proc);
|
|
|
|
ps = td->td_proc->p_sigacts;
|
|
|
|
mtx_lock(&ps->ps_mtx);
|
|
|
|
#endif
|
2003-03-31 22:49:17 +00:00
|
|
|
DPRINTF(("sigmask = 0x%x\n", td->td_sigmask));
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
DPRINTF(("sigignore = 0x%x\n", ps->ps_sigignore));
|
|
|
|
DPRINTF(("sigcaught = 0x%x\n", ps->ps_sigcatch));
|
2003-03-31 22:49:17 +00:00
|
|
|
DPRINTF(("siglist = 0x%x\n", td->td_siglist));
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
#ifdef DEBUG_SVR4
|
|
|
|
mtx_unlock(&ps->ps_mtx);
|
|
|
|
PROC_UNLOCK(td->td_proc);
|
|
|
|
#endif
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(GROTTY_READ_HACK)
|
|
|
|
if (so) { /* We've already checked to see if this is a socket */
|
|
|
|
so->so_state = so_state;
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
return(rv);
|
|
|
|
}
|
|
|
|
#endif /* READ_TEST */
|
|
|
|
|
|
|
|
#if defined(BOGUS)
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_write(td, uap)
|
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_write_args *uap;
|
|
|
|
{
|
|
|
|
struct write_args wa;
|
|
|
|
struct file *fp;
|
|
|
|
int rv;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
wa.fd = uap->fd;
|
|
|
|
wa.buf = uap->buf;
|
|
|
|
wa.nbyte = uap->nbyte;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
rv = write(td, &wa);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
DPRINTF(("svr4_write(%d, 0x%0x, %d) = %d\n",
|
2002-12-14 01:56:26 +00:00
|
|
|
uap->fd, uap->buf, uap->nbyte, rv));
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
return(rv);
|
|
|
|
}
|
|
|
|
#endif /* BOGUS */
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_fil_ioctl(fp, td, retval, fd, cmd, data)
|
1999-01-30 06:29:48 +00:00
|
|
|
struct file *fp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
register_t *retval;
|
|
|
|
int fd;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int num;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct filedesc *fdp = td->td_proc->p_fd;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
*retval = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SVR4_FIOCLEX:
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_XLOCK(fdp);
|
1999-01-30 06:29:48 +00:00
|
|
|
fdp->fd_ofileflags[fd] |= UF_EXCLOSE;
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_XUNLOCK(fdp);
|
1999-01-30 06:29:48 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SVR4_FIONCLEX:
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_XLOCK(fdp);
|
1999-01-30 06:29:48 +00:00
|
|
|
fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE;
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_XUNLOCK(fdp);
|
1999-01-30 06:29:48 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SVR4_FIOGETOWN:
|
|
|
|
case SVR4_FIOSETOWN:
|
|
|
|
case SVR4_FIOASYNC:
|
|
|
|
case SVR4_FIONBIO:
|
|
|
|
case SVR4_FIONREAD:
|
|
|
|
if ((error = copyin(data, &num, sizeof(num))) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SVR4_FIOGETOWN: cmd = FIOGETOWN; break;
|
|
|
|
case SVR4_FIOSETOWN: cmd = FIOSETOWN; break;
|
|
|
|
case SVR4_FIOASYNC: cmd = FIOASYNC; break;
|
|
|
|
case SVR4_FIONBIO: cmd = FIONBIO; break;
|
|
|
|
case SVR4_FIONREAD: cmd = FIONREAD; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SVR4_DEBUG
|
|
|
|
if (cmd == FIOASYNC) DPRINTF(("FIOASYNC\n"));
|
|
|
|
#endif
|
2002-08-17 02:36:16 +00:00
|
|
|
error = fo_ioctl(fp, cmd, (caddr_t) &num, td->td_ucred, td);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return copyout(&num, data, sizeof(num));
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINTF(("Unknown svr4 filio %lx\n", cmd));
|
|
|
|
return 0; /* ENOSYS really */
|
|
|
|
}
|
|
|
|
}
|