blob: c0fb9a24bbd245c980723bce4b0dc5777bd4fb64 [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
Thomas Gleixner2456e852016-12-25 11:38:40 +010012long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
Ingo Molnare2970f22006-06-27 02:54:47 -070013 u32 __user *uaddr2, u32 val2, u32 val3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Ingo Molnare3f2dde2006-07-29 05:17:57 +020015extern int
16handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi);
Ingo Molnar0771dfe2006-03-27 01:16:22 -080017
Rusty Russell9adef582007-05-08 00:26:42 -070018/*
19 * Futexes are matched on equal values of this key.
20 * The key type depends on whether it's a shared or private mapping.
21 * Don't rearrange members without looking at hash_futex().
22 *
23 * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
Eric Dumazet34f01cc2007-05-09 02:35:04 -070024 * We use the two low order bits of offset to tell what is the kind of key :
25 * 00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
26 * (no reference on an inode or mm)
27 * 01 : Shared futex (PTHREAD_PROCESS_SHARED)
28 * mapped on a file (reference on the underlying inode)
29 * 10 : Shared futex (PTHREAD_PROCESS_SHARED)
30 * (but private mapping on an mm, and reference taken on it)
31*/
32
33#define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */
34#define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
35
Rusty Russell9adef582007-05-08 00:26:42 -070036union futex_key {
37 struct {
38 unsigned long pgoff;
39 struct inode *inode;
40 int offset;
41 } shared;
42 struct {
43 unsigned long address;
44 struct mm_struct *mm;
45 int offset;
46 } private;
47 struct {
48 unsigned long word;
49 void *ptr;
50 int offset;
51 } both;
52};
Rusty Russell9adef582007-05-08 00:26:42 -070053
Peter Zijlstra38d47c12008-09-26 19:32:20 +020054#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } }
55
Ingo Molnar0771dfe2006-03-27 01:16:22 -080056#ifdef CONFIG_FUTEX
57extern void exit_robust_list(struct task_struct *curr);
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}
Nicolas Pitrebc2eecd2017-08-01 00:31:32 -040067#endif
68
69#ifdef CONFIG_FUTEX_PI
70extern void exit_pi_state_list(struct task_struct *curr);
71#else
Ingo Molnarc87e2832006-06-27 02:54:58 -070072static inline void exit_pi_state_list(struct task_struct *curr)
73{
74}
Ingo Molnar0771dfe2006-03-27 01:16:22 -080075#endif
Nicolas Pitrebc2eecd2017-08-01 00:31:32 -040076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#endif