tools/testing/selftests/arm64/signal/testcases/tpidr2_restore.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/signal/testcases/tpidr2_restore.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/arm64/signal/testcases/tpidr2_restore.c- Extension
.c- Size
- 1572 bytes
- Lines
- 87
- 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
signal.hucontext.hsys/auxv.hsys/prctl.hunistd.hasm/sigcontext.htest_signals_utils.htestcases.h
Detected Declarations
function Copyrightfunction set_tpidr2function save_tpidr2function modify_tpidr2function check_tpidr2
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2023 ARM Limited
*
* Verify that the TPIDR2 register context in signal frames is restored.
*/
#include <signal.h>
#include <ucontext.h>
#include <sys/auxv.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <asm/sigcontext.h>
#include "test_signals_utils.h"
#include "testcases.h"
#define SYS_TPIDR2 "S3_3_C13_C0_5"
static uint64_t get_tpidr2(void)
{
uint64_t val;
asm volatile (
"mrs %0, " SYS_TPIDR2 "\n"
: "=r"(val)
:
: "cc");
return val;
}
static void set_tpidr2(uint64_t val)
{
asm volatile (
"msr " SYS_TPIDR2 ", %0\n"
:
: "r"(val)
: "cc");
}
static uint64_t initial_tpidr2;
static bool save_tpidr2(struct tdescr *td)
{
initial_tpidr2 = get_tpidr2();
fprintf(stderr, "Initial TPIDR2: %lx\n", initial_tpidr2);
return true;
}
static int modify_tpidr2(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
{
uint64_t my_tpidr2 = get_tpidr2();
my_tpidr2++;
fprintf(stderr, "Setting TPIDR2 to %lx\n", my_tpidr2);
set_tpidr2(my_tpidr2);
return 0;
}
static void check_tpidr2(struct tdescr *td)
{
uint64_t tpidr2 = get_tpidr2();
td->pass = tpidr2 == initial_tpidr2;
if (td->pass)
fprintf(stderr, "TPIDR2 restored\n");
else
fprintf(stderr, "TPIDR2 was %lx but is now %lx\n",
initial_tpidr2, tpidr2);
}
struct tdescr tde = {
.name = "TPIDR2 restore",
.descr = "Validate that TPIDR2 is restored from the sigframe",
.feats_required = FEAT_SME,
.timeout = 3,
.sig_trig = SIGUSR1,
.init = save_tpidr2,
.run = modify_tpidr2,
.check_result = check_tpidr2,
};
Annotation
- Immediate include surface: `signal.h`, `ucontext.h`, `sys/auxv.h`, `sys/prctl.h`, `unistd.h`, `asm/sigcontext.h`, `test_signals_utils.h`, `testcases.h`.
- Detected declarations: `function Copyright`, `function set_tpidr2`, `function save_tpidr2`, `function modify_tpidr2`, `function check_tpidr2`.
- 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.