GNU Linux-libre 4.4.288-gnu1
[releases.git] / include / linux / futex.h
1 #ifndef _LINUX_FUTEX_H
2 #define _LINUX_FUTEX_H
3
4 #include <linux/sched.h>
5
6 #include <uapi/linux/futex.h>
7
8 struct inode;
9 struct mm_struct;
10 struct task_struct;
11 union ktime;
12
13 long do_futex(u32 __user *uaddr, int op, u32 val, union ktime *timeout,
14               u32 __user *uaddr2, u32 val2, u32 val3);
15
16 /*
17  * Futexes are matched on equal values of this key.
18  * The key type depends on whether it's a shared or private mapping.
19  * Don't rearrange members without looking at hash_futex().
20  *
21  * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
22  * We use the two low order bits of offset to tell what is the kind of key :
23  *  00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
24  *       (no reference on an inode or mm)
25  *  01 : Shared futex (PTHREAD_PROCESS_SHARED)
26  *      mapped on a file (reference on the underlying inode)
27  *  10 : Shared futex (PTHREAD_PROCESS_SHARED)
28  *       (but private mapping on an mm, and reference taken on it)
29 */
30
31 #define FUT_OFF_INODE    1 /* We set bit 0 if key has a reference on inode */
32 #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
33
34 union futex_key {
35         struct {
36                 u64 i_seq;
37                 unsigned long pgoff;
38                 unsigned int offset;
39         } shared;
40         struct {
41                 union {
42                         struct mm_struct *mm;
43                         u64 __tmp;
44                 };
45                 unsigned long address;
46                 unsigned int offset;
47         } private;
48         struct {
49                 u64 ptr;
50                 unsigned long word;
51                 unsigned int offset;
52         } both;
53 };
54
55 #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
56
57 #ifdef CONFIG_FUTEX
58 enum {
59         FUTEX_STATE_OK,
60         FUTEX_STATE_EXITING,
61         FUTEX_STATE_DEAD,
62 };
63
64 static inline void futex_init_task(struct task_struct *tsk)
65 {
66         tsk->robust_list = NULL;
67 #ifdef CONFIG_COMPAT
68         tsk->compat_robust_list = NULL;
69 #endif
70         INIT_LIST_HEAD(&tsk->pi_state_list);
71         tsk->pi_state_cache = NULL;
72         tsk->futex_state = FUTEX_STATE_OK;
73         mutex_init(&tsk->futex_exit_mutex);
74 }
75
76 void futex_exit_recursive(struct task_struct *tsk);
77 void futex_exit_release(struct task_struct *tsk);
78 void futex_exec_release(struct task_struct *tsk);
79
80 long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
81               u32 __user *uaddr2, u32 val2, u32 val3);
82 #else
83 static inline void futex_init_task(struct task_struct *tsk) { }
84 static inline void futex_exit_recursive(struct task_struct *tsk) { }
85 static inline void futex_exit_release(struct task_struct *tsk) { }
86 static inline void futex_exec_release(struct task_struct *tsk) { }
87 #endif
88 #endif