1.1 --- a/src/os/posix/vm/os_posix.hpp Thu Aug 01 03:44:03 2019 +0100 1.2 +++ b/src/os/posix/vm/os_posix.hpp Mon Aug 12 18:30:40 2019 +0300 1.3 @@ -62,6 +62,33 @@ 1.4 }; 1.5 1.6 /* 1.7 + * Crash protection utility used by JFR. Wrap the callback 1.8 + * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp 1.9 + * back. 1.10 + * To be able to use this - don't take locks, don't rely on destructors, 1.11 + * don't make OS library calls, don't allocate memory, don't print, 1.12 + * don't call code that could leave the heap / memory in an inconsistent state, 1.13 + * or anything else where we are not in control if we suddenly jump out. 1.14 + */ 1.15 +class ThreadCrashProtection : public StackObj { 1.16 +public: 1.17 + static bool is_crash_protected(Thread* thr) { 1.18 + return _crash_protection != NULL && _protected_thread == thr; 1.19 + } 1.20 + 1.21 + ThreadCrashProtection(); 1.22 + bool call(os::CrashProtectionCallback& cb); 1.23 + 1.24 + static void check_crash_protection(int signal, Thread* thread); 1.25 +private: 1.26 + static Thread* _protected_thread; 1.27 + static ThreadCrashProtection* _crash_protection; 1.28 + static volatile intptr_t _crash_mux; 1.29 + void restore(); 1.30 + sigjmp_buf _jmpbuf; 1.31 +}; 1.32 + 1.33 +/* 1.34 * Crash protection for the watcher thread. Wrap the callback 1.35 * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp 1.36 * back.