thread_info.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #ifdef CONFIG_DEBUG_STACK_USAGE
  50. # define THREADINFO_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
  51. #else
  52. # define THREADINFO_GFP (GFP_KERNEL | __GFP_NOTRACK)
  53. #endif
  54. /*
  55. * flag set/clear/test wrappers
  56. * - pass TIF_xxxx constants to these functions
  57. */
  58. static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
  59. {
  60. set_bit(flag, (unsigned long *)&ti->flags);
  61. }
  62. static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
  63. {
  64. clear_bit(flag, (unsigned long *)&ti->flags);
  65. }
  66. static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
  67. {
  68. return test_and_set_bit(flag, (unsigned long *)&ti->flags);
  69. }
  70. static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
  71. {
  72. return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
  73. }
  74. static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  75. {
  76. return test_bit(flag, (unsigned long *)&ti->flags);
  77. }
  78. #define set_thread_flag(flag) \
  79. set_ti_thread_flag(current_thread_info(), flag)
  80. #define clear_thread_flag(flag) \
  81. clear_ti_thread_flag(current_thread_info(), flag)
  82. #define test_and_set_thread_flag(flag) \
  83. test_and_set_ti_thread_flag(current_thread_info(), flag)
  84. #define test_and_clear_thread_flag(flag) \
  85. test_and_clear_ti_thread_flag(current_thread_info(), flag)
  86. #define test_thread_flag(flag) \
  87. test_ti_thread_flag(current_thread_info(), flag)
  88. #define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
  89. #define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
  90. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  91. /*
  92. * An arch can define its own version of set_restore_sigmask() to get the
  93. * job done however works, with or without TIF_RESTORE_SIGMASK.
  94. */
  95. #define HAVE_SET_RESTORE_SIGMASK 1
  96. /**
  97. * set_restore_sigmask() - make sure saved_sigmask processing gets done
  98. *
  99. * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
  100. * will run before returning to user mode, to process the flag. For
  101. * all callers, TIF_SIGPENDING is already set or it's no harm to set
  102. * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
  103. * arch code will notice on return to user mode, in case those bits
  104. * are scarce. We set TIF_SIGPENDING here to ensure that the arch
  105. * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  106. */
  107. static inline void set_restore_sigmask(void)
  108. {
  109. set_thread_flag(TIF_RESTORE_SIGMASK);
  110. set_thread_flag(TIF_SIGPENDING);
  111. }
  112. #endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
  113. #endif /* __KERNEL__ */
  114. #endif /* _LINUX_THREAD_INFO_H */