blob: ccaef0097785b84545d95ef8543406ee3ff01231 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_FUTEX_H
3#define _LINUX_FUTEX_H
4
Thomas Gleixner2456e852016-12-25 11:38:40 +01005#include <linux/ktime.h>
David Howells607ca462012-10-13 10:46:48 +01006#include <uapi/linux/futex.h>
Ingo Molnar0771dfe2006-03-27 01:16:22 -08007
Mike Frysinger9064a672009-09-23 15:57:23 -07008struct inode;
9struct mm_struct;
10struct task_struct;
Mike Frysinger9064a672009-09-23 15:57:23 -070011
Rusty Russell9adef582007-05-08 00:26:42 -070012/*
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.
Eric Dumazet34f01cc2007-05-09 02:35:04 -070018 * 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
Rusty Russell9adef582007-05-08 00:26:42 -070030union 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};
Rusty Russell9adef582007-05-08 00:26:42 -070047
Peter Zijlstra38d47c12008-09-26 19:32:20 +020048#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } }
49
Ingo Molnar0771dfe2006-03-27 01:16:22 -080050#ifdef CONFIG_FUTEX
51extern void exit_robust_list(struct task_struct *curr);
Dominik Brodowski2de0db92018-03-11 11:34:26 +010052
53long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
54 u32 __user *uaddr2, u32 val2, u32 val3);
Ingo Molnar0771dfe2006-03-27 01:16:22 -080055#else
56static inline void exit_robust_list(struct task_struct *curr)
57{
58}
Dominik Brodowski2de0db92018-03-11 11:34:26 +010059
60static 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}
Nicolas Pitrebc2eecd2017-08-01 00:31:32 -040066#endif
67
68#ifdef CONFIG_FUTEX_PI
69extern void exit_pi_state_list(struct task_struct *curr);
70#else
Ingo Molnarc87e2832006-06-27 02:54:58 -070071static inline void exit_pi_state_list(struct task_struct *curr)
72{
73}
Ingo Molnar0771dfe2006-03-27 01:16:22 -080074#endif
Nicolas Pitrebc2eecd2017-08-01 00:31:32 -040075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#endif