Debian Codegraph @

sysdeps/aarch64/tst-sme-signal.c

raw symbols SCIP
1 /* Test handling of SME state in a signal handler.
2 Copyright (C) 2025-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include "tst-sme-skeleton.c"
20
21 #include <support/xsignal.h>
22
23 static struct _aarch64_ctx *
24 extension (void *p)
25 {
26 return p;
27 }
28
29 #ifndef TPIDR2_MAGIC
30 #define TPIDR2_MAGIC 0x54504902
31 #endif
32
33 #ifndef ZA_MAGIC
34 #define ZA_MAGIC 0x54366345
35 #endif
36
37 #ifndef ZT_MAGIC
38 #define ZT_MAGIC 0x5a544e01
39 #endif
40
41 #ifndef EXTRA_MAGIC
42 #define EXTRA_MAGIC 0x45585401
43 #endif
44
45 /* We use a pipe to make sure that the final check of the SME state
46 happens after signal handler finished. */
47 static int pipefd[2];
48
49 #define WRITE(msg) xwrite (1, msg, sizeof (msg));
50
51 static void
52 handler (int signo, siginfo_t *si, void *ctx)
53 {
54 TEST_VERIFY (signo == SIGUSR1);
55 WRITE ("in the handler\n");
56 check_sme_za_state ("during signal", true /* State is clear. */);
57 ucontext_t *uc = ctx;
58 void *p = uc->uc_mcontext.__reserved;
59 unsigned int found = 0;
60 uint32_t m;
61 while ((m = extension (p)->magic))
62 {
63 if (m == TPIDR2_MAGIC)
64 {
65 WRITE ("found TPIDR2_MAGIC\n");
66 found += 1;
67 }
68 if (m == ZA_MAGIC)
69 {
70 WRITE ("found ZA_MAGIC\n");
71 found += 1;
72 }
73 if (m == ZT_MAGIC)
74 {
75 WRITE ("found ZT_MAGIC\n");
76 found += 1;
77 }
78 if (m == EXTRA_MAGIC)
79 {
80 WRITE ("found EXTRA_MAGIC\n");
81 struct { struct _aarch64_ctx h; uint64_t data; } *e = p;
82 p = (char *)e->data;
83 continue;
84 }
85 p = (char *)p + extension (p)->size;
86 }
87 TEST_COMPARE (found, 3);
88
89 /* Signal that the wait is over (see below). */
90 char message = '\0';
91 xwrite (pipefd[1], &message, 1);
92 }
93
94 static void
95 run (struct blk *blk)
96 {
97 xpipe (pipefd);
98
99 struct sigaction sigact;
100 sigemptyset (&sigact.sa_mask);
101 sigact.sa_flags = 0;
102 sigact.sa_flags |= SA_SIGINFO;
103 sigact.sa_sigaction = handler;
104 xsigaction (SIGUSR1, &sigact, NULL);
105
106 enable_sme_za_state (blk);
107 check_sme_za_state ("before signal", false /* State is not clear. */);
108 xraise (SIGUSR1);
109
110 /* Wait for signal handler to complete. */
111 char response;
112 xread (pipefd[0], &response, 1);
113
114 check_sme_za_state ("after signal", false /* State is not clear. */);
115 }