poll.h 2.1 KB

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