subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1563971 - /subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
Date Mon, 03 Feb 2014 16:12:26 GMT
Author: brane
Date: Mon Feb  3 16:12:26 2014
New Revision: 1563971

URL: http://svn.apache.org/r1563971
Log:
Added a malfunction handler to the JavaHL native implementation that
in most cases causes a SEGV, or returns an error, instaed of calling
abort(). Aborting prevents the JVM from creating a crash log file.

* subversion/bindings/javahl/native/JNIUtil.cpp: Include svn_error.h.
  (gentle_crash_write_loc): New; volatile NULL pointer.
  (gently_crash_the_jvm): New; malfunction handler.
  (JNIUtil::JNIGlobalInit): Register gently_crash_the_jvm().

Modified:
    subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp

Modified: subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1563971&r1=1563970&r2=1563971&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp Mon Feb  3 16:12:26 2014
@@ -46,6 +46,7 @@
 #include <apr_time.h>
 
 #include "svn_pools.h"
+#include "svn_error.h"
 #include "svn_fs.h"
 #include "svn_ra.h"
 #include "svn_utf.h"
@@ -117,6 +118,33 @@ bool initialize_jni_util(JNIEnv *env)
   return JNIUtil::JNIGlobalInit(env);
 }
 
+namespace {
+
+volatile apr_int32_t *gentle_crash_write_loc = NULL;
+
+svn_error_t *
+gently_crash_the_jvm(svn_boolean_t can_return,
+                     const char *file, int line, const char *expr)
+{
+  if (!can_return)
+    {
+      // Try not to abort; aborting prevents the JVM from creating
+      // a crash log, which is oh so useful for debugging.
+      // We can't just raise a SEGV signal, either, because it will
+      // be not be caught in the context that we're interested in
+      // getting the stack trace from.
+
+      // Try writing to the zero page
+      *gentle_crash_write_loc = 0xdeadbeef;
+    }
+
+  // Forward to the standard malfunction handler, which does call
+  // abort when !can_return; this will only happen if the write to the
+  // zero page did not cause a SEGV.
+  return svn_error_raise_on_malfunction(can_return, file, line, expr);
+}
+} // Anonymous namespace
+
 /**
  * Initialize the environment for all requests.
  * This method must be called in a single-threaded context.
@@ -244,6 +272,10 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
   if (isExceptionThrown())
     return false;
 
+  // Set a malfunction handler that tries not to call abort, because
+  // that would prevent the JVM from creating a crash and stack log file.
+  svn_error_set_malfunction_handler(gently_crash_the_jvm);
+
   return true;
 }
 



Mime
View raw message