Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright 2018, Breno Leitao, Gustavo Romero, IBM Corp.
0004  *
0005  * A test case that creates a signal and starts a suspended transaction
0006  * inside the signal handler.
0007  *
0008  * It returns from the signal handler with the CPU at suspended state, but
0009  * without setting usercontext MSR Transaction State (TS) fields.
0010  */
0011 
0012 #define _GNU_SOURCE
0013 #include <stdio.h>
0014 #include <stdlib.h>
0015 #include <signal.h>
0016 
0017 #include "utils.h"
0018 #include "tm.h"
0019 
0020 void trap_signal_handler(int signo, siginfo_t *si, void *uc)
0021 {
0022     ucontext_t *ucp = (ucontext_t *) uc;
0023 
0024     asm("tbegin.; tsuspend.;");
0025 
0026     /* Skip 'trap' instruction if it succeed */
0027     ucp->uc_mcontext.regs->nip += 4;
0028 }
0029 
0030 int tm_signal_sigreturn_nt(void)
0031 {
0032     struct sigaction trap_sa;
0033 
0034     SKIP_IF(!have_htm());
0035     SKIP_IF(htm_is_synthetic());
0036 
0037     trap_sa.sa_flags = SA_SIGINFO;
0038     trap_sa.sa_sigaction = trap_signal_handler;
0039 
0040     sigaction(SIGTRAP, &trap_sa, NULL);
0041 
0042     raise(SIGTRAP);
0043 
0044     return EXIT_SUCCESS;
0045 }
0046 
0047 int main(int argc, char **argv)
0048 {
0049     test_harness(tm_signal_sigreturn_nt, "tm_signal_sigreturn_nt");
0050 }
0051