diff --git a/src/Global.h b/src/Global.h index 434268b9..65c4e710 100644 --- a/src/Global.h +++ b/src/Global.h @@ -113,7 +113,6 @@ bool lamexp_detect_wine(void); bool lamexp_enable_close_button(const QWidget *win, const bool bEnable = true); bool lamexp_exec_shell(const QWidget *win, const QString &url, const bool explore = false); bool lamexp_exec_shell(const QWidget *win, const QString &url, const QString ¶meters, const QString &directory, const bool explore = false); -void lamexp_fatal_exit(const char* const errorMessage); void lamexp_finalization(void); unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL); void lamexp_free_window_icon(lamexp_icon_t *icon); diff --git a/src/Global_Win32.cpp b/src/Global_Win32.cpp index d5b0551e..591f47f3 100644 --- a/src/Global_Win32.cpp +++ b/src/Global_Win32.cpp @@ -123,78 +123,6 @@ while(0) } \ while(0) -/////////////////////////////////////////////////////////////////////////////// -// CRITICAL SECTION -/////////////////////////////////////////////////////////////////////////////// - -/* - * wrapper for native Win32 critical sections - */ -class CriticalSection -{ -public: - inline CriticalSection(void) - { - InitializeCriticalSection(&m_win32criticalSection); - } - - inline ~CriticalSection(void) - { - DeleteCriticalSection(&m_win32criticalSection); - } - - inline void enter(void) - { - EnterCriticalSection(&m_win32criticalSection); - } - - inline bool tryEnter(void) - { - return TryEnterCriticalSection(&m_win32criticalSection); - } - - inline void leave(void) - { - LeaveCriticalSection(&m_win32criticalSection); - } - -protected: - CRITICAL_SECTION m_win32criticalSection; -}; - -/* - * RAII-style critical section locker - */ -class CSLocker -{ -public: - inline CSLocker(CriticalSection &criticalSection) - : - m_locked(false), - m_criticalSection(criticalSection) - { - m_criticalSection.enter(); - m_locked = true; - } - - inline ~CSLocker(void) - { - forceUnlock(); - } - - inline void forceUnlock(void) - { - if(m_locked) - { - m_criticalSection.leave(); - m_locked = false; - } - } -protected: - volatile bool m_locked; - CriticalSection &m_criticalSection; -}; - /////////////////////////////////////////////////////////////////////////////// // GLOBAL VARS /////////////////////////////////////////////////////////////////////////////// @@ -204,10 +132,6 @@ static bool g_lamexp_console_attached = false; //Fatal exit flags static volatile bool g_lamexp_fatal_flag = true; -static CriticalSection g_lamexp_fatal_lock; - -//Global locks -static CriticalSection g_lamexp_message_lock; //CLI Arguments static struct @@ -452,7 +376,7 @@ void lamexp_message_handler(QtMsgType type, const char *msg) return; } - CSLocker lock(g_lamexp_message_lock); + //CSLocker lock(g_lamexp_message_lock); FIXME !!!! FIXME !!!! FIXME !!!! FIXME !!!! if(g_lamexp_log_file) { @@ -470,8 +394,8 @@ void lamexp_message_handler(QtMsgType type, const char *msg) if((type == QtCriticalMsg) || (type == QtFatalMsg)) { - lock.forceUnlock(); - lamexp_fatal_exit(msg); + //lock.forceUnlock(); + MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg))); } } @@ -480,7 +404,7 @@ void lamexp_message_handler(QtMsgType type, const char *msg) */ static void lamexp_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, const wchar_t* fil, unsigned int, uintptr_t) { - lamexp_fatal_exit("Invalid parameter handler invoked, application will exit!"); + MUtils::OS::fatal_exit(L"Invalid parameter handler invoked, application will exit!"); } /* @@ -489,7 +413,7 @@ static void lamexp_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, static void lamexp_signal_handler(int signal_num) { signal(signal_num, lamexp_signal_handler); - lamexp_fatal_exit("Signal handler invoked, application will exit!"); + MUtils::OS::fatal_exit(L"Signal handler invoked, application will exit!"); } /* @@ -497,7 +421,7 @@ static void lamexp_signal_handler(int signal_num) */ static LONG WINAPI lamexp_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) { - lamexp_fatal_exit("Unhandeled exception handler invoked, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled exception handler invoked, application will exit!"); return LONG_MAX; } @@ -635,7 +559,7 @@ static unsigned int __stdcall lamexp_debug_thread_proc(LPVOID lpParameter) { if(lamexp_check_for_debugger()) { - lamexp_fatal_exit("Not a debug build. Please unload debugger and try again!"); + MUtils::OS::fatal_exit(L"Not a debug build. Please unload debugger and try again!"); return 666; } lamexp_sleep(100); @@ -649,7 +573,7 @@ static HANDLE lamexp_debug_thread_init() { if(lamexp_check_for_debugger()) { - lamexp_fatal_exit("Not a debug build. Please unload debugger and try again!"); + MUtils::OS::fatal_exit(L"Not a debug build. Please unload debugger and try again!"); } const uintptr_t h = _beginthreadex(NULL, 0, lamexp_debug_thread_proc, NULL, 0, NULL); return (HANDLE)(h^0xdeadbeef); @@ -662,7 +586,7 @@ static bool lamexp_event_filter(void *message, long *result) { if((!(MUTILS_DEBUG)) && lamexp_check_for_debugger()) { - lamexp_fatal_exit("Not a debug build. Please unload debugger and try again!"); + MUtils::OS::fatal_exit(L"Not a debug build. Please unload debugger and try again!"); } switch(reinterpret_cast(message)->message) @@ -1849,39 +1773,6 @@ static DWORD WINAPI lamexp_fatal_exit_helper(LPVOID lpParameter) return 0; } -/* - * Fatal application exit - */ -void lamexp_fatal_exit(const char* const errorMessage) -{ - g_lamexp_fatal_lock.enter(); - - if(!g_lamexp_fatal_flag) - { - return; /*prevent recursive invocation*/ - } - - g_lamexp_fatal_flag = false; - - if(g_main_thread_id != GetCurrentThreadId()) - { - if(HANDLE hThreadMain = OpenThread(THREAD_SUSPEND_RESUME, FALSE, g_main_thread_id)) - { - SuspendThread(hThreadMain); /*stop main thread*/ - } - } - - if(HANDLE hThread = CreateThread(NULL, 0, lamexp_fatal_exit_helper, (LPVOID) errorMessage, 0, NULL)) - { - WaitForSingleObject(hThread, INFINITE); - } - - for(;;) - { - TerminateProcess(GetCurrentProcess(), 666); - } -} - /* * Initialize debug thread */ @@ -1928,7 +1819,7 @@ extern "C" void _lamexp_global_init_win32(void) { if((!MUTILS_DEBUG) && lamexp_check_for_debugger()) { - lamexp_fatal_exit("Not a debug build. Please unload debugger and try again!"); + MUtils::OS::fatal_exit(L"Not a debug build. Please unload debugger and try again!"); } //Zero *before* constructors are called diff --git a/src/Global_Zero.cpp b/src/Global_Zero.cpp index d75c6e7f..92f719aa 100644 --- a/src/Global_Zero.cpp +++ b/src/Global_Zero.cpp @@ -22,6 +22,10 @@ #include "Global.h" +//MUtils +#include + +//Qt #include /////////////////////////////////////////////////////////////////////////////// @@ -40,7 +44,7 @@ static size_t lamexp_entry_check(void) volatile size_t retVal = 0xA199B5AF; if(g_lamexp_entry_check_flag != 0x8761F64D) { - lamexp_fatal_exit("Application initialization has failed, take care!"); + MUtils::OS::fatal_exit(L"Application initialization has failed, take care!"); } return retVal; } @@ -73,7 +77,7 @@ extern "C" int lamexp_entry_point(void) { if(g_lamexp_entry_check_flag != 0x789E09B2) { - lamexp_fatal_exit("Application initialization has failed, take care!"); + MUtils::OS::fatal_exit(L"Application initialization has failed, take care!"); } //Call global initialization functions diff --git a/src/Main.cpp b/src/Main.cpp index b3603e38..50da3f6c 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -242,12 +242,12 @@ static int _main(int argc, char* argv[]) catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } return iResult; } @@ -271,7 +271,7 @@ int main(int argc, char* argv[]) __except(1) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnhandeled structured exception error!\n"); - lamexp_fatal_exit("Unhandeled structured exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled structured exception error, application will exit!"); } } } diff --git a/src/Thread_CPUObserver.cpp b/src/Thread_CPUObserver.cpp index 724817a0..d29e46ce 100644 --- a/src/Thread_CPUObserver.cpp +++ b/src/Thread_CPUObserver.cpp @@ -20,9 +20,14 @@ // http://www.gnu.org/licenses/gpl-2.0.txt /////////////////////////////////////////////////////////////////////////////// +//Internal #include "Thread_CPUObserver.h" #include "Global.h" +//MUtils +#include + +//Qt #include //Windows includes @@ -57,12 +62,12 @@ void CPUObserverThread::run(void) catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } while(m_semaphore.available()) m_semaphore.tryAcquire(); diff --git a/src/Thread_DiskObserver.cpp b/src/Thread_DiskObserver.cpp index 220bf7c3..f6b5a217 100644 --- a/src/Thread_DiskObserver.cpp +++ b/src/Thread_DiskObserver.cpp @@ -28,6 +28,7 @@ //MUtils #include +#include //Qt #include @@ -63,12 +64,12 @@ void DiskObserverThread::run(void) catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } while(m_semaphore.available()) m_semaphore.tryAcquire(); diff --git a/src/Thread_FileAnalyzer_Task.cpp b/src/Thread_FileAnalyzer_Task.cpp index fa1f34f0..7a64b773 100644 --- a/src/Thread_FileAnalyzer_Task.cpp +++ b/src/Thread_FileAnalyzer_Task.cpp @@ -29,6 +29,7 @@ //MUtils #include +#include //Qt #include @@ -89,12 +90,12 @@ void AnalyzeTask::run() catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } } diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index 696e4897..69c562fd 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -29,6 +29,7 @@ //MUtils #include +#include //Qt #include @@ -235,12 +236,12 @@ void InitializationThread::run(void) catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } } diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index 98d5f920..03ba68a2 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -37,6 +37,7 @@ //MUtils #include +#include #include //Qt @@ -187,12 +188,12 @@ void ProcessThread::run() catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } } diff --git a/src/Thread_RAMObserver.cpp b/src/Thread_RAMObserver.cpp index 4b0385aa..a0b34fa4 100644 --- a/src/Thread_RAMObserver.cpp +++ b/src/Thread_RAMObserver.cpp @@ -23,6 +23,10 @@ #include "Thread_RAMObserver.h" #include "Global.h" +//MUtils +#include + +//Qt #include //Windows includes @@ -57,12 +61,12 @@ void RAMObserverThread::run(void) catch(const std::exception &error) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what()); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } catch(...) { PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n"); - lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!"); + MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!"); } while(m_semaphore.available()) m_semaphore.tryAcquire();