You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/12 20:33:15 UTC

svn commit: r1091533 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/jniapi.h include/acr/misc.h os/unix/init.c shared/native.c

Author: mturk
Date: Tue Apr 12 18:33:14 2011
New Revision: 1091533

URL: http://svn.apache.org/viewvc?rev=1091533&view=rev
Log:
Axe signaling for unix platforms. JVM requires libjsig.so to be preloaded if standard mechanism is used

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
    commons/sandbox/runtime/trunk/src/main/native/shared/native.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h?rev=1091533&r1=1091532&r2=1091533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h Tue Apr 12 18:33:14 2011
@@ -30,9 +30,6 @@ typedef struct acr_exc_t
     int         line;
     int         code;
     int         init;
-#if !defined(WINDOWS)
-    sigjmp_buf  jump;
-#endif
 } acr_exc_t;
 
 /**
@@ -49,9 +46,8 @@ typedef struct acr_tlsd_t  {
     acr_tls_destructor_t        dtor;
 } acr_tlsd_t;
 
-#if HAVE_THREAD_LOCAL
-extern ACR_THREAD acr_exc_t     acr_exception_frame;
 #if defined(WINDOWS)
+extern ACR_THREAD acr_exc_t     acr_exception_frame;
 /* Use Microsoft Structured Exception Handling wrapper
  * The _set_se_translator is used to call the AcrExceptionHandler.
  * This requires the /EHa exception model to be used
@@ -68,24 +64,6 @@ extern ACR_THREAD acr_exc_t     acr_exce
 #define __SEH_CATCH                                                         \
    catch(...)
 
-#else
-/* Use exception_frame to save per-thread jmp_buf
- * Signal handler routine will jump into the __SEH_CATCH block
- * with code set to signal number
- */
-#define __SEH_TRY                                                           \
-    acr_exception_frame.file = __FILE__;                                    \
-    acr_exception_frame.line = __LINE__;                                    \
-    acr_exception_frame.func = __REAL_FUNCSIG__;                            \
-    acr_exception_frame.desc = 0;                                           \
-    acr_exception_frame.code = 0;                                           \
-    acr_exception_frame.init = 1;                                           \
-    if (sigsetjmp(acr_exception_frame.jump, 1) == 0)
-
-#define __SEH_CATCH                                                         \
-    else
-
-#endif
 #else /* HAVE_THREAD_LOCAL */
 #define __SEH_TRY
 #define __SEH_CATCH     if (0)
@@ -98,8 +76,6 @@ extern "C" {
 /* Called by a signal handler */
 #if defined(WINDOWS)
 void AcrExceptionHandler(unsigned int, struct _EXCEPTION_POINTERS *);
-#else
-void AcrExceptionHandler(int);
 #endif
 const char *
 AcrExceptionDescription(void);

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h?rev=1091533&r1=1091532&r2=1091533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h Tue Apr 12 18:33:14 2011
@@ -28,9 +28,6 @@ AcrLibLockAcquire(void);
 void
 AcrLibLockRelease(void);
 
-int
-AcrSignalsInit(void);
-
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c?rev=1091533&r1=1091532&r2=1091533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c Tue Apr 12 18:33:14 2011
@@ -25,84 +25,6 @@ static JavaVM           *_java_vm = 0;
 static pthread_key_t     _threadkey;
 static volatile int      _threadkey_inited = 0;
 static pthread_mutex_t   _lib_mutex  = PTHREAD_MUTEX_INITIALIZER;
-static struct sigaction *_signalset;
-
-#if HAVE_THREAD_LOCAL
-ACR_THREAD acr_exc_t   acr_exception_frame = { 0, 0, 0, 0, 0, 0 };
-/*
- * 1. Signals SIGKILL, SIGSTOP cannot be blocked.
- * 2. Signals SIGCONT, SIGTSTP, SIGTTIN, SIGTTOU are not blocked because
- *    dealing with these signals is dangerous.
- * 3. Signals SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTRAP, SIGIOT, SIGEMT,
- *    SIGBUS, SIGSYS, SIGSTKFLT are not blocked because these are synchronous
- *    signals, which may require immediate intervention, otherwise the
- *    process may starve.
- */
-static int sig_blocked[] = {
-#ifdef SIGHUP
-    SIGHUP,
-#endif
-#ifdef SIGINT
-    SIGINT,
-#endif
-#ifdef SIGQUIT
-    SIGQUIT,
-#endif
-#ifdef SIGPIPE
-    SIGPIPE,
-#endif
-#ifdef SIGALRM
-    SIGALRM,
-#endif
-#ifdef SIGTERM
-    SIGTERM,
-#endif
-#ifdef SIGUSR1
-    SIGUSR1,
-#endif
-#ifdef SIGUSR2
-    SIGUSR2,
-#endif
-#ifdef SIGCHLD
-    SIGCHLD,
-#endif
-#ifdef SIGCLD
-    SIGCLD,
-#endif
-#ifdef SIGURG
-    SIGURG,
-#endif
-#ifdef SIGIO
-    SIGIO,
-#endif
-#ifdef SIGPOLL
-    SIGPOLL,
-#endif
-#ifdef SIGXCPU
-    SIGXCPU,
-#endif
-#ifdef SIGXFSZ
-    SIGXFSZ,
-#endif
-#ifdef SIGVTALRM
-    SIGVTALRM,
-#endif
-#ifdef SIGPROF
-    SIGPROF,
-#endif
-#ifdef SIGPWR
-    SIGPWR,
-#endif
-#ifdef SIGLOST
-    SIGLOST,
-#endif
-#ifdef SIGWINCH
-    SIGWINCH,
-#endif
-    -1
-};
-
-#endif
 
 typedef struct tlsd_t
 {
@@ -154,67 +76,6 @@ static tlsd_t *_threadkey_get(void)
     return env;
 }
 
-static int _sigs_inited = 0;
-int
-AcrSignalsInit()
-{
-    int i, rc = 0;
-    struct sigaction *ssp;
-
-    if (_sigs_inited++)
-        return 0;
-    ssp = _signalset = malloc(ACR_NUMSIG * sizeof(struct sigaction));
-    for (i = 0; i < ACR_NUMSIG; i++) {
-        struct sigaction act;
-
-        memset(&act, 0, sizeof(struct sigaction));
-        sigemptyset(&act.sa_mask);
-        act.sa_handler = SIG_DFL;
-        act.sa_flags   = 0;
-#ifdef SA_INTERRUPT             /* SunOS */
-        act.sa_flags |= SA_INTERRUPT;
-#endif
-        if (sigaction(i, &act, ssp) == 0) {
-            /* Restore the original saved sigaction.
-             * ###: Is there a smarter way for getting the
-             * original signal handlers?
-             */
-            sigaction(i, ssp, &act);
-        }
-        else {
-            /* Those are for SIGKILL and SIGSTOP
-             * which cannot be caught or ignored.
-             */
-            ssp->sa_handler = SIG_ERR;
-        }
-        ++ssp;
-    }
-#if HAVE_THREAD_LOCAL
-    {
-        struct sigaction act;
-        memset(&act, 0, sizeof(struct sigaction));
-        sigemptyset(&act.sa_mask);
-        act.sa_handler = SIG_DFL; //AcrExceptionHandler;
-        act.sa_flags   = 0;
-#ifdef SA_INTERRUPT
-        act.sa_flags  |= SA_INTERRUPT;
-#endif
-        for (i = 0; sig_blocked[i] > 0; i++) {
-            /* Block most signals during SIGSEGV handling
-             */
-            sigaddset(&act.sa_mask, sig_blocked[i]);
-        }
-        /* Handle SIGSEGV signal
-         */
-        sigaction(SIGSEGV, &act, 0);
-#if defined(HPUX11) || defined(DARWIN)
-        sigaction(SIGBUS,  &act, 0);
-#endif
-    }        
-#endif
-    return rc;
-}
-
 void
 AcrLibLockAcquire()
 {
@@ -284,77 +145,12 @@ AcrGetJNIEnv()
     return tlsd->env;
 }
 
-#if HAVE_THREAD_LOCAL
-void AcrExceptionHandler(int sig)
-{
-    printf("Exception Handler for %d\n", sig);
-    if (sig == SIGSEGV || sig == SIGBUS) {
-        if (acr_exception_frame.init) {
-            acr_exception_frame.init = 0;
-            acr_exception_frame.code = sig;
-#if defined(_DEBUG) || defined(DEBUG)
-            AcrDebugPrintf(acr_exception_frame.file,
-                           acr_exception_frame.func,
-                           acr_exception_frame.line,
-                           "Executing SEH handler for %s", strsignal(sig));
-#endif
-            siglongjmp(acr_exception_frame.jump, 1);
-        }
-        else if (_signalset[sig].sa_handler != SIG_DFL &&
-                 _signalset[sig].sa_handler != SIG_IGN &&
-                 _signalset[sig].sa_handler != SIG_ERR) {
-            AcrDebugPrintf(acr_exception_frame.file,
-                           acr_exception_frame.func,
-                           acr_exception_frame.line,
-                           "Executing default handler for %s", strsignal(sig));
-            /* This should invoke JVM crash report
-             */
-            (*_signalset[sig].sa_handler)(sig);
-        }
-        else {
-            AcrDebugPrintf(acr_exception_frame.file,
-                           acr_exception_frame.func,
-                           acr_exception_frame.line,
-                           "Cannot find default handler for %s", strsignal(sig));
-            abort();
-        }
-    }    
-}
-const char *
-AcrExceptionDescription()
-{
-    return strsignal(acr_exception_frame.code);
-}
-
-#else
-void AcrExceptionHandler(int sig)
-{
-    /* Not implemented */
-}
-
 const char *
 AcrExceptionDescription()
 {
     return 0;
 }
 
-#endif
-
-ACR_JNI_EXPORT(void, Native, fini0)(JNI_STDARGS)
-{
-    int i;
-    struct sigaction *ssp;
-
-    if (_sigs_inited != 0) {
-        _sigs_inited = 0;
-        ssp = _signalset;
-        for (i = 0; i < ACR_NUMSIG; i++) {
-            sigaction(i, ssp, 0);
-            ssp++;
-        }
-    }
-}
-
 #if defined(__GNUC__) || defined(__SUNPRO_C)
 void __attribute__ ((constructor))
 AcrLibraryAttach(void)

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=1091533&r1=1091532&r2=1091533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Tue Apr 12 18:33:14 2011
@@ -30,11 +30,17 @@ ACR_JNI_EXPORT(jboolean, Native, isdbg0)
 ACR_JNI_EXPORT(jboolean, Native, init0)(JNI_STDARGS)
 {
     if (_loaded)
-	return JNI_TRUE;
+        return JNI_TRUE;
     if (AcrLoadRuntimeClasses(env) != 0)
         return JNI_FALSE;
-    if (AcrSignalsInit() != 0)
-        return JNI_FALSE;
     _loaded = JNI_TRUE;
     return _loaded;
 }
+
+ACR_JNI_EXPORT(void, Native, fini0)(JNI_STDARGS)
+{
+    if (_loaded) {
+        _loaded = JNI_FALSE;    
+    }
+}
+