tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c- Extension
.c- Size
- 3080 bytes
- Lines
- 148
- 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.hstdbool.hsignal.hunistd.hsys/mman.hword-at-a-time.hutils.h
Detected Declarations
struct extbl_entryfunction __flsfunction protect_regionfunction unprotect_regionfunction segv_handlerfunction setup_segv_handlerfunction do_one_testfunction test_bodyfunction main
Annotated Snippet
struct extbl_entry {
int insn;
int fixup;
};
static void segv_handler(int signr, siginfo_t *info, void *ptr)
{
ucontext_t *uc = (ucontext_t *)ptr;
unsigned long addr = (unsigned long)info->si_addr;
unsigned long *ip = &UCONTEXT_NIA(uc);
struct extbl_entry *entry = (struct extbl_entry *)__start___ex_table;
while (entry < (struct extbl_entry *)__stop___ex_table) {
unsigned long insn, fixup;
insn = (unsigned long)&entry->insn + entry->insn;
fixup = (unsigned long)&entry->fixup + entry->fixup;
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);
}
static int do_one_test(char *p, int page_offset)
{
unsigned long should;
unsigned long got;
FAIL_IF(unprotect_region());
should = *(unsigned long *)p;
FAIL_IF(protect_region());
got = load_unaligned_zeropad(p);
if (should != got) {
printf("offset %u load_unaligned_zeropad returned 0x%lx, should be 0x%lx\n", page_offset, got, should);
return 1;
}
return 0;
}
static int test_body(void)
{
unsigned long i;
page_size = getpagesize();
mem_region = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
FAIL_IF(mem_region == MAP_FAILED);
for (i = 0; i < page_size; i++)
mem_region[i] = i;
memset(mem_region+page_size, 0, page_size);
setup_segv_handler();
for (i = 0; i < page_size; i++)
FAIL_IF(do_one_test(mem_region+i, i));
return 0;
}
int main(void)
{
return test_harness(test_body, "load_unaligned_zeropad");
}
Annotation
- Immediate include surface: `stdlib.h`, `string.h`, `stdio.h`, `stdbool.h`, `signal.h`, `unistd.h`, `sys/mman.h`, `word-at-a-time.h`.
- Detected declarations: `struct extbl_entry`, `function __fls`, `function protect_region`, `function unprotect_region`, `function segv_handler`, `function setup_segv_handler`, `function do_one_test`, `function test_body`, `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.