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

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

Version: ~ [ linux-5.6-rc1 ] ~ [ linux-5.5.2 ] ~ [ linux-5.4.17 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.102 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.170 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.213 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.213 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ 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 delievery code to ensure that we don't
  6  * trelaim twice in the kernel signal delivery code.  This can happen
  7  * if we trigger a signal when in a transaction and the stack pointer
  8  * is bogus.
  9  *
 10  * This test case registers a SEGV handler, sets the stack pointer
 11  * (r1) to NULL, starts a transaction and then generates a SEGV.  The
 12  * SEGV should be handled but we exit here as the stack pointer is
 13  * invalid and hance we can't sigreturn.  We only need to check that
 14  * this flow doesn't crash the kernel.
 15  */
 16 
 17 #include <unistd.h>
 18 #include <sys/types.h>
 19 #include <sys/wait.h>
 20 #include <stdlib.h>
 21 #include <stdio.h>
 22 #include <signal.h>
 23 
 24 #include "utils.h"
 25 #include "tm.h"
 26 
 27 void signal_segv(int signum)
 28 {
 29         /* This should never actually run since stack is foobar */
 30         exit(1);
 31 }
 32 
 33 int tm_signal_stack()
 34 {
 35         int pid;
 36 
 37         SKIP_IF(!have_htm());
 38 
 39         pid = fork();
 40         if (pid < 0)
 41                 exit(1);
 42 
 43         if (pid) { /* Parent */
 44                 /*
 45                  * It's likely the whole machine will crash here so if
 46                  * the child ever exits, we are good.
 47                  */
 48                 wait(NULL);
 49                 return 0;
 50         }
 51 
 52         /*
 53          * The flow here is:
 54          * 1) register a signal handler (so signal delievery occurs)
 55          * 2) make stack pointer (r1) = NULL
 56          * 3) start transaction
 57          * 4) cause segv
 58          */
 59         if (signal(SIGSEGV, signal_segv) == SIG_ERR)
 60                 exit(1);
 61         asm volatile("li 1, 0 ;"                /* stack ptr == NULL */
 62                      "1:"
 63                      "tbegin.;"
 64                      "beq 1b ;"                 /* retry forever */
 65                      "tsuspend.;"
 66                      "ld 2, 0(1) ;"             /* trigger segv" */
 67                      : : : "memory");
 68 
 69         /* This should never get here due to above segv */
 70         return 1;
 71 }
 72 
 73 int main(void)
 74 {
 75         return test_harness(tm_signal_stack, "tm_signal_stack");
 76 }
 77 

~ [ 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