Disable SIGSEGV signal handler if run in JVM
authorAndrii Grynenko <andrii@fb.com>
Wed, 8 Jun 2016 01:30:18 +0000 (18:30 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Wed, 8 Jun 2016 01:38:26 +0000 (18:38 -0700)
Reviewed By: ldemailly

Differential Revision: D3402550

fbshipit-source-id: 3de47c569868545c3861dab9a7b244ed8fb1fadf

folly/fibers/GuardPageAllocator.cpp

index 87dc8f91ffe75760699b1717741e31aefccb81d5..96595946f197366ed3ae7704944ce9a4070194db 100644 (file)
@@ -15,6 +15,9 @@
  */
 #include "GuardPageAllocator.h"
 
+#ifndef _WIN32
+#include <dlfcn.h>
+#endif
 #include <signal.h>
 
 #include <mutex>
@@ -199,9 +202,20 @@ void sigsegvSignalHandler(int signum, siginfo_t* info, void*) {
   raise(signum);
 }
 
+bool isInJVM() {
+  auto getCreated = dlsym(RTLD_DEFAULT, "JNI_GetCreatedJavaVMs");
+  return getCreated;
+}
+
 void installSignalHandler() {
   static std::once_flag onceFlag;
   std::call_once(onceFlag, []() {
+    if (isInJVM()) {
+      // Don't install signal handler, since JVM internal signal handler doesn't
+      // work with SA_ONSTACK
+      return;
+    }
+
     struct sigaction sa;
     memset(&sa, 0, sizeof(sa));
     sigemptyset(&sa.sa_mask);