2005-04-16 16:20:36 -06:00
|
|
|
#ifndef _LINUX_POLL_H
|
|
|
|
#define _LINUX_POLL_H
|
|
|
|
|
|
|
|
#include <asm/poll.h>
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/string.h>
|
2006-10-20 13:17:02 -06:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/sched.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
2006-03-28 02:56:33 -07:00
|
|
|
/* ~832 bytes of stack space used max in sys_select/sys_poll before allocating
|
|
|
|
additional memory. */
|
|
|
|
#define MAX_STACK_ALLOC 832
|
|
|
|
#define FRONTEND_STACK_ALLOC 256
|
|
|
|
#define SELECT_STACK_ALLOC FRONTEND_STACK_ALLOC
|
|
|
|
#define POLL_STACK_ALLOC FRONTEND_STACK_ALLOC
|
|
|
|
#define WQUEUES_STACK_ALLOC (MAX_STACK_ALLOC - FRONTEND_STACK_ALLOC)
|
|
|
|
#define N_INLINE_POLL_ENTRIES (WQUEUES_STACK_ALLOC / sizeof(struct poll_table_entry))
|
|
|
|
|
2007-09-11 16:23:55 -06:00
|
|
|
#define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
struct poll_table_struct;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* structures and helpers for f_op->poll implementations
|
|
|
|
*/
|
|
|
|
typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
|
|
|
|
|
|
|
|
typedef struct poll_table_struct {
|
|
|
|
poll_queue_proc qproc;
|
|
|
|
} poll_table;
|
|
|
|
|
|
|
|
static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
|
|
|
|
{
|
|
|
|
if (p && wait_address)
|
|
|
|
p->qproc(filp, wait_address, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc)
|
|
|
|
{
|
|
|
|
pt->qproc = qproc;
|
|
|
|
}
|
|
|
|
|
2006-03-28 02:56:33 -07:00
|
|
|
struct poll_table_entry {
|
|
|
|
struct file * filp;
|
|
|
|
wait_queue_t wait;
|
|
|
|
wait_queue_head_t * wait_address;
|
|
|
|
};
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Structures and helpers for sys_poll/sys_poll
|
|
|
|
*/
|
|
|
|
struct poll_wqueues {
|
|
|
|
poll_table pt;
|
|
|
|
struct poll_table_page * table;
|
|
|
|
int error;
|
2006-03-28 02:56:33 -07:00
|
|
|
int inline_index;
|
|
|
|
struct poll_table_entry inline_entries[N_INLINE_POLL_ENTRIES];
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
extern void poll_initwait(struct poll_wqueues *pwq);
|
|
|
|
extern void poll_freewait(struct poll_wqueues *pwq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scaleable version of the fd_set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned long *in, *out, *ex;
|
|
|
|
unsigned long *res_in, *res_out, *res_ex;
|
|
|
|
} fd_set_bits;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* How many longwords for "nr" bits?
|
|
|
|
*/
|
|
|
|
#define FDS_BITPERLONG (8*sizeof(long))
|
|
|
|
#define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
|
|
|
|
#define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do a VERIFY_WRITE here even though we are only reading this time:
|
|
|
|
* we'll write to it eventually..
|
|
|
|
*
|
|
|
|
* Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
|
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
int get_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
|
|
|
|
{
|
|
|
|
nr = FDS_BYTES(nr);
|
|
|
|
if (ufdset)
|
|
|
|
return copy_from_user(fdset, ufdset, nr) ? -EFAULT : 0;
|
|
|
|
|
|
|
|
memset(fdset, 0, nr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long __must_check
|
|
|
|
set_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
|
|
|
|
{
|
|
|
|
if (ufdset)
|
|
|
|
return __copy_to_user(ufdset, fdset, FDS_BYTES(nr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
void zero_fd_set(unsigned long nr, unsigned long *fdset)
|
|
|
|
{
|
|
|
|
memset(fdset, 0, FDS_BYTES(nr));
|
|
|
|
}
|
|
|
|
|
[PATCH] Add pselect/ppoll system call implementation
The following implementation of ppoll() and pselect() system calls
depends on the architecture providing a TIF_RESTORE_SIGMASK flag in the
thread_info.
These system calls have to change the signal mask during their
operation, and signal handlers must be invoked using the new, temporary
signal mask. The old signal mask must be restored either upon successful
exit from the system call, or upon returning from the invoked signal
handler if the system call is interrupted. We can't simply restore the
original signal mask and return to userspace, since the restored signal
mask may actually block the signal which interrupted the system call.
The TIF_RESTORE_SIGMASK flag deals with this by causing the syscall exit
path to trap into do_signal() just as TIF_SIGPENDING does, and by
causing do_signal() to use the saved signal mask instead of the current
signal mask when setting up the stack frame for the signal handler -- or
by causing do_signal() to simply restore the saved signal mask in the
case where there is no handler to be invoked.
The first patch implements the sys_pselect() and sys_ppoll() system
calls, which are present only if TIF_RESTORE_SIGMASK is defined. That
#ifdef should go away in time when all architectures have implemented
it. The second patch implements TIF_RESTORE_SIGMASK for the PowerPC
kernel (in the -mm tree), and the third patch then removes the
arch-specific implementations of sys_rt_sigsuspend() and replaces them
with generic versions using the same trick.
The fourth and fifth patches, provided by David Howells, implement
TIF_RESTORE_SIGMASK for FR-V and i386 respectively, and the sixth patch
adds the syscalls to the i386 syscall table.
This patch:
Add the pselect() and ppoll() system calls, providing core routines usable by
the original select() and poll() system calls and also the new calls (with
their semantics w.r.t timeouts).
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Cc: Michael Kerrisk <mtk-manpages@gmx.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 18:44:05 -07:00
|
|
|
#define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1)
|
|
|
|
|
|
|
|
extern int do_select(int n, fd_set_bits *fds, s64 *timeout);
|
|
|
|
extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds,
|
|
|
|
s64 *timeout);
|
2008-04-23 12:05:15 -06:00
|
|
|
extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
|
|
|
|
fd_set __user *exp, s64 *timeout);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#endif /* KERNEL */
|
|
|
|
|
|
|
|
#endif /* _LINUX_POLL_H */
|