Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / tools / testing / selftests / powerpc / tm / tm-signal-sigreturn-nt.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2018, Breno Leitao, Gustavo Romero, IBM Corp.
4  *
5  * A test case that creates a signal and starts a suspended transaction
6  * inside the signal handler.
7  *
8  * It returns from the signal handler with the CPU at suspended state, but
9  * without setting usercontext MSR Transaction State (TS) fields.
10  */
11
12 #define _GNU_SOURCE
13 #include <stdlib.h>
14 #include <signal.h>
15
16 #include "utils.h"
17
18 void trap_signal_handler(int signo, siginfo_t *si, void *uc)
19 {
20         ucontext_t *ucp = (ucontext_t *) uc;
21
22         asm("tbegin.; tsuspend.;");
23
24         /* Skip 'trap' instruction if it succeed */
25         ucp->uc_mcontext.regs->nip += 4;
26 }
27
28 int tm_signal_sigreturn_nt(void)
29 {
30         struct sigaction trap_sa;
31
32         trap_sa.sa_flags = SA_SIGINFO;
33         trap_sa.sa_sigaction = trap_signal_handler;
34
35         sigaction(SIGTRAP, &trap_sa, NULL);
36
37         raise(SIGTRAP);
38
39         return EXIT_SUCCESS;
40 }
41
42 int main(int argc, char **argv)
43 {
44         test_harness(tm_signal_sigreturn_nt, "tm_signal_sigreturn_nt");
45 }
46