Files
kernel/include/linux/futex.h
T

94 lines
2.4 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0 */
2005-04-16 15:20:36 -07:00
#ifndef _LINUX_FUTEX_H
#define _LINUX_FUTEX_H
#include <linux/sched.h>
2016-12-25 11:38:40 +01:00
#include <linux/ktime.h>
2012-10-13 10:46:48 +01:00
#include <uapi/linux/futex.h>
2006-03-27 01:16:22 -08:00
struct inode;
struct mm_struct;
struct task_struct;
/*
* 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.
2007-05-09 02:35:04 -07:00
* 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 */
union futex_key {
struct {
2020-03-04 11:28:31 +01:00
u64 i_seq;
unsigned long pgoff;
2020-03-04 11:28:31 +01:00
unsigned int offset;
} shared;
struct {
2020-03-04 11:28:31 +01:00
union {
struct mm_struct *mm;
u64 __tmp;
};
unsigned long address;
2020-03-04 11:28:31 +01:00
unsigned int offset;
} private;
struct {
2020-03-04 11:28:31 +01:00
u64 ptr;
unsigned long word;
2020-03-04 11:28:31 +01:00
unsigned int offset;
} both;
};
2020-03-04 11:28:31 +01:00
#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }
2006-03-27 01:16:22 -08:00
#ifdef CONFIG_FUTEX
2019-11-06 22:55:37 +01:00
enum {
FUTEX_STATE_OK,
FUTEX_STATE_EXITING,
2019-11-06 22:55:37 +01:00
FUTEX_STATE_DEAD,
};
static inline void futex_init_task(struct task_struct *tsk)
{
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;
2019-11-06 22:55:37 +01:00
tsk->futex_state = FUTEX_STATE_OK;
2019-11-06 22:55:44 +01:00
mutex_init(&tsk->futex_exit_mutex);
2019-11-06 22:55:37 +01:00
}
void futex_exit_recursive(struct task_struct *tsk);
void futex_exit_release(struct task_struct *tsk);
void futex_exec_release(struct task_struct *tsk);
long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
u32 __user *uaddr2, u32 val2, u32 val3);
2006-03-27 01:16:22 -08:00
#else
static inline void futex_init_task(struct task_struct *tsk) { }
static inline void futex_exit_recursive(struct task_struct *tsk) { }
static inline void futex_exit_release(struct task_struct *tsk) { }
static inline void futex_exec_release(struct task_struct *tsk) { }
static inline long do_futex(u32 __user *uaddr, int op, u32 val,
ktime_t *timeout, u32 __user *uaddr2,
u32 val2, u32 val3)
{
return -EINVAL;
}
2017-08-01 00:31:32 -04:00
#endif
2005-04-16 15:20:36 -07:00
#endif