1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2016, Cyril Bur, IBM Corp.
5 * Test the kernel's signal frame code.
7 * The kernel sets up two sets of ucontexts if the signal was to be
8 * delivered while the thread was in a transaction.
9 * Expected behaviour is that the checkpointed state is in the user
10 * context passed to the signal handler. The speculated state can be
11 * accessed with the uc_link pointer.
13 * The rationale for this is that if TM unaware code (which linked
14 * against TM libs) installs a signal handler it will not know of the
15 * speculative nature of the 'live' registers and may infer the wrong
29 #define MAX_ATTEMPT 500000
31 #define NV_GPR_REGS 18
33 long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
35 static sig_atomic_t fail;
37 static long gps[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
38 -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18};
40 static void signal_usr1(int signum, siginfo_t *info, void *uc)
44 ucontext_t *tm_ucp = ucp->uc_link;
46 for (i = 0; i < NV_GPR_REGS && !fail; i++) {
47 fail = (ucp->uc_mcontext.gp_regs[i + 14] != gps[i]);
48 fail |= (tm_ucp->uc_mcontext.gp_regs[i + 14] != gps[i + NV_GPR_REGS]);
50 printf("Failed on %d GPR %lu or %lu\n", i,
51 ucp->uc_mcontext.gp_regs[i + 14], tm_ucp->uc_mcontext.gp_regs[i + 14]);
55 static int tm_signal_context_chk_gpr()
64 act.sa_sigaction = signal_usr1;
65 sigemptyset(&act.sa_mask);
66 act.sa_flags = SA_SIGINFO;
67 if (sigaction(SIGUSR1, &act, NULL) < 0) {
68 perror("sigaction sigusr1");
73 while (i < MAX_ATTEMPT && !fail) {
74 rc = tm_signal_self_context_load(pid, gps, NULL, NULL, NULL);
84 return test_harness(tm_signal_context_chk_gpr, "tm_signal_context_chk_gpr");