futex.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_FUTEX_H
  3. #define _LINUX_FUTEX_H
  4. #include <linux/ktime.h>
  5. #include <uapi/linux/futex.h>
  6. struct inode;
  7. struct mm_struct;
  8. struct task_struct;
  9. /*
  10. * Futexes are matched on equal values of this key.
  11. * The key type depends on whether it's a shared or private mapping.
  12. * Don't rearrange members without looking at hash_futex().
  13. *
  14. * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
  15. * We use the two low order bits of offset to tell what is the kind of key :
  16. * 00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
  17. * (no reference on an inode or mm)
  18. * 01 : Shared futex (PTHREAD_PROCESS_SHARED)
  19. * mapped on a file (reference on the underlying inode)
  20. * 10 : Shared futex (PTHREAD_PROCESS_SHARED)
  21. * (but private mapping on an mm, and reference taken on it)
  22. */
  23. #define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */
  24. #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
  25. union futex_key {
  26. struct {
  27. u64 i_seq;
  28. unsigned long pgoff;
  29. unsigned int offset;
  30. } shared;
  31. struct {
  32. union {
  33. struct mm_struct *mm;
  34. u64 __tmp;
  35. };
  36. unsigned long address;
  37. unsigned int offset;
  38. } private;
  39. struct {
  40. u64 ptr;
  41. unsigned long word;
  42. unsigned int offset;
  43. } both;
  44. };
  45. #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
  46. #ifdef CONFIG_FUTEX
  47. extern void exit_robust_list(struct task_struct *curr);
  48. long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
  49. u32 __user *uaddr2, u32 val2, u32 val3);
  50. #else
  51. static inline void exit_robust_list(struct task_struct *curr)
  52. {
  53. }
  54. static inline long do_futex(u32 __user *uaddr, int op, u32 val,
  55. ktime_t *timeout, u32 __user *uaddr2,
  56. u32 val2, u32 val3)
  57. {
  58. return -EINVAL;
  59. }
  60. #endif
  61. #ifdef CONFIG_FUTEX_PI
  62. extern void exit_pi_state_list(struct task_struct *curr);
  63. #else
  64. static inline void exit_pi_state_list(struct task_struct *curr)
  65. {
  66. }
  67. #endif
  68. #endif