~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c

Version: ~ [ linux-5.15-rc3 ] ~ [ linux-5.14.8 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.69 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.149 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.208 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.248 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.284 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.285 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2015, Michael Neuling, IBM Corp.
  3  * Licensed under GPLv2.
  4  *
  5  * Test the kernel's signal return code to ensure that it doesn't
  6  * crash when both the transactional and suspend MSR bits are set in
  7  * the signal context.
  8  *
  9  * For this test, we send ourselves a SIGUSR1.  In the SIGUSR1 handler
 10  * we modify the signal context to set both MSR TM S and T bits (which
 11  * is "reserved" by the PowerISA). When we return from the signal
 12  * handler (implicit sigreturn), the kernel should detect reserved MSR
 13  * value and send us with a SIGSEGV.
 14  */
 15 
 16 #include <stdlib.h>
 17 #include <stdio.h>
 18 #include <signal.h>
 19 #include <unistd.h>
 20 
 21 #include "utils.h"
 22 #include "tm.h"
 23 
 24 int segv_expected = 0;
 25 
 26 void signal_segv(int signum)
 27 {
 28         if (segv_expected && (signum == SIGSEGV))
 29                 _exit(0);
 30         _exit(1);
 31 }
 32 
 33 void signal_usr1(int signum, siginfo_t *info, void *uc)
 34 {
 35         ucontext_t *ucp = uc;
 36 
 37         /* Link tm checkpointed context to normal context */
 38         ucp->uc_link = ucp;
 39         /* Set all TM bits so that the context is now invalid */
 40 #ifdef __powerpc64__
 41         ucp->uc_mcontext.gp_regs[PT_MSR] |= (7ULL << 32);
 42 #else
 43         ucp->uc_mcontext.uc_regs->gregs[PT_MSR] |= (7ULL);
 44 #endif
 45         /* Should segv on return becuase of invalid context */
 46         segv_expected = 1;
 47 }
 48 
 49 int tm_signal_msr_resv()
 50 {
 51         struct sigaction act;
 52 
 53         SKIP_IF(!have_htm());
 54 
 55         act.sa_sigaction = signal_usr1;
 56         sigemptyset(&act.sa_mask);
 57         act.sa_flags = SA_SIGINFO;
 58         if (sigaction(SIGUSR1, &act, NULL) < 0) {
 59                 perror("sigaction sigusr1");
 60                 exit(1);
 61         }
 62         if (signal(SIGSEGV, signal_segv) == SIG_ERR)
 63                 exit(1);
 64 
 65         raise(SIGUSR1);
 66 
 67         /* We shouldn't get here as we exit in the segv handler */
 68         return 1;
 69 }
 70 
 71 int main(void)
 72 {
 73         return test_harness(tm_signal_msr_resv, "tm_signal_msr_resv");
 74 }
 75 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp