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 21 22 23
	union {
		struct {
			unsigned long arg0, arg1, arg2, arg3;
		};
24
		/* For futex_wait and futex_wait_requeue_pi */
25 26 27 28
		struct {
			u32 *uaddr;
			u32 val;
			u32 flags;
29
			u32 bitset;
30
			u64 time;
31
			u32 *uaddr2;
32
		} futex;
33 34 35 36 37 38 39 40 41
		/* For nanosleep */
		struct {
			clockid_t index;
			struct timespec __user *rmtp;
#ifdef CONFIG_COMPAT
			struct compat_timespec __user *compat_rmtp;
#endif
			u64 expires;
		} nanosleep;
42 43 44 45 46 47 48 49
		/* For poll */
		struct {
			struct pollfd __user *ufds;
			int nfds;
			int has_timeout;
			unsigned long tv_sec;
			unsigned long tv_nsec;
		} poll;
50
	};
L
Linus Torvalds 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
};

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

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

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

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

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

90 91 92 93 94 95 96 97 98 99 100 101 102
#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 已提交
103

104 105 106 107 108 109 110
#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

111 112 113 114
/**
 * set_restore_sigmask() - make sure saved_sigmask processing gets done
 *
 * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
115 116 117 118 119 120
 * 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.
121 122 123 124
 */
static inline void set_restore_sigmask(void)
{
	set_thread_flag(TIF_RESTORE_SIGMASK);
125
	set_thread_flag(TIF_SIGPENDING);
126
}
127
#endif	/* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
128 129

#endif	/* __KERNEL__ */
L
Linus Torvalds 已提交
130 131

#endif /* _LINUX_THREAD_INFO_H */