vserver 2.0 rc7
[linux-2.6.git] / include / linux / poll.h
1 #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
14 struct poll_table_struct;
15
16 /* 
17  * structures and helpers for f_op->poll implementations
18  */
19 typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
20
21 typedef struct poll_table_struct {
22         poll_queue_proc qproc;
23 } poll_table;
24
25 static 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
31 static 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  */
39 struct poll_wqueues {
40         poll_table pt;
41         struct poll_table_page * table;
42         int error;
43 };
44
45 extern void poll_initwait(struct poll_wqueues *pwq);
46 extern void poll_freewait(struct poll_wqueues *pwq);
47
48 /*
49  * Scaleable version of the fd_set.
50  */
51
52 typedef 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  */
70 static inline
71 int 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
81 static inline unsigned long __must_check
82 set_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
89 static inline
90 void zero_fd_set(unsigned long nr, unsigned long *fdset)
91 {
92         memset(fdset, 0, FDS_BYTES(nr));
93 }
94
95 extern int do_select(int n, fd_set_bits *fds, long *timeout);
96
97 #endif /* KERNEL */
98
99 #endif /* _LINUX_POLL_H */