thread_info.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #define THREADINFO_GFP_ACCOUNTED (THREADINFO_GFP | __GFP_KMEMCG)
  56. /*
  57. * flag set/clear/test wrappers
  58. * - pass TIF_xxxx constants to these functions
  59. */
  60. static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
  61. {
  62. set_bit(flag, (unsigned long *)&ti->flags);
  63. }
  64. static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
  65. {
  66. clear_bit(flag, (unsigned long *)&ti->flags);
  67. }
  68. static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
  69. {
  70. return test_and_set_bit(flag, (unsigned long *)&ti->flags);
  71. }
  72. static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
  73. {
  74. return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
  75. }
  76. static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  77. {
  78. return test_bit(flag, (unsigned long *)&ti->flags);
  79. }
  80. #define set_thread_flag(flag) \
  81. set_ti_thread_flag(current_thread_info(), flag)
  82. #define clear_thread_flag(flag) \
  83. clear_ti_thread_flag(current_thread_info(), flag)
  84. #define test_and_set_thread_flag(flag) \
  85. test_and_set_ti_thread_flag(current_thread_info(), flag)
  86. #define test_and_clear_thread_flag(flag) \
  87. test_and_clear_ti_thread_flag(current_thread_info(), flag)
  88. #define test_thread_flag(flag) \
  89. test_ti_thread_flag(current_thread_info(), flag)
  90. static inline __deprecated void set_need_resched(void)
  91. {
  92. /*
  93. * Use of this function in deprecated.
  94. *
  95. * As of this writing there are only a few users in the DRM tree left
  96. * all of which are wrong and can be removed without causing too much
  97. * grief.
  98. *
  99. * The DRM people are aware and are working on removing the last few
  100. * instances.
  101. */
  102. }
  103. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  104. /*
  105. * An arch can define its own version of set_restore_sigmask() to get the
  106. * job done however works, with or without TIF_RESTORE_SIGMASK.
  107. */
  108. #define HAVE_SET_RESTORE_SIGMASK 1
  109. /**
  110. * set_restore_sigmask() - make sure saved_sigmask processing gets done
  111. *
  112. * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
  113. * will run before returning to user mode, to process the flag. For
  114. * all callers, TIF_SIGPENDING is already set or it's no harm to set
  115. * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
  116. * arch code will notice on return to user mode, in case those bits
  117. * are scarce. We set TIF_SIGPENDING here to ensure that the arch
  118. * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  119. */
  120. static inline void set_restore_sigmask(void)
  121. {
  122. set_thread_flag(TIF_RESTORE_SIGMASK);
  123. WARN_ON(!test_thread_flag(TIF_SIGPENDING));
  124. }
  125. static inline void clear_restore_sigmask(void)
  126. {
  127. clear_thread_flag(TIF_RESTORE_SIGMASK);
  128. }
  129. static inline bool test_restore_sigmask(void)
  130. {
  131. return test_thread_flag(TIF_RESTORE_SIGMASK);
  132. }
  133. static inline bool test_and_clear_restore_sigmask(void)
  134. {
  135. return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
  136. }
  137. #endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
  138. #ifndef HAVE_SET_RESTORE_SIGMASK
  139. #error "no set_restore_sigmask() provided and default one won't work"
  140. #endif
  141. #endif /* __KERNEL__ */
  142. #endif /* _LINUX_THREAD_INFO_H */