]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_FUTEX_H |
3 | #define _LINUX_FUTEX_H | |
4 | ||
e891c8f7 | 5 | #include <linux/sched.h> |
2456e855 | 6 | #include <linux/ktime.h> |
e891c8f7 | 7 | |
607ca46e | 8 | #include <uapi/linux/futex.h> |
0771dfef | 9 | |
9064a678 MF |
10 | struct inode; |
11 | struct mm_struct; | |
12 | struct task_struct; | |
9064a678 | 13 | |
2456e855 | 14 | long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, |
e2970f2f | 15 | u32 __user *uaddr2, u32 val2, u32 val3); |
1da177e4 | 16 | |
9adef58b RR |
17 | /* |
18 | * Futexes are matched on equal values of this key. | |
19 | * The key type depends on whether it's a shared or private mapping. | |
20 | * Don't rearrange members without looking at hash_futex(). | |
21 | * | |
22 | * offset is aligned to a multiple of sizeof(u32) (== 4) by definition. | |
34f01cc1 ED |
23 | * We use the two low order bits of offset to tell what is the kind of key : |
24 | * 00 : Private process futex (PTHREAD_PROCESS_PRIVATE) | |
25 | * (no reference on an inode or mm) | |
26 | * 01 : Shared futex (PTHREAD_PROCESS_SHARED) | |
27 | * mapped on a file (reference on the underlying inode) | |
28 | * 10 : Shared futex (PTHREAD_PROCESS_SHARED) | |
29 | * (but private mapping on an mm, and reference taken on it) | |
30 | */ | |
31 | ||
32 | #define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */ | |
33 | #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */ | |
34 | ||
9adef58b RR |
35 | union futex_key { |
36 | struct { | |
37 | unsigned long pgoff; | |
38 | struct inode *inode; | |
39 | int offset; | |
40 | } shared; | |
41 | struct { | |
42 | unsigned long address; | |
43 | struct mm_struct *mm; | |
44 | int offset; | |
45 | } private; | |
46 | struct { | |
47 | unsigned long word; | |
48 | void *ptr; | |
49 | int offset; | |
50 | } both; | |
51 | }; | |
9adef58b | 52 | |
38d47c1b PZ |
53 | #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } } |
54 | ||
0771dfef | 55 | #ifdef CONFIG_FUTEX |
37ad9017 TG |
56 | enum { |
57 | FUTEX_STATE_OK, | |
f34df84f | 58 | FUTEX_STATE_EXITING, |
37ad9017 TG |
59 | FUTEX_STATE_DEAD, |
60 | }; | |
e891c8f7 TG |
61 | |
62 | static inline void futex_init_task(struct task_struct *tsk) | |
0771dfef | 63 | { |
e891c8f7 TG |
64 | tsk->robust_list = NULL; |
65 | #ifdef CONFIG_COMPAT | |
66 | tsk->compat_robust_list = NULL; | |
bc2eecd7 | 67 | #endif |
e891c8f7 TG |
68 | INIT_LIST_HEAD(&tsk->pi_state_list); |
69 | tsk->pi_state_cache = NULL; | |
37ad9017 | 70 | tsk->futex_state = FUTEX_STATE_OK; |
af823481 | 71 | mutex_init(&tsk->futex_exit_mutex); |
37ad9017 TG |
72 | } |
73 | ||
f34df84f | 74 | void futex_exit_recursive(struct task_struct *tsk); |
b19fd552 TG |
75 | void futex_exit_release(struct task_struct *tsk); |
76 | void futex_exec_release(struct task_struct *tsk); | |
e891c8f7 TG |
77 | |
78 | long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, | |
79 | u32 __user *uaddr2, u32 val2, u32 val3); | |
bc2eecd7 | 80 | #else |
e891c8f7 | 81 | static inline void futex_init_task(struct task_struct *tsk) { } |
f34df84f | 82 | static inline void futex_exit_recursive(struct task_struct *tsk) { } |
b19fd552 TG |
83 | static inline void futex_exit_release(struct task_struct *tsk) { } |
84 | static inline void futex_exec_release(struct task_struct *tsk) { } | |
0771dfef | 85 | #endif |
bc2eecd7 | 86 | |
1da177e4 | 87 | #endif |