blob: 821ae502d3d89b8c5bc69d45b8f02120ebe41887 [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
Ingo Molnare3f2dde2006-07-29 05:17:57 +020012extern int
13handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi);
Ingo Molnar0771dfe2006-03-27 01:16:22 -080014
Rusty Russell9adef582007-05-08 00:26:42 -070015/*
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 Dumazet34f01cc2007-05-09 02:35:04 -070021 * 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 Russell9adef582007-05-08 00:26:42 -070033union 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 Russell9adef582007-05-08 00:26:42 -070050
Peter Zijlstra38d47c12008-09-26 19:32:20 +020051#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } }
52
Ingo Molnar0771dfe2006-03-27 01:16:22 -080053#ifdef CONFIG_FUTEX
54extern void exit_robust_list(struct task_struct *curr);
Dominik Brodowski2de0db92018-03-11 11:34:26 +010055
56long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
57 u32 __user *uaddr2, u32 val2, u32 val3);
Heiko Carstens03b8c7b2014-03-02 13:09:47 +010058#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
59#define futex_cmpxchg_enabled 1
60#else
Thomas Gleixnera0c1e902008-02-23 15:23:57 -080061extern int futex_cmpxchg_enabled;
Heiko Carstens03b8c7b2014-03-02 13:09:47 +010062#endif
Ingo Molnar0771dfe2006-03-27 01:16:22 -080063#else
64static inline void exit_robust_list(struct task_struct *curr)
65{
66}
Dominik Brodowski2de0db92018-03-11 11:34:26 +010067
68static 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 Pitrebc2eecd2017-08-01 00:31:32 -040074#endif
75
76#ifdef CONFIG_FUTEX_PI
77extern void exit_pi_state_list(struct task_struct *curr);
78#else
Ingo Molnarc87e2832006-06-27 02:54:58 -070079static inline void exit_pi_state_list(struct task_struct *curr)
80{
81}
Ingo Molnar0771dfe2006-03-27 01:16:22 -080082#endif
Nicolas Pitrebc2eecd2017-08-01 00:31:32 -040083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#endif