tools/testing/selftests/powerpc/alignment/copy_first_unaligned.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/alignment/copy_first_unaligned.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/alignment/copy_first_unaligned.c- Extension
.c- Size
- 1659 bytes
- Lines
- 68
- 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
signal.hstring.hunistd.hutils.hinstructions.h
Detected Declarations
function signal_action_handlerfunction setup_signal_handlerfunction test_copy_first_unalignedfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2016, Chris Smart, IBM Corporation.
*
* Calls to copy_first which are not 128-byte aligned should be
* caught and sent a SIGBUS.
*/
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include "utils.h"
#include "instructions.h"
unsigned int expected_instruction = PPC_INST_COPY_FIRST;
unsigned int instruction_mask = 0xfc2007fe;
void signal_action_handler(int signal_num, siginfo_t *info, void *ptr)
{
ucontext_t *ctx = ptr;
#ifdef __powerpc64__
unsigned int *pc = (unsigned int *)ctx->uc_mcontext.gp_regs[PT_NIP];
#else
unsigned int *pc = (unsigned int *)ctx->uc_mcontext.uc_regs->gregs[PT_NIP];
#endif
/*
* Check that the signal was on the correct instruction, using a
* mask because the compiler assigns the register at RB.
*/
if ((*pc & instruction_mask) == expected_instruction)
_exit(0); /* We hit the right instruction */
_exit(1);
}
void setup_signal_handler(void)
{
struct sigaction signal_action;
memset(&signal_action, 0, sizeof(signal_action));
signal_action.sa_sigaction = signal_action_handler;
signal_action.sa_flags = SA_SIGINFO;
sigaction(SIGBUS, &signal_action, NULL);
}
char cacheline_buf[128] __cacheline_aligned;
int test_copy_first_unaligned(void)
{
/* Only run this test on a P9 or later */
SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_00));
/* Register our signal handler with SIGBUS */
setup_signal_handler();
/* +1 makes buf unaligned */
copy_first(cacheline_buf+1);
/* We should not get here */
return 1;
}
int main(int argc, char *argv[])
{
return test_harness(test_copy_first_unaligned, "test_copy_first_unaligned");
}
Annotation
- Immediate include surface: `signal.h`, `string.h`, `unistd.h`, `utils.h`, `instructions.h`.
- Detected declarations: `function signal_action_handler`, `function setup_signal_handler`, `function test_copy_first_unaligned`, `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.