hotspot/test/runtime/libadimalloc.solaris.sparc/liboverflow.c
author gthornbr
Wed, 18 Nov 2015 09:32:52 -0800
changeset 34233 2cf348387c44
permissions -rw-r--r--
8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file Summary: Add libadimalloc.so SIGSEGV defines and a test to validate the correct message is printed in the hs_err file Reviewed-by: dcubed, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     1
/*
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     4
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     8
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    13
 * accompanied this code).
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    14
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    18
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    21
 * questions.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    22
 */
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    23
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    24
#include <stdio.h>
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    25
#include <stdlib.h>
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    26
#include <string.h>
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    27
#include <unistd.h>
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    28
#include <jni.h>
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    29
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    30
#ifdef __cplusplus
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    31
extern "C" {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    32
#endif
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    33
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    34
JNIEXPORT jstring JNICALL Java_SEGVOverflow_nativesegv(JNIEnv *env, jobject obj) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    35
  char *buffer1;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    36
  char *buffer2;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    37
  char *buffer3;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    38
  char ch;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    39
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    40
  jstring ret = NULL;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    41
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    42
  // sleep for a bit to let the libadimalloc library initialize
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    43
  sleep(5);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    44
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    45
  // allocate three buffers
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    46
  buffer1 = (char *)malloc(64);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    47
  buffer2 = (char *)malloc(64);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    48
  buffer3 = (char *)malloc(64);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    49
  if ((buffer1 == NULL) || (buffer2 == NULL) || (buffer3 == NULL)) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    50
    // this return will result in a test failure
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    51
    return ret;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    52
  }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    53
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    54
  // Read past the end of each buffer multiple times to increase the probability
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    55
  // that an ADI version mismatch occurs so an ADI fault is triggered.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    56
  ch = buffer1[70];
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    57
  ch = buffer2[70];
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    58
  ch = buffer3[70];
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    59
  ch = buffer1[140];
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    60
  ch = buffer2[140];
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    61
  ch = buffer3[140];
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    62
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    63
  // create a failed test return value because this test should have cored
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    64
  buffer1 = "TEST FAILED, a read past the end of a buffer succeeded.";
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    65
  ret = (*env)->NewStringUTF(env, buffer1);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    66
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    67
  return ret;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    68
}
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    69
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    70
#ifdef __cplusplus
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    71
}
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    72
#endif