1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/sched.h>
6 #include <linux/ktime.h>
7 #include <linux/mm_types.h>
9 #include <uapi/linux/futex.h>
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().
19 * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
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)
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 */
37 /* unsigned int node; */
44 unsigned long address;
46 /* unsigned int node; */
52 unsigned int node; /* NOT hashed! */
56 #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
65 static inline void futex_init_task(struct task_struct *tsk)
67 tsk->robust_list = NULL;
69 tsk->compat_robust_list = NULL;
71 INIT_LIST_HEAD(&tsk->pi_state_list);
72 tsk->pi_state_cache = NULL;
73 tsk->futex_state = FUTEX_STATE_OK;
74 mutex_init(&tsk->futex_exit_mutex);
77 void futex_exit_recursive(struct task_struct *tsk);
78 void futex_exit_release(struct task_struct *tsk);
79 void futex_exec_release(struct task_struct *tsk);
81 long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
82 u32 __user *uaddr2, u32 val2, u32 val3);
83 int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4);
85 #ifdef CONFIG_FUTEX_PRIVATE_HASH
86 int futex_hash_allocate_default(void);
87 void futex_hash_free(struct mm_struct *mm);
89 static inline void futex_mm_init(struct mm_struct *mm)
91 RCU_INIT_POINTER(mm->futex_phash, NULL);
92 mm->futex_phash_new = NULL;
93 mutex_init(&mm->futex_hash_lock);
96 #else /* !CONFIG_FUTEX_PRIVATE_HASH */
97 static inline int futex_hash_allocate_default(void) { return 0; }
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 */
102 #else /* !CONFIG_FUTEX */
103 static inline void futex_init_task(struct task_struct *tsk) { }
104 static inline void futex_exit_recursive(struct task_struct *tsk) { }
105 static inline void futex_exit_release(struct task_struct *tsk) { }
106 static inline void futex_exec_release(struct task_struct *tsk) { }
107 static inline long do_futex(u32 __user *uaddr, int op, u32 val,
108 ktime_t *timeout, u32 __user *uaddr2,
113 static inline int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4)
117 static inline int futex_hash_allocate_default(void)
121 static inline void futex_hash_free(struct mm_struct *mm) { }
122 static inline void futex_mm_init(struct mm_struct *mm) { }