tools/testing/selftests/powerpc/tm/tm-signal-stack.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/tm/tm-signal-stack.c- Extension
.c- Size
- 1774 bytes
- Lines
- 78
- 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.
Dependency Surface
unistd.hsys/types.hsys/wait.hstdlib.hstdio.hsignal.hutils.htm.h
Detected Declarations
function signal_segvfunction tm_signal_stackfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2015, Michael Neuling, IBM Corp.
*
* Test the kernel's signal delievery code to ensure that we don't
* trelaim twice in the kernel signal delivery code. This can happen
* if we trigger a signal when in a transaction and the stack pointer
* is bogus.
*
* This test case registers a SEGV handler, sets the stack pointer
* (r1) to NULL, starts a transaction and then generates a SEGV. The
* SEGV should be handled but we exit here as the stack pointer is
* invalid and hance we can't sigreturn. We only need to check that
* this flow doesn't crash the kernel.
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "utils.h"
#include "tm.h"
void signal_segv(int signum)
{
/* This should never actually run since stack is foobar */
exit(1);
}
int tm_signal_stack()
{
int pid;
SKIP_IF(!have_htm());
SKIP_IF(htm_is_synthetic());
pid = fork();
if (pid < 0)
exit(1);
if (pid) { /* Parent */
/*
* It's likely the whole machine will crash here so if
* the child ever exits, we are good.
*/
wait(NULL);
return 0;
}
/*
* The flow here is:
* 1) register a signal handler (so signal delievery occurs)
* 2) make stack pointer (r1) = NULL
* 3) start transaction
* 4) cause segv
*/
if (signal(SIGSEGV, signal_segv) == SIG_ERR)
exit(1);
asm volatile("li 1, 0 ;" /* stack ptr == NULL */
"1:"
"tbegin.;"
"beq 1b ;" /* retry forever */
"tsuspend.;"
"ld 2, 0(1) ;" /* trigger segv" */
: : : "memory");
/* This should never get here due to above segv */
return 1;
}
int main(void)
{
return test_harness(tm_signal_stack, "tm_signal_stack");
}
Annotation
- Immediate include surface: `unistd.h`, `sys/types.h`, `sys/wait.h`, `stdlib.h`, `stdio.h`, `signal.h`, `utils.h`, `tm.h`.
- Detected declarations: `function signal_segv`, `function tm_signal_stack`, `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.