2005-04-17 05:20:36 +07:00
|
|
|
#ifndef _LINUX_POLL_H
|
|
|
|
#define _LINUX_POLL_H
|
|
|
|
|
|
|
|
#include <asm/poll.h>
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
2009-10-04 19:11:37 +07:00
|
|
|
#include <linux/ktime.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/string.h>
|
2006-10-21 02:17:02 +07:00
|
|
|
#include <linux/fs.h>
|
2010-03-11 06:24:10 +07:00
|
|
|
#include <linux/sysctl.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
2010-03-11 06:24:10 +07:00
|
|
|
extern struct ctl_table epoll_table[]; /* for sysctl */
|
2006-03-28 16: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-12 05:23:55 +07:00
|
|
|
#define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
|
|
|
|
|
2005-04-17 05:20:36 +07: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;
|
2009-06-17 05:33:36 +07:00
|
|
|
unsigned long key;
|
2005-04-17 05:20:36 +07:00
|
|
|
} 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;
|
2009-06-17 05:33:36 +07:00
|
|
|
pt->key = ~0UL; /* all events enabled */
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-03-28 16:56:33 +07:00
|
|
|
struct poll_table_entry {
|
2009-01-07 05:40:59 +07:00
|
|
|
struct file *filp;
|
2009-06-17 05:33:36 +07:00
|
|
|
unsigned long key;
|
2006-03-28 16:56:33 +07:00
|
|
|
wait_queue_t wait;
|
2009-01-07 05:40:59 +07:00
|
|
|
wait_queue_head_t *wait_address;
|
2006-03-28 16:56:33 +07:00
|
|
|
};
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Structures and helpers for sys_poll/sys_poll
|
|
|
|
*/
|
|
|
|
struct poll_wqueues {
|
|
|
|
poll_table pt;
|
2009-01-07 05:40:59 +07:00
|
|
|
struct poll_table_page *table;
|
|
|
|
struct task_struct *polling_task;
|
|
|
|
int triggered;
|
2005-04-17 05:20:36 +07:00
|
|
|
int error;
|
2006-03-28 16:56:33 +07:00
|
|
|
int inline_index;
|
|
|
|
struct poll_table_entry inline_entries[N_INLINE_POLL_ENTRIES];
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
extern void poll_initwait(struct poll_wqueues *pwq);
|
|
|
|
extern void poll_freewait(struct poll_wqueues *pwq);
|
2009-01-07 05:40:59 +07:00
|
|
|
extern int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
|
|
|
|
ktime_t *expires, unsigned long slack);
|
|
|
|
|
|
|
|
static inline int poll_schedule(struct poll_wqueues *pwq, int state)
|
|
|
|
{
|
|
|
|
return poll_schedule_timeout(pwq, state, NULL, 0);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-19 08:44:05 +07:00
|
|
|
#define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1)
|
|
|
|
|
2008-08-31 22:26:40 +07:00
|
|
|
extern int do_select(int n, fd_set_bits *fds, struct timespec *end_time);
|
[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-19 08:44:05 +07:00
|
|
|
extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds,
|
2008-08-31 22:26:40 +07:00
|
|
|
struct timespec *end_time);
|
2008-04-24 01:05:15 +07:00
|
|
|
extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
|
2008-08-31 22:26:40 +07:00
|
|
|
fd_set __user *exp, struct timespec *end_time);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-08-31 22:16:57 +07:00
|
|
|
extern int poll_select_set_timeout(struct timespec *to, long sec, long nsec);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* KERNEL */
|
|
|
|
|
|
|
|
#endif /* _LINUX_POLL_H */
|