Merge branch 'for-linus-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / thread_info.h
CommitLineData
1da177e4
LT
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
ce6bd420 10#include <linux/types.h>
edd63a27 11#include <linux/bug.h>
53d74d05 12#include <linux/restart_block.h>
a332d86d 13
c65eacbe 14#ifdef CONFIG_THREAD_INFO_IN_TASK
dc3d2a67
MR
15/*
16 * For CONFIG_THREAD_INFO_IN_TASK kernels we need <asm/current.h> for the
17 * definition of current, but for !CONFIG_THREAD_INFO_IN_TASK kernels,
18 * including <asm/current.h> can cause a circular dependency on some platforms.
19 */
20#include <asm/current.h>
c65eacbe
AL
21#define current_thread_info() ((struct thread_info *)current)
22#endif
23
1da177e4 24#include <linux/bitops.h>
96dc4f9f
S
25
26/*
27 * For per-arch arch_within_stack_frames() implementations, defined in
28 * asm/thread_info.h.
29 */
30enum {
31 BAD_STACK = -1,
32 NOT_STACK = 0,
33 GOOD_FRAME,
34 GOOD_STACK,
35};
36
1da177e4
LT
37#include <asm/thread_info.h>
38
39#ifdef __KERNEL__
40
2889f608 41#ifdef CONFIG_DEBUG_STACK_USAGE
5d097056
VD
42# define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | \
43 __GFP_ZERO)
2889f608 44#else
5d097056 45# define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
2889f608
TG
46#endif
47
1da177e4
LT
48/*
49 * flag set/clear/test wrappers
50 * - pass TIF_xxxx constants to these functions
51 */
52
1da177e4
LT
53static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
54{
5548fecd 55 set_bit(flag, (unsigned long *)&ti->flags);
1da177e4
LT
56}
57
58static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
59{
5548fecd 60 clear_bit(flag, (unsigned long *)&ti->flags);
1da177e4
LT
61}
62
63static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
64{
5548fecd 65 return test_and_set_bit(flag, (unsigned long *)&ti->flags);
1da177e4
LT
66}
67
68static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
69{
5548fecd 70 return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
1da177e4
LT
71}
72
73static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
74{
5548fecd 75 return test_bit(flag, (unsigned long *)&ti->flags);
1da177e4
LT
76}
77
3b66a1ed
RZ
78#define set_thread_flag(flag) \
79 set_ti_thread_flag(current_thread_info(), flag)
80#define clear_thread_flag(flag) \
81 clear_ti_thread_flag(current_thread_info(), flag)
82#define test_and_set_thread_flag(flag) \
83 test_and_set_ti_thread_flag(current_thread_info(), flag)
84#define test_and_clear_thread_flag(flag) \
85 test_and_clear_ti_thread_flag(current_thread_info(), flag)
86#define test_thread_flag(flag) \
87 test_ti_thread_flag(current_thread_info(), flag)
88
ea811747
PZ
89#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
90
0f60a8ef
KC
91#ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
92static inline int arch_within_stack_frames(const void * const stack,
93 const void * const stackend,
94 const void *obj, unsigned long len)
95{
96 return 0;
97}
98#endif
99
f5509cc1
KC
100#ifdef CONFIG_HARDENED_USERCOPY
101extern void __check_object_size(const void *ptr, unsigned long n,
102 bool to_user);
103
a85d6b82
KC
104static __always_inline void check_object_size(const void *ptr, unsigned long n,
105 bool to_user)
f5509cc1 106{
81409e9e
KC
107 if (!__builtin_constant_p(n))
108 __check_object_size(ptr, n, to_user);
f5509cc1
KC
109}
110#else
111static inline void check_object_size(const void *ptr, unsigned long n,
112 bool to_user)
113{ }
114#endif /* CONFIG_HARDENED_USERCOPY */
115
e9ea1e7f
KH
116#ifndef arch_setup_new_exec
117static inline void arch_setup_new_exec(void) { }
118#endif
119
4e4c22c7 120#endif /* __KERNEL__ */
1da177e4
LT
121
122#endif /* _LINUX_THREAD_INFO_H */