aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/arm64/signal/testcases/fpmr_siginfo.c
blob: e9d24685e74194fc4ed1aebdcfd4c6edd3488e1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2023 ARM Limited
 *
 * Verify that the FPMR register context in signal frames is set up as
 * expected.
 */

#include <signal.h>
#include <ucontext.h>
#include <sys/auxv.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <asm/sigcontext.h>

#include "test_signals_utils.h"
#include "testcases.h"

static union {
	ucontext_t uc;
	char buf[1024 * 128];
} context;

#define SYS_FPMR "S3_3_C4_C4_2"

static uint64_t get_fpmr(void)
{
	uint64_t val;

	asm volatile (
		"mrs	%0, " SYS_FPMR "\n"
		: "=r"(val)
		:
		: "cc");

	return val;
}

int fpmr_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
{
	struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
	struct fpmr_context *fpmr_ctx;
	size_t offset;
	bool in_sigframe;
	bool have_fpmr;
	__u64 orig_fpmr;

	have_fpmr = getauxval(AT_HWCAP2) & HWCAP2_FPMR;
	if (have_fpmr)
		orig_fpmr = get_fpmr();

	if (!get_current_context(td, &context.uc, sizeof(context)))
		return 1;

	fpmr_ctx = (struct fpmr_context *)
		get_header(head, FPMR_MAGIC, td->live_sz, &offset);

	in_sigframe = fpmr_ctx != NULL;

	fprintf(stderr, "FPMR sigframe %s on system %s FPMR\n",
		in_sigframe ? "present" : "absent",
		have_fpmr ? "with" : "without");

	td->pass = (in_sigframe == have_fpmr);

	if (have_fpmr && fpmr_ctx) {
		if (fpmr_ctx->fpmr != orig_fpmr) {
			fprintf(stderr, "FPMR in frame is %llx, was %llx\n",
				fpmr_ctx->fpmr, orig_fpmr);
			td->pass = false;
		}
	}

	return 0;
}

struct tdescr tde = {
	.name = "FPMR",
	.descr = "Validate that FPMR is present as expected",
	.timeout = 3,
	.run = fpmr_present,
};