thread_info.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
  91. #define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
  92. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  93. /*
  94. * An arch can define its own version of set_restore_sigmask() to get the
  95. * job done however works, with or without TIF_RESTORE_SIGMASK.
  96. */
  97. #define HAVE_SET_RESTORE_SIGMASK 1
  98. /**
  99. * set_restore_sigmask() - make sure saved_sigmask processing gets done
  100. *
  101. * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
  102. * will run before returning to user mode, to process the flag. For
  103. * all callers, TIF_SIGPENDING is already set or it's no harm to set
  104. * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
  105. * arch code will notice on return to user mode, in case those bits
  106. * are scarce. We set TIF_SIGPENDING here to ensure that the arch
  107. * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  108. */
  109. static inline void set_restore_sigmask(void)
  110. {
  111. set_thread_flag(TIF_RESTORE_SIGMASK);
  112. WARN_ON(!test_thread_flag(TIF_SIGPENDING));
  113. }
  114. static inline void clear_restore_sigmask(void)
  115. {
  116. clear_thread_flag(TIF_RESTORE_SIGMASK);
  117. }
  118. static inline bool test_restore_sigmask(void)
  119. {
  120. return test_thread_flag(TIF_RESTORE_SIGMASK);
  121. }
  122. static inline bool test_and_clear_restore_sigmask(void)
  123. {
  124. return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
  125. }
  126. #endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
  127. #ifndef HAVE_SET_RESTORE_SIGMASK
  128. #error "no set_restore_sigmask() provided and default one won't work"
  129. #endif
  130. #endif /* __KERNEL__ */
  131. #endif /* _LINUX_THREAD_INFO_H */