Name: md23716 Date: 02/26/2001
HotSpot aborts if a signal handler has been installed previously. This is
a regression from JDK 1.1.8.
Testcase:
Testcase source code (sig_test.c):
#include <jni.h>
#include <stdio.h>
#include <signal.h>
#include <ucontext.h>
static JavaVMOption VM_OPTIONS[] = {
{"-Xmx16m", NULL},
{"-Djava.class.path=.", NULL},
/*
{"-XX:+AllowUserSignalHandlers", NULL},
*/
};
static const N_VM_OPTIONS = (sizeof(VM_OPTIONS)) /
(sizeof(JavaVMOption));
void start_jni(void)
{
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
vm_args.version = JNI_VERSION_1_2;
vm_args.options = VM_OPTIONS;
vm_args.nOptions = N_VM_OPTIONS;
vm_args.ignoreUnrecognized = JNI_FALSE;
fprintf(stderr, "About to create JVM\n");
res = JNI_CreateJavaVM(&jvm,(void**) &env, &vm_args);
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
fprintf(stderr, "About to delete JVM\n");
(*jvm)->DestroyJavaVM(jvm);
fprintf(stderr, "About to exit\n");
}
void sig_handler(int sig, siginfo_t *sip, void *uap)
{
char sigstr[4 + SIG2STR_MAX] = "SIG";
char *errstr;
sig2str(sig, sigstr+3);
if (sip)
{
psiginfo(sip, sigstr);
errstr = (sip->si_errno ? (char *)strerror(sip->si_errno)
: "NONE");
fprintf(stderr, "errno: %s [%i]\n", errstr, sip->si_errno);
}
else
{
psignal(sig, sigstr);
}
exit(1);
}
void add_handler(int sig)
{
struct sigaction act, oact;
act.sa_handler = 0;
act.sa_sigaction = sig_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
sigaction(sig, &act, &oact);
}
int main(int argc, char *argv[])
{
int sig;
const char *sigstr = (argc > 1 ? argv[1] : "");
if (strcmp(sigstr, "") != 0)
{
if (strncmp(sigstr, "SIG", 3) == 0)
{
sigstr += 3;
}
if (str2sig(sigstr, &sig) == 0)
{
add_handler(sig);
}
else
{
fprintf(stderr, "Unknown signal: %s\n", sigstr);
}
}
start_jni();
return 0;
}
Testcase shell script (SigTest.sh):
#!/bin/sh
INC="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris"
LIB="-L${JAVA_HOME}/jre/lib/sparc"
cc -mt ${INC} ${LIB} -o sig_test sig_test.c -ljvm
truss -aelf -o truss.out ./sig_test $*
Usage:
./SigTest.sh <signal name>
Fails for:
./SigTest.sh SIGILL
./SigTest.sh SIGFPE
./SigTest.sh SIGBUS
./SigTest.sh SIGSEGV
./SigTest.sh SIGPIPE
./SigTest.sh SIGUSR1
Failure Output:
About to create JVM
#
# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
[error occured during error reporting]
======================================================================
gary.collins@East 2001-02-26