1 /* thread_info.h: common low-level thread information accessors
3 * Copyright (C) 2002 David Howells (dhowells@redhat.com)
4 * - Incorporating suggestions made by Linus Torvalds
7 #ifndef _LINUX_THREAD_INFO_H
8 #define _LINUX_THREAD_INFO_H
10 #include <linux/types.h>
11 #include <linux/bug.h>
12 #include <linux/restart_block.h>
14 #ifdef CONFIG_THREAD_INFO_IN_TASK
16 struct compat_timespec;
19 * For CONFIG_THREAD_INFO_IN_TASK kernels we need <asm/current.h> for the
20 * definition of current, but for !CONFIG_THREAD_INFO_IN_TASK kernels,
21 * including <asm/current.h> can cause a circular dependency on some platforms.
23 #include <asm/current.h>
24 #define current_thread_info() ((struct thread_info *)current)
27 #include <linux/bitops.h>
28 #include <asm/thread_info.h>
32 #define THREADINFO_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
35 * flag set/clear/test wrappers
36 * - pass TIF_xxxx constants to these functions
39 static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
41 set_bit(flag, (unsigned long *)&ti->flags);
44 static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
46 clear_bit(flag, (unsigned long *)&ti->flags);
49 static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
51 return test_and_set_bit(flag, (unsigned long *)&ti->flags);
54 static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
56 return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
59 static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
61 return test_bit(flag, (unsigned long *)&ti->flags);
64 #define set_thread_flag(flag) \
65 set_ti_thread_flag(current_thread_info(), flag)
66 #define clear_thread_flag(flag) \
67 clear_ti_thread_flag(current_thread_info(), flag)
68 #define test_and_set_thread_flag(flag) \
69 test_and_set_ti_thread_flag(current_thread_info(), flag)
70 #define test_and_clear_thread_flag(flag) \
71 test_and_clear_ti_thread_flag(current_thread_info(), flag)
72 #define test_thread_flag(flag) \
73 test_ti_thread_flag(current_thread_info(), flag)
75 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
77 #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
79 * An arch can define its own version of set_restore_sigmask() to get the
80 * job done however works, with or without TIF_RESTORE_SIGMASK.
82 #define HAVE_SET_RESTORE_SIGMASK 1
85 * set_restore_sigmask() - make sure saved_sigmask processing gets done
87 * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
88 * will run before returning to user mode, to process the flag. For
89 * all callers, TIF_SIGPENDING is already set or it's no harm to set
90 * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
91 * arch code will notice on return to user mode, in case those bits
92 * are scarce. We set TIF_SIGPENDING here to ensure that the arch
93 * signal code always gets run when TIF_RESTORE_SIGMASK is set.
95 static inline void set_restore_sigmask(void)
97 set_thread_flag(TIF_RESTORE_SIGMASK);
98 WARN_ON(!test_thread_flag(TIF_SIGPENDING));
100 static inline void clear_restore_sigmask(void)
102 clear_thread_flag(TIF_RESTORE_SIGMASK);
104 static inline bool test_restore_sigmask(void)
106 return test_thread_flag(TIF_RESTORE_SIGMASK);
108 static inline bool test_and_clear_restore_sigmask(void)
110 return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
112 #endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
114 #ifndef HAVE_SET_RESTORE_SIGMASK
115 #error "no set_restore_sigmask() provided and default one won't work"
118 #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
119 static inline int arch_within_stack_frames(const void * const stack,
120 const void * const stackend,
121 const void *obj, unsigned long len)
127 #ifdef CONFIG_HARDENED_USERCOPY
128 extern void __check_object_size(const void *ptr, unsigned long n,
131 static __always_inline void check_object_size(const void *ptr, unsigned long n,
134 if (!__builtin_constant_p(n))
135 __check_object_size(ptr, n, to_user);
138 static inline void check_object_size(const void *ptr, unsigned long n,
141 #endif /* CONFIG_HARDENED_USERCOPY */
143 #endif /* __KERNEL__ */
145 #endif /* _LINUX_THREAD_INFO_H */