Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_FUTEX_H
0003 #define _LINUX_FUTEX_H
0004 
0005 #include <linux/sched.h>
0006 #include <linux/ktime.h>
0007 
0008 #include <uapi/linux/futex.h>
0009 
0010 struct inode;
0011 struct mm_struct;
0012 struct task_struct;
0013 
0014 /*
0015  * Futexes are matched on equal values of this key.
0016  * The key type depends on whether it's a shared or private mapping.
0017  * Don't rearrange members without looking at hash_futex().
0018  *
0019  * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
0020  * We use the two low order bits of offset to tell what is the kind of key :
0021  *  00 : Private process futex (PTHREAD_PROCESS_PRIVATE)
0022  *       (no reference on an inode or mm)
0023  *  01 : Shared futex (PTHREAD_PROCESS_SHARED)
0024  *  mapped on a file (reference on the underlying inode)
0025  *  10 : Shared futex (PTHREAD_PROCESS_SHARED)
0026  *       (but private mapping on an mm, and reference taken on it)
0027 */
0028 
0029 #define FUT_OFF_INODE    1 /* We set bit 0 if key has a reference on inode */
0030 #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
0031 
0032 union futex_key {
0033     struct {
0034         u64 i_seq;
0035         unsigned long pgoff;
0036         unsigned int offset;
0037     } shared;
0038     struct {
0039         union {
0040             struct mm_struct *mm;
0041             u64 __tmp;
0042         };
0043         unsigned long address;
0044         unsigned int offset;
0045     } private;
0046     struct {
0047         u64 ptr;
0048         unsigned long word;
0049         unsigned int offset;
0050     } both;
0051 };
0052 
0053 #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
0054 
0055 #ifdef CONFIG_FUTEX
0056 enum {
0057     FUTEX_STATE_OK,
0058     FUTEX_STATE_EXITING,
0059     FUTEX_STATE_DEAD,
0060 };
0061 
0062 static inline void futex_init_task(struct task_struct *tsk)
0063 {
0064     tsk->robust_list = NULL;
0065 #ifdef CONFIG_COMPAT
0066     tsk->compat_robust_list = NULL;
0067 #endif
0068     INIT_LIST_HEAD(&tsk->pi_state_list);
0069     tsk->pi_state_cache = NULL;
0070     tsk->futex_state = FUTEX_STATE_OK;
0071     mutex_init(&tsk->futex_exit_mutex);
0072 }
0073 
0074 void futex_exit_recursive(struct task_struct *tsk);
0075 void futex_exit_release(struct task_struct *tsk);
0076 void futex_exec_release(struct task_struct *tsk);
0077 
0078 long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
0079           u32 __user *uaddr2, u32 val2, u32 val3);
0080 #else
0081 static inline void futex_init_task(struct task_struct *tsk) { }
0082 static inline void futex_exit_recursive(struct task_struct *tsk) { }
0083 static inline void futex_exit_release(struct task_struct *tsk) { }
0084 static inline void futex_exec_release(struct task_struct *tsk) { }
0085 static inline long do_futex(u32 __user *uaddr, int op, u32 val,
0086                 ktime_t *timeout, u32 __user *uaddr2,
0087                 u32 val2, u32 val3)
0088 {
0089     return -EINVAL;
0090 }
0091 #endif
0092 
0093 #endif