Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / include / linux / futex.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FUTEX_H
3 #define _LINUX_FUTEX_H
4
5 #include <linux/ktime.h>
6 #include <uapi/linux/futex.h>
7
8 struct inode;
9 struct mm_struct;
10 struct task_struct;
11
12 /*
13  * Futexes are matched on equal values of this key.
14  * The key type depends on whether it's a shared or private mapping.
15  * Don't rearrange members without looking at hash_futex().
16  *
17  * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
18  * We use the two low order bits of offset to tell what is the kind of key :
19  *  00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
20  *       (no reference on an inode or mm)
21  *  01 : Shared futex (PTHREAD_PROCESS_SHARED)
22  *      mapped on a file (reference on the underlying inode)
23  *  10 : Shared futex (PTHREAD_PROCESS_SHARED)
24  *       (but private mapping on an mm, and reference taken on it)
25 */
26
27 #define FUT_OFF_INODE    1 /* We set bit 0 if key has a reference on inode */
28 #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
29
30 union futex_key {
31         struct {
32                 unsigned long pgoff;
33                 struct inode *inode;
34                 int offset;
35         } shared;
36         struct {
37                 unsigned long address;
38                 struct mm_struct *mm;
39                 int offset;
40         } private;
41         struct {
42                 unsigned long word;
43                 void *ptr;
44                 int offset;
45         } both;
46 };
47
48 #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } }
49
50 #ifdef CONFIG_FUTEX
51 extern void exit_robust_list(struct task_struct *curr);
52
53 long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
54               u32 __user *uaddr2, u32 val2, u32 val3);
55 #else
56 static inline void exit_robust_list(struct task_struct *curr)
57 {
58 }
59
60 static inline long do_futex(u32 __user *uaddr, int op, u32 val,
61                             ktime_t *timeout, u32 __user *uaddr2,
62                             u32 val2, u32 val3)
63 {
64         return -EINVAL;
65 }
66 #endif
67
68 #ifdef CONFIG_FUTEX_PI
69 extern void exit_pi_state_list(struct task_struct *curr);
70 #else
71 static inline void exit_pi_state_list(struct task_struct *curr)
72 {
73 }
74 #endif
75
76 #endif