thread_info.h 3.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9
/* thread_info.h: common low-level thread information accessors
 *
 * Copyright (C) 2002  David Howells (dhowells@redhat.com)
 * - Incorporating suggestions made by Linus Torvalds
 */

#ifndef _LINUX_THREAD_INFO_H
#define _LINUX_THREAD_INFO_H

10
#include <linux/types.h>
11
#include <linux/bug.h>
12

13 14 15
struct timespec;
struct compat_timespec;

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#ifdef CONFIG_THREAD_INFO_IN_TASK
struct thread_info {
	u32			flags;		/* low level flags */
};

#define INIT_THREAD_INFO(tsk)			\
{						\
	.flags		= 0,			\
}
#endif

#ifdef CONFIG_THREAD_INFO_IN_TASK
#define current_thread_info() ((struct thread_info *)current)
#endif

L
Linus Torvalds 已提交
31
/*
32
 * System call restart block.
L
Linus Torvalds 已提交
33 34 35
 */
struct restart_block {
	long (*fn)(struct restart_block *);
36
	union {
37
		/* For futex_wait and futex_wait_requeue_pi */
38
		struct {
39
			u32 __user *uaddr;
40 41
			u32 val;
			u32 flags;
42
			u32 bitset;
43
			u64 time;
44
			u32 __user *uaddr2;
45
		} futex;
46 47
		/* For nanosleep */
		struct {
48
			clockid_t clockid;
49 50 51 52 53 54
			struct timespec __user *rmtp;
#ifdef CONFIG_COMPAT
			struct compat_timespec __user *compat_rmtp;
#endif
			u64 expires;
		} nanosleep;
55 56 57 58 59 60 61 62
		/* For poll */
		struct {
			struct pollfd __user *ufds;
			int nfds;
			int has_timeout;
			unsigned long tv_sec;
			unsigned long tv_nsec;
		} poll;
63
	};
L
Linus Torvalds 已提交
64 65 66 67 68 69 70 71 72
};

extern long do_no_restart_syscall(struct restart_block *parm);

#include <linux/bitops.h>
#include <asm/thread_info.h>

#ifdef __KERNEL__

73
#ifdef CONFIG_DEBUG_STACK_USAGE
74 75
# define THREADINFO_GFP		(GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | \
				 __GFP_ZERO)
76
#else
77
# define THREADINFO_GFP		(GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
78 79
#endif

L
Linus Torvalds 已提交
80 81 82 83 84 85 86
/*
 * flag set/clear/test wrappers
 * - pass TIF_xxxx constants to these functions
 */

static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
{
87
	set_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
88 89 90 91
}

static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
{
92
	clear_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
93 94 95 96
}

static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
{
97
	return test_and_set_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
98 99 100 101
}

static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
{
102
	return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
103 104 105 106
}

static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
{
107
	return test_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
108 109
}

110 111 112 113 114 115 116 117 118 119 120
#define set_thread_flag(flag) \
	set_ti_thread_flag(current_thread_info(), flag)
#define clear_thread_flag(flag) \
	clear_ti_thread_flag(current_thread_info(), flag)
#define test_and_set_thread_flag(flag) \
	test_and_set_ti_thread_flag(current_thread_info(), flag)
#define test_and_clear_thread_flag(flag) \
	test_and_clear_ti_thread_flag(current_thread_info(), flag)
#define test_thread_flag(flag) \
	test_ti_thread_flag(current_thread_info(), flag)

121 122
#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)

123 124 125 126 127 128 129 130 131
#ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
static inline int arch_within_stack_frames(const void * const stack,
					   const void * const stackend,
					   const void *obj, unsigned long len)
{
	return 0;
}
#endif

K
Kees Cook 已提交
132 133 134 135
#ifdef CONFIG_HARDENED_USERCOPY
extern void __check_object_size(const void *ptr, unsigned long n,
					bool to_user);

136 137
static __always_inline void check_object_size(const void *ptr, unsigned long n,
					      bool to_user)
K
Kees Cook 已提交
138
{
139 140
	if (!__builtin_constant_p(n))
		__check_object_size(ptr, n, to_user);
K
Kees Cook 已提交
141 142 143 144 145 146 147
}
#else
static inline void check_object_size(const void *ptr, unsigned long n,
				     bool to_user)
{ }
#endif /* CONFIG_HARDENED_USERCOPY */

148
#endif	/* __KERNEL__ */
L
Linus Torvalds 已提交
149 150

#endif /* _LINUX_THREAD_INFO_H */