From 6d0beb9d87575ba27179c5f62c84e3474cd332c8 Mon Sep 17 00:00:00 2001 From: Helge Norberg Date: Tue, 31 Jan 2017 16:34:21 +0100 Subject: [PATCH] [win32] Give the server a tiny hope of recovering from a stack overflow bug. Still unlikely that the server will not crash. --- common/log.cpp | 10 ++++++++++ common/log.h | 5 +++-- common/os/windows/win32_exception.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/log.cpp b/common/log.cpp index b6488739d..55ee3406c 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -163,6 +163,16 @@ void init() boost::log::core::get()->add_sink(stream_sink); } +std::string current_exception_diagnostic_information() +{ + auto e = boost::current_exception_cast(); + + if (e) + return std::string("[char *] = ") + *e + "\n"; + else + return boost::current_exception_diagnostic_information(); +} + } void add_file_sink(const std::wstring& file, const boost::log::filter& filter) diff --git a/common/log.h b/common/log.h index 860c1a646..9df9470f2 100644 --- a/common/log.h +++ b/common/log.h @@ -43,6 +43,7 @@ namespace caspar { namespace log { namespace internal{ void init(); std::wstring get_call_stack(); +std::string current_exception_diagnostic_information(); } const char* remove_source_prefix(const char* file); @@ -102,12 +103,12 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger) catch(...){} #define CASPAR_LOG_CURRENT_EXCEPTION() try{\ - CASPAR_LOG(error) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ + CASPAR_LOG(error) << caspar::u16(::caspar::log::internal::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ }\ catch(...){} #define CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(lvl) try{\ - CASPAR_LOG(lvl) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ + CASPAR_LOG(lvl) << caspar::u16(::caspar::log::internal::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ }\ catch(...){} diff --git a/common/os/windows/win32_exception.cpp b/common/os/windows/win32_exception.cpp index 75006bc25..0a65c5ceb 100644 --- a/common/os/windows/win32_exception.cpp +++ b/common/os/windows/win32_exception.cpp @@ -31,7 +31,7 @@ inline void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) { RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); } - __except (EXCEPTION_CONTINUE_EXECUTION){} + __except (EXCEPTION_CONTINUE_EXECUTION){} } } // namespace detail @@ -41,7 +41,7 @@ bool& installed_for_thread() static boost::thread_specific_ptr installed; auto for_thread = installed.get(); - + if (!for_thread) { for_thread = new bool(false); @@ -99,6 +99,8 @@ void win32_exception::Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo) { case EXCEPTION_ACCESS_VIOLATION: CASPAR_THROW_EXCEPTION(win32_access_violation() << generate_message(*(pInfo->ExceptionRecord))); + case EXCEPTION_STACK_OVERFLOW: + throw "Stack overflow. Not generating stack trace to protect from further overflowing the stack"; default: CASPAR_THROW_EXCEPTION(win32_exception() << generate_message(*(pInfo->ExceptionRecord))); } -- 2.39.2