thread_info.h 3.4 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 11
#include <linux/types.h>

12 13 14
struct timespec;
struct compat_timespec;

L
Linus Torvalds 已提交
15
/*
16
 * System call restart block.
L
Linus Torvalds 已提交
17 18 19
 */
struct restart_block {
	long (*fn)(struct restart_block *);
20
	union {
21
		/* For futex_wait and futex_wait_requeue_pi */
22
		struct {
23
			u32 __user *uaddr;
24 25
			u32 val;
			u32 flags;
26
			u32 bitset;
27
			u64 time;
28
			u32 __user *uaddr2;
29
		} futex;
30 31
		/* For nanosleep */
		struct {
32
			clockid_t clockid;
33 34 35 36 37 38
			struct timespec __user *rmtp;
#ifdef CONFIG_COMPAT
			struct compat_timespec __user *compat_rmtp;
#endif
			u64 expires;
		} nanosleep;
39 40 41 42 43 44 45 46
		/* For poll */
		struct {
			struct pollfd __user *ufds;
			int nfds;
			int has_timeout;
			unsigned long tv_sec;
			unsigned long tv_nsec;
		} poll;
47
	};
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
};

extern long do_no_restart_syscall(struct restart_block *parm);

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

#ifdef __KERNEL__

/*
 * 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)
{
64
	set_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
65 66 67 68
}

static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
{
69
	clear_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
70 71 72 73
}

static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
{
74
	return test_and_set_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
75 76 77 78
}

static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
{
79
	return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
L
Linus Torvalds 已提交
80 81 82 83
}

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

87 88 89 90 91 92 93 94 95 96 97 98 99
#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)

#define set_need_resched()	set_thread_flag(TIF_NEED_RESCHED)
#define clear_need_resched()	clear_thread_flag(TIF_NEED_RESCHED)
L
Linus Torvalds 已提交
100

101 102 103 104 105 106 107
#if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
/*
 * An arch can define its own version of set_restore_sigmask() to get the
 * job done however works, with or without TIF_RESTORE_SIGMASK.
 */
#define HAVE_SET_RESTORE_SIGMASK	1

108 109 110 111
/**
 * set_restore_sigmask() - make sure saved_sigmask processing gets done
 *
 * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
112 113 114 115 116 117
 * will run before returning to user mode, to process the flag.  For
 * all callers, TIF_SIGPENDING is already set or it's no harm to set
 * it.  TIF_RESTORE_SIGMASK need not be in the set of bits that the
 * arch code will notice on return to user mode, in case those bits
 * are scarce.  We set TIF_SIGPENDING here to ensure that the arch
 * signal code always gets run when TIF_RESTORE_SIGMASK is set.
118 119 120 121
 */
static inline void set_restore_sigmask(void)
{
	set_thread_flag(TIF_RESTORE_SIGMASK);
122
	set_thread_flag(TIF_SIGPENDING);
123
}
124
#endif	/* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
125 126

#endif	/* __KERNEL__ */
L
Linus Torvalds 已提交
127 128

#endif /* _LINUX_THREAD_INFO_H */