Blame view

include/linux/poll.h 4.49 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  #ifndef _LINUX_POLL_H
  #define _LINUX_POLL_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
  
  #include <linux/compiler.h>
a99bbaf5e   Alexey Dobriyan   headers: remove s...
5
  #include <linux/ktime.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
  #include <linux/wait.h>
  #include <linux/string.h>
f23f6e08c   Al Viro   [PATCH] severing ...
8
  #include <linux/fs.h>
9ff993394   Dave Young   sysctl extern cle...
9
  #include <linux/sysctl.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  #include <asm/uaccess.h>
607ca46e9   David Howells   UAPI: (Scripted) ...
11
  #include <uapi/linux/poll.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12

9ff993394   Dave Young   sysctl extern cle...
13
  extern struct ctl_table epoll_table[]; /* for sysctl */
70674f95c   Andi Kleen   [PATCH] Optimize ...
14
15
16
17
18
19
20
21
  /* ~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))
dd23aae4f   Alexey Dobriyan   Fix select on /pr...
22
  #define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
27
28
  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 *);
626cf2366   Hans Verkuil   poll: add poll_re...
29
30
31
32
  /*
   * Do not touch the structure directly, use the access functions
   * poll_does_not_wait() and poll_requested_events() instead.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
  typedef struct poll_table_struct {
626cf2366   Hans Verkuil   poll: add poll_re...
34
35
  	poll_queue_proc _qproc;
  	unsigned long _key;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
  } poll_table;
  
  static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
  {
626cf2366   Hans Verkuil   poll: add poll_re...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  	if (p && p->_qproc && wait_address)
  		p->_qproc(filp, wait_address, p);
  }
  
  /*
   * Return true if it is guaranteed that poll will not wait. This is the case
   * if the poll() of another file descriptor in the set got an event, so there
   * is no need for waiting.
   */
  static inline bool poll_does_not_wait(const poll_table *p)
  {
  	return p == NULL || p->_qproc == NULL;
  }
  
  /*
   * Return the set of events that the application wants to poll for.
   * This is useful for drivers that need to know whether a DMA transfer has
   * to be started implicitly on poll(). You typically only want to do that
   * if the application is actually polling for POLLIN and/or POLLOUT.
   */
  static inline unsigned long poll_requested_events(const poll_table *p)
  {
  	return p ? p->_key : ~0UL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
66
  }
  
  static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc)
  {
626cf2366   Hans Verkuil   poll: add poll_re...
67
68
  	pt->_qproc = qproc;
  	pt->_key   = ~0UL; /* all events enabled */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  }
70674f95c   Andi Kleen   [PATCH] Optimize ...
70
  struct poll_table_entry {
5f820f648   Tejun Heo   poll: allow f_op-...
71
  	struct file *filp;
4938d7e02   Eric Dumazet   poll: avoid extra...
72
  	unsigned long key;
70674f95c   Andi Kleen   [PATCH] Optimize ...
73
  	wait_queue_t wait;
5f820f648   Tejun Heo   poll: allow f_op-...
74
  	wait_queue_head_t *wait_address;
70674f95c   Andi Kleen   [PATCH] Optimize ...
75
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  /*
dac36dd87   Namhyung Kim   poll: fix a typo ...
77
   * Structures and helpers for select/poll syscall
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
   */
  struct poll_wqueues {
  	poll_table pt;
5f820f648   Tejun Heo   poll: allow f_op-...
81
82
83
  	struct poll_table_page *table;
  	struct task_struct *polling_task;
  	int triggered;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
  	int error;
70674f95c   Andi Kleen   [PATCH] Optimize ...
85
86
  	int inline_index;
  	struct poll_table_entry inline_entries[N_INLINE_POLL_ENTRIES];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
89
90
  };
  
  extern void poll_initwait(struct poll_wqueues *pwq);
  extern void poll_freewait(struct poll_wqueues *pwq);
5f820f648   Tejun Heo   poll: allow f_op-...
91
92
  extern int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
  				 ktime_t *expires, unsigned long slack);
766b9f928   Deepa Dinamani   fs: poll/select/r...
93
  extern u64 select_estimate_accuracy(struct timespec64 *tv);
95aac7b1c   Shawn Bohrer   epoll: make epoll...
94

5f820f648   Tejun Heo   poll: allow f_op-...
95
96
97
98
99
  
  static inline int poll_schedule(struct poll_wqueues *pwq, int state)
  {
  	return poll_schedule_timeout(pwq, state, NULL, 0);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
  
  /*
25985edce   Lucas De Marchi   Fix common misspe...
102
   * Scalable version of the fd_set.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
   */
  
  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));
  }
9f72949f6   David Woodhouse   [PATCH] Add psele...
147
  #define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1)
766b9f928   Deepa Dinamani   fs: poll/select/r...
148
  extern int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time);
9f72949f6   David Woodhouse   [PATCH] Add psele...
149
  extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds,
766b9f928   Deepa Dinamani   fs: poll/select/r...
150
  		       struct timespec64 *end_time);
a2dcb44c3   Al Viro   [PATCH] make osf_...
151
  extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
766b9f928   Deepa Dinamani   fs: poll/select/r...
152
  			   fd_set __user *exp, struct timespec64 *end_time);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153

766b9f928   Deepa Dinamani   fs: poll/select/r...
154
155
  extern int poll_select_set_timeout(struct timespec64 *to, time64_t sec,
  				   long nsec);
b773ad40a   Thomas Gleixner   select: add poll_...
156

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
  #endif /* _LINUX_POLL_H */