tools/testing/selftests/rseq/syscall_errors_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/rseq/syscall_errors_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/rseq/syscall_errors_test.c- Extension
.c- Size
- 3805 bytes
- Lines
- 125
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: syscall or user/kernel boundary
- Status
- core 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 participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
assert.hstdint.hsyscall.hstring.hunistd.hrseq.h
Detected Declarations
function sys_rseqfunction main
Annotated Snippet
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2024 Michael Jeanson <mjeanson@efficios.com>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <assert.h>
#include <stdint.h>
#include <syscall.h>
#include <string.h>
#include <unistd.h>
#include "rseq.h"
static int sys_rseq(void *rseq_abi, uint32_t rseq_len,
int flags, uint32_t sig)
{
return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
}
/*
* Check the value of errno on some expected failures of the rseq syscall.
*/
int main(void)
{
struct rseq_abi *global_rseq = rseq_get_abi();
int ret;
int errno_copy;
if (!rseq_available()) {
fprintf(stderr, "rseq syscall unavailable");
goto error;
}
/* The current thread is NOT registered. */
/* EINVAL */
errno = 0;
ret = sys_rseq(global_rseq, 32, -1, RSEQ_SIG);
errno_copy = errno;
fprintf(stderr, "Registration with invalid flag fails with errno set to EINVAL (ret = %d, errno = %s)\n", ret, strerrorname_np(errno_copy));
if (ret == 0 || errno_copy != EINVAL)
goto error;
errno = 0;
ret = sys_rseq((char *) global_rseq + 1, 32, 0, RSEQ_SIG);
errno_copy = errno;
fprintf(stderr, "Registration with unaligned rseq_abi fails with errno set to EINVAL (ret = %d, errno = %s)\n", ret, strerrorname_np(errno_copy));
if (ret == 0 || errno_copy != EINVAL)
goto error;
errno = 0;
ret = sys_rseq(global_rseq, 31, 0, RSEQ_SIG);
errno_copy = errno;
fprintf(stderr, "Registration with invalid size fails with errno set to EINVAL (ret = %d, errno = %s)\n", ret, strerrorname_np(errno_copy));
if (ret == 0 || errno_copy != EINVAL)
goto error;
#if defined(__LP64__) && (!defined(__s390__) && !defined(__s390x__))
/*
* We haven't found a reliable way to find an invalid address when
* running a 32bit userspace on a 64bit kernel, so only run this test
* on 64bit builds for the moment.
*
* Also exclude architectures that select
* CONFIG_ALTERNATE_USER_ADDRESS_SPACE where the kernel and userspace
* have their own address space and this failure can't happen.
*/
/* EFAULT */
errno = 0;
ret = sys_rseq((void *) -4096UL, 32, 0, RSEQ_SIG);
errno_copy = errno;
fprintf(stderr, "Registration with invalid address fails with errno set to EFAULT (ret = %d, errno = %s)\n", ret, strerrorname_np(errno_copy));
if (ret == 0 || errno_copy != EFAULT)
goto error;
#endif
errno = 0;
ret = sys_rseq(global_rseq, 32, 0, RSEQ_SIG);
errno_copy = errno;
fprintf(stderr, "Registration succeeds for the current thread (ret = %d, errno = %s)\n", ret, strerrorname_np(errno_copy));
if (ret != 0 && errno != 0)
goto error;
/* The current thread is registered. */
Annotation
- Immediate include surface: `assert.h`, `stdint.h`, `syscall.h`, `string.h`, `unistd.h`, `rseq.h`.
- Detected declarations: `function sys_rseq`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: core 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.