thread_info.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #include <linux/bug.h>
  10. struct timespec;
  11. struct compat_timespec;
  12. /*
  13. * System call restart block.
  14. */
  15. struct restart_block {
  16. long (*fn)(struct restart_block *);
  17. union {
  18. /* For futex_wait and futex_wait_requeue_pi */
  19. struct {
  20. u32 __user *uaddr;
  21. u32 val;
  22. u32 flags;
  23. u32 bitset;
  24. u64 time;
  25. u32 __user *uaddr2;
  26. } futex;
  27. /* For nanosleep */
  28. struct {
  29. clockid_t clockid;
  30. struct timespec __user *rmtp;
  31. #ifdef CONFIG_COMPAT
  32. struct compat_timespec __user *compat_rmtp;
  33. #endif
  34. u64 expires;
  35. } nanosleep;
  36. /* For poll */
  37. struct {
  38. struct pollfd __user *ufds;
  39. int nfds;
  40. int has_timeout;
  41. unsigned long tv_sec;
  42. unsigned long tv_nsec;
  43. } poll;
  44. };
  45. };
  46. extern long do_no_restart_syscall(struct restart_block *parm);
  47. #include <linux/bitops.h>
  48. #include <asm/thread_info.h>
  49. #ifdef __KERNEL__
  50. #ifdef CONFIG_DEBUG_STACK_USAGE
  51. # define THREADINFO_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
  52. #else
  53. # define THREADINFO_GFP (GFP_KERNEL | __GFP_NOTRACK)
  54. #endif
  55. /*
  56. * flag set/clear/test wrappers
  57. * - pass TIF_xxxx constants to these functions
  58. */
  59. static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
  60. {
  61. set_bit(flag, (unsigned long *)&ti->flags);
  62. }
  63. static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
  64. {
  65. clear_bit(flag, (unsigned long *)&ti->flags);
  66. }
  67. static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
  68. {
  69. return test_and_set_bit(flag, (unsigned long *)&ti->flags);
  70. }
  71. static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
  72. {
  73. return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
  74. }
  75. static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  76. {
  77. return test_bit(flag, (unsigned long *)&ti->flags);
  78. }
  79. #define set_thread_flag(flag) \
  80. set_ti_thread_flag(current_thread_info(), flag)
  81. #define clear_thread_flag(flag) \
  82. clear_ti_thread_flag(current_thread_info(), flag)
  83. #define test_and_set_thread_flag(flag) \
  84. test_and_set_ti_thread_flag(current_thread_info(), flag)
  85. #define test_and_clear_thread_flag(flag) \
  86. test_and_clear_ti_thread_flag(current_thread_info(), flag)
  87. #define test_thread_flag(flag) \
  88. test_ti_thread_flag(current_thread_info(), flag)
  89. #define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
  90. #define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
  91. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  92. /*
  93. * An arch can define its own version of set_restore_sigmask() to get the
  94. * job done however works, with or without TIF_RESTORE_SIGMASK.
  95. */
  96. #define HAVE_SET_RESTORE_SIGMASK 1
  97. /**
  98. * set_restore_sigmask() - make sure saved_sigmask processing gets done
  99. *
  100. * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
  101. * will run before returning to user mode, to process the flag. For
  102. * all callers, TIF_SIGPENDING is already set or it's no harm to set
  103. * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
  104. * arch code will notice on return to user mode, in case those bits
  105. * are scarce. We set TIF_SIGPENDING here to ensure that the arch
  106. * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  107. */
  108. static inline void set_restore_sigmask(void)
  109. {
  110. set_thread_flag(TIF_RESTORE_SIGMASK);
  111. WARN_ON(!test_thread_flag(TIF_SIGPENDING));
  112. }
  113. static inline void clear_restore_sigmask(void)
  114. {
  115. clear_thread_flag(TIF_RESTORE_SIGMASK);
  116. }
  117. static inline bool test_restore_sigmask(void)
  118. {
  119. return test_thread_flag(TIF_RESTORE_SIGMASK);
  120. }
  121. static inline bool test_and_clear_restore_sigmask(void)
  122. {
  123. return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
  124. }
  125. #endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
  126. #ifndef HAVE_SET_RESTORE_SIGMASK
  127. #error "no set_restore_sigmask() provided and default one won't work"
  128. #endif
  129. #endif /* __KERNEL__ */
  130. #endif /* _LINUX_THREAD_INFO_H */