Merge tag 'tpmdd-next-6.10-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / include / linux / futex.h
CommitLineData
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>
ba31c1a4 7
607ca46e 8#include <uapi/linux/futex.h>
0771dfef 9
9064a678
MF
10struct inode;
11struct mm_struct;
12struct 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
32union futex_key {
33 struct {
8019ad13 34 u64 i_seq;
9adef58b 35 unsigned long pgoff;
8019ad13 36 unsigned int offset;
9adef58b
RR
37 } shared;
38 struct {
8019ad13
PZ
39 union {
40 struct mm_struct *mm;
41 u64 __tmp;
42 };
9adef58b 43 unsigned long address;
8019ad13 44 unsigned int offset;
9adef58b
RR
45 } private;
46 struct {
8019ad13 47 u64 ptr;
9adef58b 48 unsigned long word;
8019ad13 49 unsigned int offset;
9adef58b
RR
50 } both;
51};
9adef58b 52
8019ad13 53#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
38d47c1b 54
0771dfef 55#ifdef CONFIG_FUTEX
3d4775df
TG
56enum {
57 FUTEX_STATE_OK,
18f69438 58 FUTEX_STATE_EXITING,
3d4775df
TG
59 FUTEX_STATE_DEAD,
60};
2de0db99 61
ba31c1a4 62static inline void futex_init_task(struct task_struct *tsk)
0771dfef 63{
ba31c1a4
TG
64 tsk->robust_list = NULL;
65#ifdef CONFIG_COMPAT
66 tsk->compat_robust_list = NULL;
67#endif
68 INIT_LIST_HEAD(&tsk->pi_state_list);
69 tsk->pi_state_cache = NULL;
3d4775df 70 tsk->futex_state = FUTEX_STATE_OK;
3f186d97 71 mutex_init(&tsk->futex_exit_mutex);
3d4775df
TG
72}
73
18f69438 74void futex_exit_recursive(struct task_struct *tsk);
150d7158
TG
75void futex_exit_release(struct task_struct *tsk);
76void futex_exec_release(struct task_struct *tsk);
ba31c1a4
TG
77
78long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
79 u32 __user *uaddr2, u32 val2, u32 val3);
80#else
81static inline void futex_init_task(struct task_struct *tsk) { }
18f69438 82static inline void futex_exit_recursive(struct task_struct *tsk) { }
150d7158
TG
83static inline void futex_exit_release(struct task_struct *tsk) { }
84static inline void futex_exec_release(struct task_struct *tsk) { }
2de0db99
DB
85static inline long do_futex(u32 __user *uaddr, int op, u32 val,
86 ktime_t *timeout, u32 __user *uaddr2,
87 u32 val2, u32 val3)
88{
89 return -EINVAL;
90}
bc2eecd7
NP
91#endif
92
1da177e4 93#endif