thread_info.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* thread_info.h: common low-level thread information accessors
  2. *
  3. * Copyright (C) 2002 David Howells (dhowells@redhat.com)
  4. * - Incorporating suggestions made by Linus Torvalds
  5. */
  6. #ifndef _LINUX_THREAD_INFO_H
  7. #define _LINUX_THREAD_INFO_H
  8. #include <linux/types.h>
  9. struct timespec;
  10. struct compat_timespec;
  11. /*
  12. * System call restart block.
  13. */
  14. struct restart_block {
  15. long (*fn)(struct restart_block *);
  16. union {
  17. /* For futex_wait and futex_wait_requeue_pi */
  18. struct {
  19. u32 __user *uaddr;
  20. u32 val;
  21. u32 flags;
  22. u32 bitset;
  23. u64 time;
  24. u32 __user *uaddr2;
  25. } futex;
  26. /* For nanosleep */
  27. struct {
  28. clockid_t clockid;
  29. struct timespec __user *rmtp;
  30. #ifdef CONFIG_COMPAT
  31. struct compat_timespec __user *compat_rmtp;
  32. #endif
  33. u64 expires;
  34. } nanosleep;
  35. /* For poll */
  36. struct {
  37. struct pollfd __user *ufds;
  38. int nfds;
  39. int has_timeout;
  40. unsigned long tv_sec;
  41. unsigned long tv_nsec;
  42. } poll;
  43. };
  44. };
  45. extern long do_no_restart_syscall(struct restart_block *parm);
  46. #include <linux/bitops.h>
  47. #include <asm/thread_info.h>
  48. #ifdef __KERNEL__
  49. /*
  50. * flag set/clear/test wrappers
  51. * - pass TIF_xxxx constants to these functions
  52. */
  53. static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
  54. {
  55. set_bit(flag, (unsigned long *)&ti->flags);
  56. }
  57. static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
  58. {
  59. clear_bit(flag, (unsigned long *)&ti->flags);
  60. }
  61. static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
  62. {
  63. return test_and_set_bit(flag, (unsigned long *)&ti->flags);
  64. }
  65. static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
  66. {
  67. return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
  68. }
  69. static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  70. {
  71. return test_bit(flag, (unsigned long *)&ti->flags);
  72. }
  73. #define set_thread_flag(flag) \
  74. set_ti_thread_flag(current_thread_info(), flag)
  75. #define clear_thread_flag(flag) \
  76. clear_ti_thread_flag(current_thread_info(), flag)
  77. #define test_and_set_thread_flag(flag) \
  78. test_and_set_ti_thread_flag(current_thread_info(), flag)
  79. #define test_and_clear_thread_flag(flag) \
  80. test_and_clear_ti_thread_flag(current_thread_info(), flag)
  81. #define test_thread_flag(flag) \
  82. test_ti_thread_flag(current_thread_info(), flag)
  83. #define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
  84. #define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
  85. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  86. /*
  87. * An arch can define its own version of set_restore_sigmask() to get the
  88. * job done however works, with or without TIF_RESTORE_SIGMASK.
  89. */
  90. #define HAVE_SET_RESTORE_SIGMASK 1
  91. /**
  92. * set_restore_sigmask() - make sure saved_sigmask processing gets done
  93. *
  94. * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
  95. * will run before returning to user mode, to process the flag. For
  96. * all callers, TIF_SIGPENDING is already set or it's no harm to set
  97. * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
  98. * arch code will notice on return to user mode, in case those bits
  99. * are scarce. We set TIF_SIGPENDING here to ensure that the arch
  100. * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  101. */
  102. static inline void set_restore_sigmask(void)
  103. {
  104. set_thread_flag(TIF_RESTORE_SIGMASK);
  105. set_thread_flag(TIF_SIGPENDING);
  106. }
  107. #endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
  108. #endif /* __KERNEL__ */
  109. #endif /* _LINUX_THREAD_INFO_H */