Blame view

include/linux/futex.h 2.39 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  #ifndef _LINUX_FUTEX_H
  #define _LINUX_FUTEX_H
8012f98f9   Thomas Gleixner   futex: Move futex...
4
  #include <linux/sched.h>
2456e8553   Thomas Gleixner   ktime: Get rid of...
5
  #include <linux/ktime.h>
8012f98f9   Thomas Gleixner   futex: Move futex...
6

607ca46e9   David Howells   UAPI: (Scripted) ...
7
  #include <uapi/linux/futex.h>
0771dfefc   Ingo Molnar   [PATCH] lightweig...
8

9064a6787   Mike Frysinger   linux/futex.h: pl...
9
10
11
  struct inode;
  struct mm_struct;
  struct task_struct;
9064a6787   Mike Frysinger   linux/futex.h: pl...
12

9adef58b1   Rusty Russell   futex: get_futex_...
13
14
15
16
17
18
  /*
   * Futexes are matched on equal values of this key.
   * The key type depends on whether it's a shared or private mapping.
   * Don't rearrange members without looking at hash_futex().
   *
   * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
34f01cc1f   Eric Dumazet   FUTEX: new PRIVAT...
19
20
21
22
23
24
25
26
27
28
29
   * We use the two low order bits of offset to tell what is the kind of key :
   *  00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
   *       (no reference on an inode or mm)
   *  01 : Shared futex (PTHREAD_PROCESS_SHARED)
   *	mapped on a file (reference on the underlying inode)
   *  10 : Shared futex (PTHREAD_PROCESS_SHARED)
   *       (but private mapping on an mm, and reference taken on it)
  */
  
  #define FUT_OFF_INODE    1 /* We set bit 0 if key has a reference on inode */
  #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
9adef58b1   Rusty Russell   futex: get_futex_...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  union futex_key {
  	struct {
  		unsigned long pgoff;
  		struct inode *inode;
  		int offset;
  	} shared;
  	struct {
  		unsigned long address;
  		struct mm_struct *mm;
  		int offset;
  	} private;
  	struct {
  		unsigned long word;
  		void *ptr;
  		int offset;
  	} both;
  };
9adef58b1   Rusty Russell   futex: get_futex_...
47

38d47c1b7   Peter Zijlstra   futex: rely on ge...
48
  #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } }
0771dfefc   Ingo Molnar   [PATCH] lightweig...
49
  #ifdef CONFIG_FUTEX
52507cfaf   Thomas Gleixner   futex: Replace PF...
50
51
  enum {
  	FUTEX_STATE_OK,
b2f4e1067   Thomas Gleixner   futex: Mark the b...
52
  	FUTEX_STATE_EXITING,
52507cfaf   Thomas Gleixner   futex: Replace PF...
53
54
  	FUTEX_STATE_DEAD,
  };
2de0db992   Dominik Brodowski   mm: use do_futex(...
55

8012f98f9   Thomas Gleixner   futex: Move futex...
56
  static inline void futex_init_task(struct task_struct *tsk)
0771dfefc   Ingo Molnar   [PATCH] lightweig...
57
  {
8012f98f9   Thomas Gleixner   futex: Move futex...
58
59
60
61
62
63
  	tsk->robust_list = NULL;
  #ifdef CONFIG_COMPAT
  	tsk->compat_robust_list = NULL;
  #endif
  	INIT_LIST_HEAD(&tsk->pi_state_list);
  	tsk->pi_state_cache = NULL;
52507cfaf   Thomas Gleixner   futex: Replace PF...
64
  	tsk->futex_state = FUTEX_STATE_OK;
d3ba1e8d5   Thomas Gleixner   futex: Add mutex ...
65
  	mutex_init(&tsk->futex_exit_mutex);
52507cfaf   Thomas Gleixner   futex: Replace PF...
66
  }
b2f4e1067   Thomas Gleixner   futex: Mark the b...
67
  void futex_exit_recursive(struct task_struct *tsk);
1bcee2337   Thomas Gleixner   futex: Split fute...
68
69
  void futex_exit_release(struct task_struct *tsk);
  void futex_exec_release(struct task_struct *tsk);
8012f98f9   Thomas Gleixner   futex: Move futex...
70
71
72
73
74
  
  long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
  	      u32 __user *uaddr2, u32 val2, u32 val3);
  #else
  static inline void futex_init_task(struct task_struct *tsk) { }
b2f4e1067   Thomas Gleixner   futex: Mark the b...
75
  static inline void futex_exit_recursive(struct task_struct *tsk) { }
1bcee2337   Thomas Gleixner   futex: Split fute...
76
77
  static inline void futex_exit_release(struct task_struct *tsk) { }
  static inline void futex_exec_release(struct task_struct *tsk) { }
2de0db992   Dominik Brodowski   mm: use do_futex(...
78
79
80
81
82
83
  static inline long do_futex(u32 __user *uaddr, int op, u32 val,
  			    ktime_t *timeout, u32 __user *uaddr2,
  			    u32 val2, u32 val3)
  {
  	return -EINVAL;
  }
bc2eecd7e   Nicolas Pitre   futex: Allow for ...
84
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  #endif