OSDN Git Service

Merge tag 'v4.4.207' into 10
[sagit-ice-cold/kernel_xiaomi_msm8998.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/restart_block.h>
13
14 #ifdef CONFIG_THREAD_INFO_IN_TASK
15 struct timespec;
16 struct compat_timespec;
17
18 /*
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.
22  */
23 #include <asm/current.h>
24 #define current_thread_info() ((struct thread_info *)current)
25 #endif
26
27 #include <linux/bitops.h>
28 #include <asm/thread_info.h>
29
30 #ifdef __KERNEL__
31
32 #define THREADINFO_GFP          (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
33
34 /*
35  * flag set/clear/test wrappers
36  * - pass TIF_xxxx constants to these functions
37  */
38
39 static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
40 {
41         set_bit(flag, (unsigned long *)&ti->flags);
42 }
43
44 static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
45 {
46         clear_bit(flag, (unsigned long *)&ti->flags);
47 }
48
49 static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
50 {
51         return test_and_set_bit(flag, (unsigned long *)&ti->flags);
52 }
53
54 static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
55 {
56         return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
57 }
58
59 static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
60 {
61         return test_bit(flag, (unsigned long *)&ti->flags);
62 }
63
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)
74
75 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
76
77 #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
78 /*
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.
81  */
82 #define HAVE_SET_RESTORE_SIGMASK        1
83
84 /**
85  * set_restore_sigmask() - make sure saved_sigmask processing gets done
86  *
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.
94  */
95 static inline void set_restore_sigmask(void)
96 {
97         set_thread_flag(TIF_RESTORE_SIGMASK);
98         WARN_ON(!test_thread_flag(TIF_SIGPENDING));
99 }
100 static inline void clear_restore_sigmask(void)
101 {
102         clear_thread_flag(TIF_RESTORE_SIGMASK);
103 }
104 static inline bool test_restore_sigmask(void)
105 {
106         return test_thread_flag(TIF_RESTORE_SIGMASK);
107 }
108 static inline bool test_and_clear_restore_sigmask(void)
109 {
110         return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
111 }
112 #endif  /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
113
114 #ifndef HAVE_SET_RESTORE_SIGMASK
115 #error "no set_restore_sigmask() provided and default one won't work"
116 #endif
117
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)
122 {
123         return 0;
124 }
125 #endif
126
127 #ifdef CONFIG_HARDENED_USERCOPY
128 extern void __check_object_size(const void *ptr, unsigned long n,
129                                         bool to_user);
130
131 static __always_inline void check_object_size(const void *ptr, unsigned long n,
132                                               bool to_user)
133 {
134         if (!__builtin_constant_p(n))
135                 __check_object_size(ptr, n, to_user);
136 }
137 #else
138 static inline void check_object_size(const void *ptr, unsigned long n,
139                                      bool to_user)
140 { }
141 #endif /* CONFIG_HARDENED_USERCOPY */
142
143 #endif  /* __KERNEL__ */
144
145 #endif /* _LINUX_THREAD_INFO_H */