Merge tag 'stackleak-v4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.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 extern int
13 handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi);
14
15 /*
16  * Futexes are matched on equal values of this key.
17  * The key type depends on whether it's a shared or private mapping.
18  * Don't rearrange members without looking at hash_futex().
19  *
20  * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
21  * We use the two low order bits of offset to tell what is the kind of key :
22  *  00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
23  *       (no reference on an inode or mm)
24  *  01 : Shared futex (PTHREAD_PROCESS_SHARED)
25  *      mapped on a file (reference on the underlying inode)
26  *  10 : Shared futex (PTHREAD_PROCESS_SHARED)
27  *       (but private mapping on an mm, and reference taken on it)
28 */
29
30 #define FUT_OFF_INODE    1 /* We set bit 0 if key has a reference on inode */
31 #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
32
33 union futex_key {
34         struct {
35                 unsigned long pgoff;
36                 struct inode *inode;
37                 int offset;
38         } shared;
39         struct {
40                 unsigned long address;
41                 struct mm_struct *mm;
42                 int offset;
43         } private;
44         struct {
45                 unsigned long word;
46                 void *ptr;
47                 int offset;
48         } both;
49 };
50
51 #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } }
52
53 #ifdef CONFIG_FUTEX
54 extern void exit_robust_list(struct task_struct *curr);
55
56 long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
57               u32 __user *uaddr2, u32 val2, u32 val3);
58 #ifdef CONFIG_HAVE_FUTEX_CMPXCHG
59 #define futex_cmpxchg_enabled 1
60 #else
61 extern int futex_cmpxchg_enabled;
62 #endif
63 #else
64 static inline void exit_robust_list(struct task_struct *curr)
65 {
66 }
67
68 static inline long do_futex(u32 __user *uaddr, int op, u32 val,
69                             ktime_t *timeout, u32 __user *uaddr2,
70                             u32 val2, u32 val3)
71 {
72         return -EINVAL;
73 }
74 #endif
75
76 #ifdef CONFIG_FUTEX_PI
77 extern void exit_pi_state_list(struct task_struct *curr);
78 #else
79 static inline void exit_pi_state_list(struct task_struct *curr)
80 {
81 }
82 #endif
83
84 #endif