thread_info.h 3.4 KB

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