blob: c75c6ab364cafa722eae97c66a699b1361b3de20 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Steven Rostedtce6bd422007-12-05 15:46:09 +010010#include <linux/types.h>
Al Viroedd63a22012-04-27 13:42:45 -040011#include <linux/bug.h>
Mark Rutland53d74d02016-10-19 19:28:12 +010012#include <linux/restart_block.h>
Thomas Gleixnera332d862008-02-10 09:04:12 +010013
Andy Lutomirskic65eacb2016-09-13 14:29:24 -070014#ifdef CONFIG_THREAD_INFO_IN_TASK
Andy Lutomirskic65eacb2016-09-13 14:29:24 -070015#define current_thread_info() ((struct thread_info *)current)
16#endif
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/bitops.h>
19#include <asm/thread_info.h>
20
21#ifdef __KERNEL__
22
Thomas Gleixner2889f602012-05-05 15:05:41 +000023#ifdef CONFIG_DEBUG_STACK_USAGE
Vladimir Davydov5d097052016-01-14 15:18:21 -080024# define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | \
25 __GFP_ZERO)
Thomas Gleixner2889f602012-05-05 15:05:41 +000026#else
Vladimir Davydov5d097052016-01-14 15:18:21 -080027# define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
Thomas Gleixner2889f602012-05-05 15:05:41 +000028#endif
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/*
31 * flag set/clear/test wrappers
32 * - pass TIF_xxxx constants to these functions
33 */
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
36{
Jeremy Fitzhardinge5548fec2008-01-30 13:30:55 +010037 set_bit(flag, (unsigned long *)&ti->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
40static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
41{
Jeremy Fitzhardinge5548fec2008-01-30 13:30:55 +010042 clear_bit(flag, (unsigned long *)&ti->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
45static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
46{
Jeremy Fitzhardinge5548fec2008-01-30 13:30:55 +010047 return test_and_set_bit(flag, (unsigned long *)&ti->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
50static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
51{
Jeremy Fitzhardinge5548fec2008-01-30 13:30:55 +010052 return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
56{
Jeremy Fitzhardinge5548fec2008-01-30 13:30:55 +010057 return test_bit(flag, (unsigned long *)&ti->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
Roman Zippel3b66a1e2005-11-13 16:06:59 -080060#define set_thread_flag(flag) \
61 set_ti_thread_flag(current_thread_info(), flag)
62#define clear_thread_flag(flag) \
63 clear_ti_thread_flag(current_thread_info(), flag)
64#define test_and_set_thread_flag(flag) \
65 test_and_set_ti_thread_flag(current_thread_info(), flag)
66#define test_and_clear_thread_flag(flag) \
67 test_and_clear_ti_thread_flag(current_thread_info(), flag)
68#define test_thread_flag(flag) \
69 test_ti_thread_flag(current_thread_info(), flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Peter Zijlstraea811742013-09-11 12:43:13 +020071#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
72
Kees Cook0f60a8e2016-07-12 16:19:48 -070073#ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
74static inline int arch_within_stack_frames(const void * const stack,
75 const void * const stackend,
76 const void *obj, unsigned long len)
77{
78 return 0;
79}
80#endif
81
Kees Cookf5509cc2016-06-07 11:05:33 -070082#ifdef CONFIG_HARDENED_USERCOPY
83extern void __check_object_size(const void *ptr, unsigned long n,
84 bool to_user);
85
Kees Cooka85d6b82016-09-07 09:39:32 -070086static __always_inline void check_object_size(const void *ptr, unsigned long n,
87 bool to_user)
Kees Cookf5509cc2016-06-07 11:05:33 -070088{
Kees Cook81409e92016-08-31 16:04:21 -070089 if (!__builtin_constant_p(n))
90 __check_object_size(ptr, n, to_user);
Kees Cookf5509cc2016-06-07 11:05:33 -070091}
92#else
93static inline void check_object_size(const void *ptr, unsigned long n,
94 bool to_user)
95{ }
96#endif /* CONFIG_HARDENED_USERCOPY */
97
Roland McGrath4e4c22c2008-04-30 00:53:06 -070098#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100#endif /* _LINUX_THREAD_INFO_H */