tools/testing/selftests/powerpc/tm/tm-sigreturn.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/tm/tm-sigreturn.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/tm/tm-sigreturn.c- Extension
.c- Size
- 2049 bytes
- Lines
- 95
- 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.hstdio.hstdlib.hstring.hsys/types.hsys/wait.hunistd.htm.hutils.h
Detected Declarations
function sigreturnfunction tm_sigreturnfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2015, Laurent Dufour, IBM Corp.
*
* Test the kernel's signal returning code to check reclaim is done if the
* sigreturn() is called while in a transaction (suspended since active is
* already dropped trough the system call path).
*
* The kernel must discard the transaction when entering sigreturn, since
* restoring the potential TM SPRS from the signal frame is requiring to not be
* in a transaction.
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "tm.h"
#include "utils.h"
void handler(int sig)
{
uint64_t ret;
asm __volatile__(
"li 3,1 ;"
"tbegin. ;"
"beq 1f ;"
"li 3,0 ;"
"tsuspend. ;"
"1: ;"
"std%X[ret] 3, %[ret] ;"
: [ret] "=m"(ret)
:
: "memory", "3", "cr0");
if (ret)
exit(1);
/*
* We return from the signal handle while in a suspended transaction
*/
}
int tm_sigreturn(void)
{
struct sigaction sa;
uint64_t ret = 0;
SKIP_IF(!have_htm());
SKIP_IF(htm_is_synthetic());
SKIP_IF(!is_ppc64le());
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGSEGV, &sa, NULL))
exit(1);
asm __volatile__(
"tbegin. ;"
"beq 1f ;"
"li 3,0 ;"
"std 3,0(3) ;" /* trigger SEGV */
"li 3,1 ;"
"std%X[ret] 3,%[ret] ;"
"tend. ;"
"b 2f ;"
"1: ;"
"li 3,2 ;"
"std%X[ret] 3,%[ret] ;"
"2: ;"
: [ret] "=m"(ret)
:
: "memory", "3", "cr0");
if (ret != 2)
exit(1);
exit(0);
}
Annotation
- Immediate include surface: `signal.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/types.h`, `sys/wait.h`, `unistd.h`, `tm.h`.
- Detected declarations: `function sigreturn`, `function tm_sigreturn`, `function main`.
- 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.