tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c- Extension
.c- Size
- 2084 bytes
- Lines
- 83
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hsyscall.hunistd.herrno.hlinux/futex.hpthread.hlibgen.hsignal.hfutextest.hkselftest_harness.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/******************************************************************************
*
* Copyright FUJITSU LIMITED 2010
* Copyright KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
*
* DESCRIPTION
* Internally, Futex has two handling mode, anon and file. The private file
* mapping is special. At first it behave as file, but after write anything
* it behave as anon. This test is intent to test such case.
*
* AUTHOR
* KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
*
* HISTORY
* 2010-Jan-6: Initial version by KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <syscall.h>
#include <unistd.h>
#include <errno.h>
#include <linux/futex.h>
#include <pthread.h>
#include <libgen.h>
#include <signal.h>
#include "futextest.h"
#include "kselftest_harness.h"
#define PAGE_SZ 4096
char pad[PAGE_SZ] = {1};
futex_t val = 1;
char pad2[PAGE_SZ] = {1};
#define WAKE_WAIT_US 3000000
struct timespec wait_timeout = { .tv_sec = 5, .tv_nsec = 0};
void *thr_futex_wait(void *arg)
{
int ret;
ksft_print_dbg_msg("futex wait\n");
ret = futex_wait(&val, 1, &wait_timeout, 0);
if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT)
ksft_exit_fail_msg("futex error.\n");
if (ret && errno == ETIMEDOUT)
ksft_exit_fail_msg("waiter timedout\n");
ksft_print_dbg_msg("futex_wait: ret = %d, errno = %d\n", ret, errno);
return NULL;
}
TEST(wait_private_mapped_file)
{
pthread_t thr;
int res;
res = pthread_create(&thr, NULL, thr_futex_wait, NULL);
if (res < 0)
ksft_exit_fail_msg("pthread_create error\n");
ksft_print_dbg_msg("wait a while\n");
usleep(WAKE_WAIT_US);
val = 2;
res = futex_wake(&val, 1, 0);
ksft_print_dbg_msg("futex_wake %d\n", res);
if (res != 1)
ksft_exit_fail_msg("FUTEX_WAKE didn't find the waiting thread.\n");
ksft_print_dbg_msg("join\n");
pthread_join(thr, NULL);
ksft_test_result_pass("wait_private_mapped_file");
}
TEST_HARNESS_MAIN
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `syscall.h`, `unistd.h`, `errno.h`, `linux/futex.h`, `pthread.h`, `libgen.h`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.