thread_info.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifdef CONFIG_THREAD_INFO_IN_TASK
  13. #define current_thread_info() ((struct thread_info *)current)
  14. #endif
  15. /*
  16. * System call restart block.
  17. */
  18. struct restart_block {
  19. long (*fn)(struct restart_block *);
  20. union {
  21. /* For futex_wait and futex_wait_requeue_pi */
  22. struct {
  23. u32 __user *uaddr;
  24. u32 val;
  25. u32 flags;
  26. u32 bitset;
  27. u64 time;
  28. u32 __user *uaddr2;
  29. } futex;
  30. /* For nanosleep */
  31. struct {
  32. clockid_t clockid;
  33. struct timespec __user *rmtp;
  34. #ifdef CONFIG_COMPAT
  35. struct compat_timespec __user *compat_rmtp;
  36. #endif
  37. u64 expires;
  38. } nanosleep;
  39. /* For poll */
  40. struct {
  41. struct pollfd __user *ufds;
  42. int nfds;
  43. int has_timeout;
  44. unsigned long tv_sec;
  45. unsigned long tv_nsec;
  46. } poll;
  47. };
  48. };
  49. extern long do_no_restart_syscall(struct restart_block *parm);
  50. #include <linux/bitops.h>
  51. #include <asm/thread_info.h>
  52. #ifdef __KERNEL__
  53. #ifdef CONFIG_DEBUG_STACK_USAGE
  54. # define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | \
  55. __GFP_ZERO)
  56. #else
  57. # define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
  58. #endif
  59. /*
  60. * flag set/clear/test wrappers
  61. * - pass TIF_xxxx constants to these functions
  62. */
  63. static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
  64. {
  65. set_bit(flag, (unsigned long *)&ti->flags);
  66. }
  67. static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
  68. {
  69. clear_bit(flag, (unsigned long *)&ti->flags);
  70. }
  71. static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
  72. {
  73. return test_and_set_bit(flag, (unsigned long *)&ti->flags);
  74. }
  75. static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
  76. {
  77. return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
  78. }
  79. static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  80. {
  81. return test_bit(flag, (unsigned long *)&ti->flags);
  82. }
  83. #define set_thread_flag(flag) \
  84. set_ti_thread_flag(current_thread_info(), flag)
  85. #define clear_thread_flag(flag) \
  86. clear_ti_thread_flag(current_thread_info(), flag)
  87. #define test_and_set_thread_flag(flag) \
  88. test_and_set_ti_thread_flag(current_thread_info(), flag)
  89. #define test_and_clear_thread_flag(flag) \
  90. test_and_clear_ti_thread_flag(current_thread_info(), flag)
  91. #define test_thread_flag(flag) \
  92. test_ti_thread_flag(current_thread_info(), flag)
  93. #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  94. #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
  95. static inline int arch_within_stack_frames(const void * const stack,
  96. const void * const stackend,
  97. const void *obj, unsigned long len)
  98. {
  99. return 0;
  100. }
  101. #endif
  102. #ifdef CONFIG_HARDENED_USERCOPY
  103. extern void __check_object_size(const void *ptr, unsigned long n,
  104. bool to_user);
  105. static __always_inline void check_object_size(const void *ptr, unsigned long n,
  106. bool to_user)
  107. {
  108. if (!__builtin_constant_p(n))
  109. __check_object_size(ptr, n, to_user);
  110. }
  111. #else
  112. static inline void check_object_size(const void *ptr, unsigned long n,
  113. bool to_user)
  114. { }
  115. #endif /* CONFIG_HARDENED_USERCOPY */
  116. #endif /* __KERNEL__ */
  117. #endif /* _LINUX_THREAD_INFO_H */