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/errno.h>
15 struct compat_timespec;
17 #ifdef CONFIG_THREAD_INFO_IN_TASK
18 #define current_thread_info() ((struct thread_info *)current)
22 * System call restart block.
24 struct restart_block {
25 long (*fn)(struct restart_block *);
27 /* For futex_wait and futex_wait_requeue_pi */
39 struct timespec __user *rmtp;
41 struct compat_timespec __user *compat_rmtp;
47 struct pollfd __user *ufds;
51 unsigned long tv_nsec;
56 extern long do_no_restart_syscall(struct restart_block *parm);
58 #include <linux/bitops.h>
59 #include <asm/thread_info.h>
63 #ifndef arch_set_restart_data
64 #define arch_set_restart_data(restart) do { } while (0)
67 static inline long set_restart_fn(struct restart_block *restart,
68 long (*fn)(struct restart_block *))
71 arch_set_restart_data(restart);
72 return -ERESTART_RESTARTBLOCK;
75 #define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | __GFP_ZERO)
78 * flag set/clear/test wrappers
79 * - pass TIF_xxxx constants to these functions
82 static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
84 set_bit(flag, (unsigned long *)&ti->flags);
87 static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
89 clear_bit(flag, (unsigned long *)&ti->flags);
92 static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
94 return test_and_set_bit(flag, (unsigned long *)&ti->flags);
97 static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
99 return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
102 static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
104 return test_bit(flag, (unsigned long *)&ti->flags);
107 #define set_thread_flag(flag) \
108 set_ti_thread_flag(current_thread_info(), flag)
109 #define clear_thread_flag(flag) \
110 clear_ti_thread_flag(current_thread_info(), flag)
111 #define test_and_set_thread_flag(flag) \
112 test_and_set_ti_thread_flag(current_thread_info(), flag)
113 #define test_and_clear_thread_flag(flag) \
114 test_and_clear_ti_thread_flag(current_thread_info(), flag)
115 #define test_thread_flag(flag) \
116 test_ti_thread_flag(current_thread_info(), flag)
118 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
120 #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
121 static inline int arch_within_stack_frames(const void * const stack,
122 const void * const stackend,
123 const void *obj, unsigned long len)
129 #ifdef CONFIG_HARDENED_USERCOPY
130 extern void __check_object_size(const void *ptr, unsigned long n,
133 static __always_inline void check_object_size(const void *ptr, unsigned long n,
136 if (!__builtin_constant_p(n))
137 __check_object_size(ptr, n, to_user);
140 static inline void check_object_size(const void *ptr, unsigned long n,
143 #endif /* CONFIG_HARDENED_USERCOPY */
145 #endif /* __KERNEL__ */
147 #endif /* _LINUX_THREAD_INFO_H */