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 <stdio.h>
14#include <stdlib.h>
15#include <signal.h>
16
17#include "utils.h"
18#include "tm.h"
19
20void trap_signal_handler(int signo, siginfo_t *si, void *uc)
21{
22	ucontext_t *ucp = (ucontext_t *) uc;
23
24	asm("tbegin.; tsuspend.;");
25
26	/* Skip 'trap' instruction if it succeed */
27	ucp->uc_mcontext.regs->nip += 4;
28}
29
30int tm_signal_sigreturn_nt(void)
31{
32	struct sigaction trap_sa;
33
34	SKIP_IF(!have_htm());
35	SKIP_IF(htm_is_synthetic());
36
37	trap_sa.sa_flags = SA_SIGINFO;
38	trap_sa.sa_sigaction = trap_signal_handler;
39
40	sigaction(SIGTRAP, &trap_sa, NULL);
41
42	raise(SIGTRAP);
43
44	return EXIT_SUCCESS;
45}
46
47int main(int argc, char **argv)
48{
49	test_harness(tm_signal_sigreturn_nt, "tm_signal_sigreturn_nt");
50}
51
52