1 # Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
   2 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3 #
   4 # This code is free software; you can redistribute it and/or modify it
   5 # under the terms of the GNU General Public License version 2 only, as
   6 # published by the Free Software Foundation.
   7 #
   8 # This code is distributed in the hope that it will be useful, but WITHOUT
   9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11 # version 2 for more details (a copy is included in the LICENSE file that
  12 # accompanied this code).
  13 #
  14 # You should have received a copy of the GNU General Public License version
  15 # 2 along with this work; if not, write to the Free Software Foundation,
  16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17 #
  18 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19 # or visit www.oracle.com if you need additional information or have any
  20 # questions.
  21 #!/bin/sh
  22 
  23 #
  24 # @test testme.sh
  25 # @bug 8197429
  26 # @summary Linux kernel stack guard should not cause segfaults on x86-32
  27 # @compile T.java
  28 # @run shell testme.sh
  29 #
  30 
  31 if [ "${TESTSRC}" = "" ]
  32 then
  33   TESTSRC=${PWD}
  34   echo "TESTSRC not set.  Using "${TESTSRC}" as default"
  35 fi
  36 echo "TESTSRC=${TESTSRC}"
  37 ## Adding common setup Variables for running shell tests.
  38 . ${TESTSRC}/../../test_env.sh
  39 
  40 if [ "${VM_OS}" != "linux" ]
  41 then
  42   echo "Test only valid for Linux"
  43   exit 0
  44 fi
  45 
  46 gcc_cmd=`which gcc`
  47 if [ "x$gcc_cmd" = "x" ]; then
  48     echo "WARNING: gcc not found. Cannot execute test." 2>&1
  49     exit 0;
  50 fi
  51 
  52 CFLAGS="-m${VM_BITS}"
  53 
  54 LD_LIBRARY_PATH=.:${COMPILEJAVA}/jre/lib/${VM_CPU}/${VM_TYPE}:/usr/lib:$LD_LIBRARY_PATH
  55 export LD_LIBRARY_PATH
  56 
  57 cp ${TESTSRC}${FS}exestack-gap.c .
  58 
  59 # Copy the result of our @compile action:
  60 cp ${TESTCLASSES}${FS}T.class .
  61 
  62 echo "Compilation flag: ${COMP_FLAG}"
  63 # Note pthread may not be found thus invoke creation will fail to be created.
  64 # Check to ensure you have a /usr/lib/libpthread.so if you don't please look
  65 # for /usr/lib/`uname -m`-linux-gnu version ensure to add that path to below compilation.
  66 
  67 $gcc_cmd -DLINUX ${CFLAGS} -o stack-gap \
  68     -I${COMPILEJAVA}/include -I${COMPILEJAVA}/include/linux \
  69     -L${COMPILEJAVA}/jre/lib/${VM_CPU}/${VM_TYPE} \
  70     -ljvm -lpthread exestack-gap.c
  71 
  72 ./stack-gap || exit $?
  73 ./stack-gap -XX:+DisablePrimordialThreadGuardPages || exit $?