|
- /*
- ==============================================================================
-
- This file is part of the JUCE library - "Jules' Utility Class Extensions"
- Copyright 2004-11 by Raw Material Software Ltd.
-
- ------------------------------------------------------------------------------
-
- JUCE can be redistributed and/or modified under the terms of the GNU General
- Public License (Version 2), as published by the Free Software Foundation.
- A copy of the license is included in the JUCE distribution, or can be found
- online at www.gnu.org/licenses.
-
- JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- ------------------------------------------------------------------------------
-
- To release a closed-source product which uses JUCE, commercial licenses are
- available: visit www.rawmaterialsoftware.com/juce for more information.
-
- ==============================================================================
- */
-
- const SystemStats::CPUFlags& SystemStats::getCPUFlags()
- {
- static CPUFlags cpuFlags;
- return cpuFlags;
- }
-
- String SystemStats::getJUCEVersion()
- {
- // Some basic tests, to keep an eye on things and make sure these types work ok
- // on all platforms. Let me know if any of these assertions fail on your system!
- static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
- static_jassert (sizeof (int8) == 1);
- static_jassert (sizeof (uint8) == 1);
- static_jassert (sizeof (int16) == 2);
- static_jassert (sizeof (uint16) == 2);
- static_jassert (sizeof (int32) == 4);
- static_jassert (sizeof (uint32) == 4);
- static_jassert (sizeof (int64) == 8);
- static_jassert (sizeof (uint64) == 8);
-
- return "JUCE v" JUCE_STRINGIFY(JUCE_MAJOR_VERSION)
- "." JUCE_STRINGIFY(JUCE_MINOR_VERSION)
- "." JUCE_STRINGIFY(JUCE_BUILDNUMBER);
- }
-
- #if JUCE_ANDROID && ! defined (JUCE_DISABLE_JUCE_VERSION_PRINTING)
- #define JUCE_DISABLE_JUCE_VERSION_PRINTING 1
- #endif
-
- #if JUCE_DEBUG && ! JUCE_DISABLE_JUCE_VERSION_PRINTING
- struct JuceVersionPrinter
- {
- JuceVersionPrinter()
- {
- DBG (SystemStats::getJUCEVersion());
- }
- };
-
- static JuceVersionPrinter juceVersionPrinter;
- #endif
-
-
- //==============================================================================
- String SystemStats::getStackBacktrace()
- {
- String result;
-
- #if JUCE_ANDROID
- jassertfalse; // sorry, not implemented yet!
-
- #elif JUCE_WINDOWS
- HANDLE process = GetCurrentProcess();
- SymInitialize (process, nullptr, TRUE);
-
- void* stack[128];
- int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
-
- HeapBlock<SYMBOL_INFO> symbol;
- symbol.calloc (sizeof(SYMBOL_INFO) + 256, 1);
- symbol->MaxNameLen = 255;
- symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
-
- for (int i = 0; i < frames; ++i)
- {
- DWORD64 displacement = 0;
-
- if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
- {
- result << i << ": ";
-
- IMAGEHLP_MODULE64 moduleInfo;
- zerostruct (moduleInfo);
- moduleInfo.SizeOfStruct = sizeof (moduleInfo);
-
- if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
- result << moduleInfo.ModuleName << ": ";
-
- result << symbol->Name << " + 0x" << String::toHexString ((int64) displacement) << newLine;
- }
- }
-
- #else
- void* stack[128];
- int frames = backtrace (stack, numElementsInArray (stack));
- char** frameStrings = backtrace_symbols (stack, frames);
-
- for (int i = 0; i < frames; ++i)
- result << frameStrings[i] << newLine;
-
- ::free (frameStrings);
- #endif
-
- return result;
- }
-
- //==============================================================================
- static SystemStats::CrashHandlerFunction globalCrashHandler = nullptr;
-
- #if JUCE_WINDOWS
- static LONG WINAPI handleCrash (LPEXCEPTION_POINTERS)
- {
- globalCrashHandler();
- return EXCEPTION_EXECUTE_HANDLER;
- }
- #else
- static void handleCrash (int)
- {
- globalCrashHandler();
- kill (getpid(), SIGKILL);
- }
- #endif
-
- void SystemStats::setApplicationCrashHandler (CrashHandlerFunction handler)
- {
- jassert (handler != nullptr); // This must be a valid function.
- globalCrashHandler = handler;
-
- #if JUCE_WINDOWS
- SetUnhandledExceptionFilter (handleCrash);
- #else
- const int signals[] = { SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT, SIGSYS };
-
- for (int i = 0; i < numElementsInArray (signals); ++i)
- {
- ::signal (signals[i], handleCrash);
- ::siginterrupt (signals[i], 1);
- }
- #endif
- }
|