Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_FUTEX_H |
3 | #define _LINUX_FUTEX_H | |
4 | ||
ba31c1a4 | 5 | #include <linux/sched.h> |
2456e855 | 6 | #include <linux/ktime.h> |
80367ad0 | 7 | #include <linux/mm_types.h> |
ba31c1a4 | 8 | |
607ca46e | 9 | #include <uapi/linux/futex.h> |
0771dfef | 10 | |
9064a678 | 11 | struct inode; |
9064a678 | 12 | struct task_struct; |
9064a678 | 13 | |
9adef58b RR |
14 | /* |
15 | * Futexes are matched on equal values of this key. | |
16 | * The key type depends on whether it's a shared or private mapping. | |
17 | * Don't rearrange members without looking at hash_futex(). | |
18 | * | |
19 | * offset is aligned to a multiple of sizeof(u32) (== 4) by definition. | |
34f01cc1 ED |
20 | * We use the two low order bits of offset to tell what is the kind of key : |
21 | * 00 : Private process futex (PTHREAD_PROCESS_PRIVATE) | |
22 | * (no reference on an inode or mm) | |
23 | * 01 : Shared futex (PTHREAD_PROCESS_SHARED) | |
24 | * mapped on a file (reference on the underlying inode) | |
25 | * 10 : Shared futex (PTHREAD_PROCESS_SHARED) | |
26 | * (but private mapping on an mm, and reference taken on it) | |
27 | */ | |
28 | ||
29 | #define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */ | |
30 | #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */ | |
31 | ||
9adef58b RR |
32 | union futex_key { |
33 | struct { | |
8019ad13 | 34 | u64 i_seq; |
9adef58b | 35 | unsigned long pgoff; |
8019ad13 | 36 | unsigned int offset; |
cec199c5 | 37 | /* unsigned int node; */ |
9adef58b RR |
38 | } shared; |
39 | struct { | |
8019ad13 PZ |
40 | union { |
41 | struct mm_struct *mm; | |
42 | u64 __tmp; | |
43 | }; | |
9adef58b | 44 | unsigned long address; |
8019ad13 | 45 | unsigned int offset; |
cec199c5 | 46 | /* unsigned int node; */ |
9adef58b RR |
47 | } private; |
48 | struct { | |
8019ad13 | 49 | u64 ptr; |
9adef58b | 50 | unsigned long word; |
8019ad13 | 51 | unsigned int offset; |
cec199c5 | 52 | unsigned int node; /* NOT hashed! */ |
9adef58b RR |
53 | } both; |
54 | }; | |
9adef58b | 55 | |
8019ad13 | 56 | #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } } |
38d47c1b | 57 | |
0771dfef | 58 | #ifdef CONFIG_FUTEX |
3d4775df TG |
59 | enum { |
60 | FUTEX_STATE_OK, | |
18f69438 | 61 | FUTEX_STATE_EXITING, |
3d4775df TG |
62 | FUTEX_STATE_DEAD, |
63 | }; | |
2de0db99 | 64 | |
ba31c1a4 | 65 | static inline void futex_init_task(struct task_struct *tsk) |
0771dfef | 66 | { |
ba31c1a4 TG |
67 | tsk->robust_list = NULL; |
68 | #ifdef CONFIG_COMPAT | |
69 | tsk->compat_robust_list = NULL; | |
70 | #endif | |
71 | INIT_LIST_HEAD(&tsk->pi_state_list); | |
72 | tsk->pi_state_cache = NULL; | |
3d4775df | 73 | tsk->futex_state = FUTEX_STATE_OK; |
3f186d97 | 74 | mutex_init(&tsk->futex_exit_mutex); |
3d4775df TG |
75 | } |
76 | ||
18f69438 | 77 | void futex_exit_recursive(struct task_struct *tsk); |
150d7158 TG |
78 | void futex_exit_release(struct task_struct *tsk); |
79 | void futex_exec_release(struct task_struct *tsk); | |
ba31c1a4 TG |
80 | |
81 | long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, | |
82 | u32 __user *uaddr2, u32 val2, u32 val3); | |
80367ad0 SAS |
83 | int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4); |
84 | ||
85 | #ifdef CONFIG_FUTEX_PRIVATE_HASH | |
7c4f75a2 | 86 | int futex_hash_allocate_default(void); |
80367ad0 SAS |
87 | void futex_hash_free(struct mm_struct *mm); |
88 | ||
89 | static inline void futex_mm_init(struct mm_struct *mm) | |
90 | { | |
279f2c2c | 91 | RCU_INIT_POINTER(mm->futex_phash, NULL); |
a24cc6ce | 92 | mm->futex_phash_new = NULL; |
bd54df5e | 93 | mutex_init(&mm->futex_hash_lock); |
80367ad0 SAS |
94 | } |
95 | ||
96 | #else /* !CONFIG_FUTEX_PRIVATE_HASH */ | |
7c4f75a2 | 97 | static inline int futex_hash_allocate_default(void) { return 0; } |
80367ad0 SAS |
98 | static inline void futex_hash_free(struct mm_struct *mm) { } |
99 | static inline void futex_mm_init(struct mm_struct *mm) { } | |
100 | #endif /* CONFIG_FUTEX_PRIVATE_HASH */ | |
101 | ||
102 | #else /* !CONFIG_FUTEX */ | |
ba31c1a4 | 103 | static inline void futex_init_task(struct task_struct *tsk) { } |
18f69438 | 104 | static inline void futex_exit_recursive(struct task_struct *tsk) { } |
150d7158 TG |
105 | static inline void futex_exit_release(struct task_struct *tsk) { } |
106 | static inline void futex_exec_release(struct task_struct *tsk) { } | |
2de0db99 DB |
107 | static inline long do_futex(u32 __user *uaddr, int op, u32 val, |
108 | ktime_t *timeout, u32 __user *uaddr2, | |
109 | u32 val2, u32 val3) | |
110 | { | |
111 | return -EINVAL; | |
112 | } | |
80367ad0 SAS |
113 | static inline int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4) |
114 | { | |
115 | return -EINVAL; | |
116 | } | |
7c4f75a2 SAS |
117 | static inline int futex_hash_allocate_default(void) |
118 | { | |
119 | return 0; | |
120 | } | |
80367ad0 SAS |
121 | static inline void futex_hash_free(struct mm_struct *mm) { } |
122 | static inline void futex_mm_init(struct mm_struct *mm) { } | |
123 | ||
bc2eecd7 NP |
124 | #endif |
125 | ||
1da177e4 | 126 | #endif |