Path: blob/master/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c
26295 views
// SPDX-License-Identifier: GPL-2.01/*2* Copyright (C) 2022 ARM Limited3*4* Verify that the TPIDR2 register context in signal frames is set up as5* expected.6*/78#include <signal.h>9#include <ucontext.h>10#include <sys/auxv.h>11#include <sys/prctl.h>12#include <unistd.h>13#include <asm/sigcontext.h>1415#include "test_signals_utils.h"16#include "testcases.h"1718static union {19ucontext_t uc;20char buf[1024 * 128];21} context;2223#define SYS_TPIDR2 "S3_3_C13_C0_5"2425static uint64_t get_tpidr2(void)26{27uint64_t val;2829asm volatile (30"mrs %0, " SYS_TPIDR2 "\n"31: "=r"(val)32:33: "cc");3435return val;36}3738int tpidr2_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc)39{40struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);41struct tpidr2_context *tpidr2_ctx;42size_t offset;43bool in_sigframe;44bool have_sme;45__u64 orig_tpidr2;4647have_sme = getauxval(AT_HWCAP2) & HWCAP2_SME;48if (have_sme)49orig_tpidr2 = get_tpidr2();5051if (!get_current_context(td, &context.uc, sizeof(context)))52return 1;5354tpidr2_ctx = (struct tpidr2_context *)55get_header(head, TPIDR2_MAGIC, td->live_sz, &offset);5657in_sigframe = tpidr2_ctx != NULL;5859fprintf(stderr, "TPIDR2 sigframe %s on system %s SME\n",60in_sigframe ? "present" : "absent",61have_sme ? "with" : "without");6263td->pass = (in_sigframe == have_sme);6465/*66* Check that the value we read back was the one present at67* the time that the signal was triggered. TPIDR2 is owned by68* libc so we can't safely choose the value and it is possible69* that we may need to revisit this in future if something70* starts deciding to set a new TPIDR2 between us reading and71* the signal.72*/73if (have_sme && tpidr2_ctx) {74if (tpidr2_ctx->tpidr2 != orig_tpidr2) {75fprintf(stderr, "TPIDR2 in frame is %llx, was %llx\n",76tpidr2_ctx->tpidr2, orig_tpidr2);77td->pass = false;78}79}8081return 0;82}8384struct tdescr tde = {85.name = "TPIDR2",86.descr = "Validate that TPIDR2 is present as expected",87.timeout = 3,88.run = tpidr2_present,89};909192