thread_info.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include <linux/restart_block.h>
  11. #ifdef CONFIG_THREAD_INFO_IN_TASK
  12. /*
  13. * For CONFIG_THREAD_INFO_IN_TASK kernels we need <asm/current.h> for the
  14. * definition of current, but for !CONFIG_THREAD_INFO_IN_TASK kernels,
  15. * including <asm/current.h> can cause a circular dependency on some platforms.
  16. */
  17. #include <asm/current.h>
  18. #define current_thread_info() ((struct thread_info *)current)
  19. #endif
  20. #include <linux/bitops.h>
  21. #include <asm/thread_info.h>
  22. #ifdef __KERNEL__
  23. #ifdef CONFIG_DEBUG_STACK_USAGE
  24. # define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | \
  25. __GFP_ZERO)
  26. #else
  27. # define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
  28. #endif
  29. /*
  30. * flag set/clear/test wrappers
  31. * - pass TIF_xxxx constants to these functions
  32. */
  33. static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
  34. {
  35. set_bit(flag, (unsigned long *)&ti->flags);
  36. }
  37. static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
  38. {
  39. clear_bit(flag, (unsigned long *)&ti->flags);
  40. }
  41. static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
  42. {
  43. return test_and_set_bit(flag, (unsigned long *)&ti->flags);
  44. }
  45. static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
  46. {
  47. return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
  48. }
  49. static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  50. {
  51. return test_bit(flag, (unsigned long *)&ti->flags);
  52. }
  53. #define set_thread_flag(flag) \
  54. set_ti_thread_flag(current_thread_info(), flag)
  55. #define clear_thread_flag(flag) \
  56. clear_ti_thread_flag(current_thread_info(), flag)
  57. #define test_and_set_thread_flag(flag) \
  58. test_and_set_ti_thread_flag(current_thread_info(), flag)
  59. #define test_and_clear_thread_flag(flag) \
  60. test_and_clear_ti_thread_flag(current_thread_info(), flag)
  61. #define test_thread_flag(flag) \
  62. test_ti_thread_flag(current_thread_info(), flag)
  63. #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  64. #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
  65. static inline int arch_within_stack_frames(const void * const stack,
  66. const void * const stackend,
  67. const void *obj, unsigned long len)
  68. {
  69. return 0;
  70. }
  71. #endif
  72. #ifdef CONFIG_HARDENED_USERCOPY
  73. extern void __check_object_size(const void *ptr, unsigned long n,
  74. bool to_user);
  75. static __always_inline void check_object_size(const void *ptr, unsigned long n,
  76. bool to_user)
  77. {
  78. if (!__builtin_constant_p(n))
  79. __check_object_size(ptr, n, to_user);
  80. }
  81. #else
  82. static inline void check_object_size(const void *ptr, unsigned long n,
  83. bool to_user)
  84. { }
  85. #endif /* CONFIG_HARDENED_USERCOPY */
  86. #endif /* __KERNEL__ */
  87. #endif /* _LINUX_THREAD_INFO_H */