Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_FUTEX_H |
| 3 | #define _LINUX_FUTEX_H |
| 4 | |
Thomas Gleixner | 2456e85 | 2016-12-25 11:38:40 +0100 | [diff] [blame] | 5 | #include <linux/ktime.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 6 | #include <uapi/linux/futex.h> |
Ingo Molnar | 0771dfe | 2006-03-27 01:16:22 -0800 | [diff] [blame] | 7 | |
Mike Frysinger | 9064a67 | 2009-09-23 15:57:23 -0700 | [diff] [blame] | 8 | struct inode; |
| 9 | struct mm_struct; |
| 10 | struct task_struct; |
Mike Frysinger | 9064a67 | 2009-09-23 15:57:23 -0700 | [diff] [blame] | 11 | |
Ingo Molnar | e3f2dde | 2006-07-29 05:17:57 +0200 | [diff] [blame] | 12 | extern int |
| 13 | handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi); |
Ingo Molnar | 0771dfe | 2006-03-27 01:16:22 -0800 | [diff] [blame] | 14 | |
Rusty Russell | 9adef58 | 2007-05-08 00:26:42 -0700 | [diff] [blame] | 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. |
Eric Dumazet | 34f01cc | 2007-05-09 02:35:04 -0700 | [diff] [blame] | 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 | |
Rusty Russell | 9adef58 | 2007-05-08 00:26:42 -0700 | [diff] [blame] | 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 | }; |
Rusty Russell | 9adef58 | 2007-05-08 00:26:42 -0700 | [diff] [blame] | 50 | |
Peter Zijlstra | 38d47c1 | 2008-09-26 19:32:20 +0200 | [diff] [blame] | 51 | #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } } |
| 52 | |
Ingo Molnar | 0771dfe | 2006-03-27 01:16:22 -0800 | [diff] [blame] | 53 | #ifdef CONFIG_FUTEX |
| 54 | extern void exit_robust_list(struct task_struct *curr); |
Dominik Brodowski | 2de0db9 | 2018-03-11 11:34:26 +0100 | [diff] [blame] | 55 | |
| 56 | long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, |
| 57 | u32 __user *uaddr2, u32 val2, u32 val3); |
Heiko Carstens | 03b8c7b | 2014-03-02 13:09:47 +0100 | [diff] [blame] | 58 | #ifdef CONFIG_HAVE_FUTEX_CMPXCHG |
| 59 | #define futex_cmpxchg_enabled 1 |
| 60 | #else |
Thomas Gleixner | a0c1e90 | 2008-02-23 15:23:57 -0800 | [diff] [blame] | 61 | extern int futex_cmpxchg_enabled; |
Heiko Carstens | 03b8c7b | 2014-03-02 13:09:47 +0100 | [diff] [blame] | 62 | #endif |
Ingo Molnar | 0771dfe | 2006-03-27 01:16:22 -0800 | [diff] [blame] | 63 | #else |
| 64 | static inline void exit_robust_list(struct task_struct *curr) |
| 65 | { |
| 66 | } |
Dominik Brodowski | 2de0db9 | 2018-03-11 11:34:26 +0100 | [diff] [blame] | 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 | } |
Nicolas Pitre | bc2eecd | 2017-08-01 00:31:32 -0400 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | #ifdef CONFIG_FUTEX_PI |
| 77 | extern void exit_pi_state_list(struct task_struct *curr); |
| 78 | #else |
Ingo Molnar | c87e283 | 2006-06-27 02:54:58 -0700 | [diff] [blame] | 79 | static inline void exit_pi_state_list(struct task_struct *curr) |
| 80 | { |
| 81 | } |
Ingo Molnar | 0771dfe | 2006-03-27 01:16:22 -0800 | [diff] [blame] | 82 | #endif |
Nicolas Pitre | bc2eecd | 2017-08-01 00:31:32 -0400 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #endif |