tools/testing/selftests/powerpc/mm/wild_bctr.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/mm/wild_bctr.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/mm/wild_bctr.c
Extension
.c
Size
3508 bytes
Lines
171
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct opd {
	unsigned long ip;
	unsigned long toc;
	unsigned long env;
};
static struct opd bad_opd = {
	.ip = BAD_NIP,
};
#define BAD_FUNC (&bad_opd)
#else
#define BAD_FUNC BAD_NIP
#endif

int test_wild_bctr(void)
{
	int (*func_ptr)(void);
	struct sigaction segv = {
		.sa_sigaction = segv_handler,
		.sa_flags = SA_SIGINFO
	};
	struct sigaction usr2 = {
		.sa_sigaction = usr2_handler,
		.sa_flags = SA_SIGINFO
	};

	FAIL_IF(sigaction(SIGSEGV, &segv, NULL));
	FAIL_IF(sigaction(SIGUSR2, &usr2, NULL));

	bzero(&signal_regs, sizeof(signal_regs));

	if (setjmp(setjmp_env) == 0) {
		func_ptr = ok;
		func_ptr();

		kill(getpid(), SIGUSR2);
		printf("Regs before:\n");
		dump_regs();
		bzero(&signal_regs, sizeof(signal_regs));

		poison_regs();

		func_ptr = (int (*)(void))BAD_FUNC;
		func_ptr();

		FAIL_IF(1); /* we didn't segv? */
	}

	FAIL_IF(signal_regs.nip != BAD_NIP);

	printf("All good - took SEGV as expected branching to 0x%llx\n", BAD_NIP);

	dump_regs();
	FAIL_IF(check_regs());

	return 0;
}

int main(void)
{
	return test_harness(test_wild_bctr, "wild_bctr");
}

Annotation

Implementation Notes