tools/testing/selftests/futex/include/futextest.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/futex/include/futextest.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/futex/include/futextest.h
Extension
.h
Size
8400 bytes
Lines
291
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef _FUTEXTEST_H
#define _FUTEXTEST_H

#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/futex.h>

typedef volatile u_int32_t futex_t;
#define FUTEX_INITIALIZER 0

/* Define the newer op codes if the system header file is not up to date. */
#ifndef FUTEX_WAIT_BITSET
#define FUTEX_WAIT_BITSET		9
#endif
#ifndef FUTEX_WAKE_BITSET
#define FUTEX_WAKE_BITSET		10
#endif
#ifndef FUTEX_WAIT_REQUEUE_PI
#define FUTEX_WAIT_REQUEUE_PI		11
#endif
#ifndef FUTEX_CMP_REQUEUE_PI
#define FUTEX_CMP_REQUEUE_PI		12
#endif
#ifndef FUTEX_ROBUST_UNLOCK
#define FUTEX_ROBUST_UNLOCK		512
#endif
#ifndef FUTEX_ROBUST_LIST32
#define FUTEX_ROBUST_LIST32		1024
#endif
#ifndef FUTEX_WAIT_REQUEUE_PI_PRIVATE
#define FUTEX_WAIT_REQUEUE_PI_PRIVATE	(FUTEX_WAIT_REQUEUE_PI | \
					 FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_REQUEUE_PI_PRIVATE
#define FUTEX_CMP_REQUEUE_PI_PRIVATE	(FUTEX_CMP_REQUEUE_PI | \
					 FUTEX_PRIVATE_FLAG)
#endif

/*
 * SYS_futex is expected from system C library, in glibc some 32-bit
 * architectures (e.g. RV32) are using 64-bit time_t, therefore it doesn't have
 * SYS_futex defined but just SYS_futex_time64. Define SYS_futex as
 * SYS_futex_time64 in this situation to ensure the compilation and the
 * compatibility.
 */
#if !defined(SYS_futex) && defined(SYS_futex_time64)
#define SYS_futex SYS_futex_time64
#endif

/*
 * On 32bit systems if we use "-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" or if
 * we are using a newer compiler then the size of the timestamps will be 64bit,
 * however, the SYS_futex will still point to the 32bit futex system call.
 */
#if __SIZEOF_POINTER__ == 4 && defined(SYS_futex_time64) && \
	defined(_TIME_BITS) && _TIME_BITS == 64
# undef SYS_futex
# define SYS_futex SYS_futex_time64
#endif

/**
 * futex() - SYS_futex syscall wrapper
 * @uaddr:	address of first futex
 * @op:		futex op code
 * @val:	typically expected value of uaddr, but varies by op
 * @timeout:	typically an absolute struct timespec (except where noted
 *              otherwise). Overloaded by some ops
 * @uaddr2:	address of second futex for some ops\
 * @val3:	varies by op
 * @opflags:	flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLAG
 *
 * futex() is used by all the following futex op wrappers. It can also be
 * used for misuse and abuse testing. Generally, the specific op wrappers
 * should be used instead. It is a macro instead of an static inline function as
 * some of the types over overloaded (timeout is used for nr_requeue for
 * example).
 *
 * These argument descriptions are the defaults for all
 * like-named arguments in the following wrappers except where noted below.
 */
#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \
	syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3)

/**
 * futex_wait() - block on uaddr with optional timeout
 * @timeout:	relative timeout
 */
static inline int
futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags)

Annotation

Implementation Notes