blob: 8e8f6098508aca2992e6402f12e83087d3846757 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_POLL_H
2#define _LINUX_POLL_H
3
4#include <asm/poll.h>
5
6#ifdef __KERNEL__
7
8#include <linux/compiler.h>
9#include <linux/wait.h>
10#include <linux/string.h>
11#include <linux/mm.h>
12#include <asm/uaccess.h>
13
14struct poll_table_struct;
15
16/*
17 * structures and helpers for f_op->poll implementations
18 */
19typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
20
21typedef struct poll_table_struct {
22 poll_queue_proc qproc;
23} poll_table;
24
25static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
26{
27 if (p && wait_address)
28 p->qproc(filp, wait_address, p);
29}
30
31static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc)
32{
33 pt->qproc = qproc;
34}
35
36/*
37 * Structures and helpers for sys_poll/sys_poll
38 */
39struct poll_wqueues {
40 poll_table pt;
41 struct poll_table_page * table;
42 int error;
43};
44
45extern void poll_initwait(struct poll_wqueues *pwq);
46extern void poll_freewait(struct poll_wqueues *pwq);
47
48/*
49 * Scaleable version of the fd_set.
50 */
51
52typedef struct {
53 unsigned long *in, *out, *ex;
54 unsigned long *res_in, *res_out, *res_ex;
55} fd_set_bits;
56
57/*
58 * How many longwords for "nr" bits?
59 */
60#define FDS_BITPERLONG (8*sizeof(long))
61#define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
62#define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long))
63
64/*
65 * We do a VERIFY_WRITE here even though we are only reading this time:
66 * we'll write to it eventually..
67 *
68 * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
69 */
70static inline
71int get_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
72{
73 nr = FDS_BYTES(nr);
74 if (ufdset)
75 return copy_from_user(fdset, ufdset, nr) ? -EFAULT : 0;
76
77 memset(fdset, 0, nr);
78 return 0;
79}
80
81static inline unsigned long __must_check
82set_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
83{
84 if (ufdset)
85 return __copy_to_user(ufdset, fdset, FDS_BYTES(nr));
86 return 0;
87}
88
89static inline
90void zero_fd_set(unsigned long nr, unsigned long *fdset)
91{
92 memset(fdset, 0, FDS_BYTES(nr));
93}
94
David Woodhouse9f729492006-01-18 17:44:05 -080095#define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1)
96
97extern int do_select(int n, fd_set_bits *fds, s64 *timeout);
98extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds,
99 s64 *timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#endif /* KERNEL */
102
103#endif /* _LINUX_POLL_H */