tools/testing/selftests/powerpc/copyloops/exc_validate.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/copyloops/exc_validate.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/copyloops/exc_validate.c- Extension
.c- Size
- 2688 bytes
- Lines
- 125
- 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
stdlib.hstring.hstdio.hsignal.hunistd.hsys/mman.hutils.h
Detected Declarations
function segv_handlerfunction setup_segv_handlerfunction do_one_testfunction test_copy_exceptionfunction main
Annotated Snippet
if (insn == *ip) {
*ip = fixup;
return;
}
}
printf("No exception table match for NIA %lx ADDR %lx\n", *ip, addr);
abort();
}
static void setup_segv_handler(void)
{
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_sigaction = segv_handler;
action.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &action, NULL);
}
unsigned long COPY_LOOP(void *to, const void *from, unsigned long size);
unsigned long test_copy_tofrom_user_reference(void *to, const void *from, unsigned long size);
static int total_passed;
static int total_failed;
static void do_one_test(char *dstp, char *srcp, unsigned long len)
{
unsigned long got, expected;
got = COPY_LOOP(dstp, srcp, len);
expected = test_copy_tofrom_user_reference(dstp, srcp, len);
if (got != expected) {
total_failed++;
printf("FAIL from=%p to=%p len=%ld returned %ld, expected %ld\n",
srcp, dstp, len, got, expected);
//abort();
} else
total_passed++;
}
//#define MAX_LEN 512
#define MAX_LEN 16
int test_copy_exception(void)
{
int page_size;
static char *p, *q;
unsigned long src, dst, len;
page_size = getpagesize();
p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) {
perror("mmap");
exit(1);
}
memset(p, 0, page_size);
setup_segv_handler();
if (mprotect(p + page_size, page_size, PROT_NONE)) {
perror("mprotect");
exit(1);
}
q = p + page_size - MAX_LEN;
for (src = 0; src < MAX_LEN; src++) {
for (dst = 0; dst < MAX_LEN; dst++) {
for (len = 0; len < MAX_LEN+1; len++) {
// printf("from=%p to=%p len=%ld\n", q+dst, q+src, len);
do_one_test(q+dst, q+src, len);
}
}
}
printf("Totals:\n");
printf(" Pass: %d\n", total_passed);
printf(" Fail: %d\n", total_failed);
return 0;
}
int main(void)
{
return test_harness(test_copy_exception, str(COPY_LOOP));
Annotation
- Immediate include surface: `stdlib.h`, `string.h`, `stdio.h`, `signal.h`, `unistd.h`, `sys/mman.h`, `utils.h`.
- Detected declarations: `function segv_handler`, `function setup_segv_handler`, `function do_one_test`, `function test_copy_exception`, `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.