tools/testing/selftests/powerpc/signal/sigreturn_kernel.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/signal/sigreturn_kernel.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/signal/sigreturn_kernel.c- Extension
.c- Size
- 2650 bytes
- Lines
- 133
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hsignal.hstdlib.hsys/types.hsys/wait.hunistd.hutils.h
Detected Declarations
function sigusr1_handlerfunction fork_childfunction expect_segvfunction test_sigreturn_kernelfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Test that we can't sigreturn to kernel addresses, or to kernel mode.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "utils.h"
#define MSR_PR (1ul << 14)
static volatile unsigned long long sigreturn_addr;
static volatile unsigned long long sigreturn_msr_mask;
static void sigusr1_handler(int signo, siginfo_t *si, void *uc_ptr)
{
ucontext_t *uc = (ucontext_t *)uc_ptr;
if (sigreturn_addr)
UCONTEXT_NIA(uc) = sigreturn_addr;
if (sigreturn_msr_mask)
UCONTEXT_MSR(uc) &= sigreturn_msr_mask;
}
static pid_t fork_child(void)
{
pid_t pid;
pid = fork();
if (pid == 0) {
raise(SIGUSR1);
exit(0);
}
return pid;
}
static int expect_segv(pid_t pid)
{
int child_ret;
waitpid(pid, &child_ret, 0);
FAIL_IF(WIFEXITED(child_ret));
FAIL_IF(!WIFSIGNALED(child_ret));
FAIL_IF(WTERMSIG(child_ret) != 11);
return 0;
}
int test_sigreturn_kernel(void)
{
struct sigaction act;
int child_ret, i;
pid_t pid;
act.sa_sigaction = sigusr1_handler;
act.sa_flags = SA_SIGINFO;
sigemptyset(&act.sa_mask);
FAIL_IF(sigaction(SIGUSR1, &act, NULL));
for (i = 0; i < 2; i++) {
// Return to kernel
sigreturn_addr = 0xcull << 60;
pid = fork_child();
expect_segv(pid);
// Return to kernel virtual
sigreturn_addr = 0xc008ull << 48;
pid = fork_child();
expect_segv(pid);
// Return out of range
sigreturn_addr = 0xc010ull << 48;
pid = fork_child();
expect_segv(pid);
// Return to no-man's land, just below PAGE_OFFSET
sigreturn_addr = (0xcull << 60) - (64 * 1024);
pid = fork_child();
expect_segv(pid);
Annotation
- Immediate include surface: `stdio.h`, `signal.h`, `stdlib.h`, `sys/types.h`, `sys/wait.h`, `unistd.h`, `utils.h`.
- Detected declarations: `function sigusr1_handler`, `function fork_child`, `function expect_segv`, `function test_sigreturn_kernel`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.