tools/testing/selftests/powerpc/mm/segv_errors.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/mm/segv_errors.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/mm/segv_errors.c- Extension
.c- Size
- 1384 bytes
- Lines
- 79
- 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
stdbool.hstdio.hstdlib.hstring.hunistd.hsignal.hsys/mman.hassert.hucontext.hutils.h
Detected Declarations
function segv_handlerfunction test_segv_errorsfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2017 John Sperbeck
*
* Test that an access to a mapped but inaccessible area causes a SEGV and
* reports si_code == SEGV_ACCERR.
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/mman.h>
#include <assert.h>
#include <ucontext.h>
#include "utils.h"
static bool faulted;
static int si_code;
static void segv_handler(int n, siginfo_t *info, void *ctxt_v)
{
ucontext_t *ctxt = (ucontext_t *)ctxt_v;
struct pt_regs *regs = ctxt->uc_mcontext.regs;
faulted = true;
si_code = info->si_code;
regs->nip += 4;
}
int test_segv_errors(void)
{
struct sigaction act = {
.sa_sigaction = segv_handler,
.sa_flags = SA_SIGINFO,
};
char c, *p = NULL;
p = mmap(NULL, getpagesize(), 0, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
FAIL_IF(p == MAP_FAILED);
FAIL_IF(sigaction(SIGSEGV, &act, NULL) != 0);
faulted = false;
si_code = 0;
/*
* We just need a compiler barrier, but mb() works and has the nice
* property of being easy to spot in the disassembly.
*/
mb();
c = *p;
mb();
FAIL_IF(!faulted);
FAIL_IF(si_code != SEGV_ACCERR);
faulted = false;
si_code = 0;
mb();
*p = c;
mb();
FAIL_IF(!faulted);
FAIL_IF(si_code != SEGV_ACCERR);
return 0;
}
int main(void)
{
return test_harness(test_segv_errors, "segv_errors");
}
Annotation
- Immediate include surface: `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `signal.h`, `sys/mman.h`, `assert.h`.
- Detected declarations: `function segv_handler`, `function test_segv_errors`, `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.