blob: c015fa91e7cce74d155191f319fcb3e4ecc47d6e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_FUTEX_H
2#define _LINUX_FUTEX_H
3
David Howells607ca462012-10-13 10:46:48 +01004#include <uapi/linux/futex.h>
Ingo Molnar0771dfe2006-03-27 01:16:22 -08005
Mike Frysinger9064a672009-09-23 15:57:23 -07006struct inode;
7struct mm_struct;
8struct task_struct;
9union ktime;
10
Pierre Peifferc19384b2007-05-09 02:35:02 -070011long do_futex(u32 __user *uaddr, int op, u32 val, union ktime *timeout,
Ingo Molnare2970f22006-06-27 02:54:47 -070012 u32 __user *uaddr2, u32 val2, u32 val3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Ingo Molnare3f2dde2006-07-29 05:17:57 +020014extern int
15handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi);
Ingo Molnar0771dfe2006-03-27 01:16:22 -080016
Rusty Russell9adef582007-05-08 00:26:42 -070017/*
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.
Eric Dumazet34f01cc2007-05-09 02:35:04 -070023 * 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
Rusty Russell9adef582007-05-08 00:26:42 -070035union futex_key {
36 struct {
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010037 u64 i_seq;
Rusty Russell9adef582007-05-08 00:26:42 -070038 unsigned long pgoff;
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010039 unsigned int offset;
Rusty Russell9adef582007-05-08 00:26:42 -070040 } shared;
41 struct {
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010042 union {
43 struct mm_struct *mm;
44 u64 __tmp;
45 };
Rusty Russell9adef582007-05-08 00:26:42 -070046 unsigned long address;
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010047 unsigned int offset;
Rusty Russell9adef582007-05-08 00:26:42 -070048 } private;
49 struct {
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010050 u64 ptr;
Rusty Russell9adef582007-05-08 00:26:42 -070051 unsigned long word;
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010052 unsigned int offset;
Rusty Russell9adef582007-05-08 00:26:42 -070053 } both;
54};
Rusty Russell9adef582007-05-08 00:26:42 -070055
Peter Zijlstrafb099f3b2020-03-04 11:28:31 +010056#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
Peter Zijlstra38d47c12008-09-26 19:32:20 +020057
Ingo Molnar0771dfe2006-03-27 01:16:22 -080058#ifdef CONFIG_FUTEX
59extern void exit_robust_list(struct task_struct *curr);
Ingo Molnarc87e2832006-06-27 02:54:58 -070060extern void exit_pi_state_list(struct task_struct *curr);
Heiko Carstens03b8c7b2014-03-02 13:09:47 +010061#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
62#define futex_cmpxchg_enabled 1
63#else
Thomas Gleixnera0c1e902008-02-23 15:23:57 -080064extern int futex_cmpxchg_enabled;
Heiko Carstens03b8c7b2014-03-02 13:09:47 +010065#endif
Ingo Molnar0771dfe2006-03-27 01:16:22 -080066#else
67static inline void exit_robust_list(struct task_struct *curr)
68{
69}
Ingo Molnarc87e2832006-06-27 02:54:58 -070070static inline void exit_pi_state_list(struct task_struct *curr)
71{
72}
Ingo Molnar0771dfe2006-03-27 01:16:22 -080073#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#endif