diff src/os/posix/vm/os_posix.hpp @ 11151:5e3b6f79d280

8020701: Avoid crashes in WatcherThread Reviewed-by: acorn, dcubed, dsimms
author rbackman
date Wed, 17 Jul 2013 13:48:15 +0200
parents b9a9ed0f8eeb
children de6a9e811145 f42f2e2a1518
line wrap: on
line diff
--- a/src/os/posix/vm/os_posix.hpp	Thu Jul 18 06:47:15 2013 -0400
+++ b/src/os/posix/vm/os_posix.hpp	Wed Jul 17 13:48:15 2013 +0200
@@ -37,5 +37,24 @@
 
 };
 
+/*
+ * Crash protection for the watcher thread. Wrap the callback
+ * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp
+ * back.
+ * To be able to use this - don't take locks, don't rely on destructors,
+ * don't make OS library calls, don't allocate memory, don't print,
+ * don't call code that could leave the heap / memory in an inconsistent state,
+ * or anything else where we are not in control if we suddenly jump out.
+ */
+class WatcherThreadCrashProtection : public StackObj {
+public:
+  WatcherThreadCrashProtection();
+  bool call(os::CrashProtectionCallback& cb);
+
+  static void check_crash_protection(int signal, Thread* thread);
+private:
+  void restore();
+  sigjmp_buf _jmpbuf;
+};
 
 #endif