GNU Linux-libre 4.9.304-gnu1
[releases.git] / include / linux / thread_info.h
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
7 #ifndef _LINUX_THREAD_INFO_H
8 #define _LINUX_THREAD_INFO_H
9
10 #include <linux/types.h>
11 #include <linux/bug.h>
12 #include <linux/errno.h>
13
14 struct timespec;
15 struct compat_timespec;
16
17 #ifdef CONFIG_THREAD_INFO_IN_TASK
18 #define current_thread_info() ((struct thread_info *)current)
19 #endif
20
21 /*
22  * System call restart block.
23  */
24 struct restart_block {
25         long (*fn)(struct restart_block *);
26         union {
27                 /* For futex_wait and futex_wait_requeue_pi */
28                 struct {
29                         u32 __user *uaddr;
30                         u32 val;
31                         u32 flags;
32                         u32 bitset;
33                         u64 time;
34                         u32 __user *uaddr2;
35                 } futex;
36                 /* For nanosleep */
37                 struct {
38                         clockid_t clockid;
39                         struct timespec __user *rmtp;
40 #ifdef CONFIG_COMPAT
41                         struct compat_timespec __user *compat_rmtp;
42 #endif
43                         u64 expires;
44                 } nanosleep;
45                 /* For poll */
46                 struct {
47                         struct pollfd __user *ufds;
48                         int nfds;
49                         int has_timeout;
50                         unsigned long tv_sec;
51                         unsigned long tv_nsec;
52                 } poll;
53         };
54 };
55
56 extern long do_no_restart_syscall(struct restart_block *parm);
57
58 #include <linux/bitops.h>
59 #include <asm/thread_info.h>
60
61 #ifdef __KERNEL__
62
63 #ifndef arch_set_restart_data
64 #define arch_set_restart_data(restart) do { } while (0)
65 #endif
66
67 static inline long set_restart_fn(struct restart_block *restart,
68                                         long (*fn)(struct restart_block *))
69 {
70         restart->fn = fn;
71         arch_set_restart_data(restart);
72         return -ERESTART_RESTARTBLOCK;
73 }
74
75 #define THREADINFO_GFP  (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | __GFP_ZERO)
76
77 /*
78  * flag set/clear/test wrappers
79  * - pass TIF_xxxx constants to these functions
80  */
81
82 static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
83 {
84         set_bit(flag, (unsigned long *)&ti->flags);
85 }
86
87 static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
88 {
89         clear_bit(flag, (unsigned long *)&ti->flags);
90 }
91
92 static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
93 {
94         return test_and_set_bit(flag, (unsigned long *)&ti->flags);
95 }
96
97 static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
98 {
99         return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
100 }
101
102 static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
103 {
104         return test_bit(flag, (unsigned long *)&ti->flags);
105 }
106
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)
117
118 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
119
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)
124 {
125         return 0;
126 }
127 #endif
128
129 #ifdef CONFIG_HARDENED_USERCOPY
130 extern void __check_object_size(const void *ptr, unsigned long n,
131                                         bool to_user);
132
133 static __always_inline void check_object_size(const void *ptr, unsigned long n,
134                                               bool to_user)
135 {
136         if (!__builtin_constant_p(n))
137                 __check_object_size(ptr, n, to_user);
138 }
139 #else
140 static inline void check_object_size(const void *ptr, unsigned long n,
141                                      bool to_user)
142 { }
143 #endif /* CONFIG_HARDENED_USERCOPY */
144
145 #endif  /* __KERNEL__ */
146
147 #endif /* _LINUX_THREAD_INFO_H */