The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. const SystemStats::CPUFlags& SystemStats::getCPUFlags()
  19. {
  20. static CPUFlags cpuFlags;
  21. return cpuFlags;
  22. }
  23. String SystemStats::getJUCEVersion()
  24. {
  25. // Some basic tests, to keep an eye on things and make sure these types work ok
  26. // on all platforms. Let me know if any of these assertions fail on your system!
  27. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  28. static_jassert (sizeof (int8) == 1);
  29. static_jassert (sizeof (uint8) == 1);
  30. static_jassert (sizeof (int16) == 2);
  31. static_jassert (sizeof (uint16) == 2);
  32. static_jassert (sizeof (int32) == 4);
  33. static_jassert (sizeof (uint32) == 4);
  34. static_jassert (sizeof (int64) == 8);
  35. static_jassert (sizeof (uint64) == 8);
  36. return "JUCE v" JUCE_STRINGIFY(JUCE_MAJOR_VERSION)
  37. "." JUCE_STRINGIFY(JUCE_MINOR_VERSION)
  38. "." JUCE_STRINGIFY(JUCE_BUILDNUMBER);
  39. }
  40. #if JUCE_ANDROID && ! defined (JUCE_DISABLE_JUCE_VERSION_PRINTING)
  41. #define JUCE_DISABLE_JUCE_VERSION_PRINTING 1
  42. #endif
  43. #if JUCE_DEBUG && ! JUCE_DISABLE_JUCE_VERSION_PRINTING
  44. struct JuceVersionPrinter
  45. {
  46. JuceVersionPrinter()
  47. {
  48. DBG (SystemStats::getJUCEVersion());
  49. }
  50. };
  51. static JuceVersionPrinter juceVersionPrinter;
  52. #endif
  53. //==============================================================================
  54. String SystemStats::getStackBacktrace()
  55. {
  56. String result;
  57. #if JUCE_ANDROID
  58. jassertfalse; // sorry, not implemented yet!
  59. #elif JUCE_WINDOWS
  60. HANDLE process = GetCurrentProcess();
  61. SymInitialize (process, nullptr, TRUE);
  62. void* stack[128];
  63. int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
  64. HeapBlock<SYMBOL_INFO> symbol;
  65. symbol.calloc (sizeof(SYMBOL_INFO) + 256, 1);
  66. symbol->MaxNameLen = 255;
  67. symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
  68. for (int i = 0; i < frames; ++i)
  69. {
  70. DWORD64 displacement = 0;
  71. if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
  72. {
  73. result << i << ": ";
  74. IMAGEHLP_MODULE64 moduleInfo;
  75. zerostruct (moduleInfo);
  76. moduleInfo.SizeOfStruct = sizeof (moduleInfo);
  77. if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
  78. result << moduleInfo.ModuleName << ": ";
  79. result << symbol->Name << " + 0x" << String::toHexString ((int64) displacement) << newLine;
  80. }
  81. }
  82. #else
  83. void* stack[128];
  84. int frames = backtrace (stack, numElementsInArray (stack));
  85. char** frameStrings = backtrace_symbols (stack, frames);
  86. for (int i = 0; i < frames; ++i)
  87. result << frameStrings[i] << newLine;
  88. ::free (frameStrings);
  89. #endif
  90. return result;
  91. }
  92. //==============================================================================
  93. static SystemStats::CrashHandlerFunction globalCrashHandler = nullptr;
  94. #if JUCE_WINDOWS
  95. static LONG WINAPI handleCrash (LPEXCEPTION_POINTERS)
  96. {
  97. globalCrashHandler();
  98. return EXCEPTION_EXECUTE_HANDLER;
  99. }
  100. #else
  101. static void handleCrash (int)
  102. {
  103. globalCrashHandler();
  104. kill (getpid(), SIGKILL);
  105. }
  106. #endif
  107. void SystemStats::setApplicationCrashHandler (CrashHandlerFunction handler)
  108. {
  109. jassert (handler != nullptr); // This must be a valid function.
  110. globalCrashHandler = handler;
  111. #if JUCE_WINDOWS
  112. SetUnhandledExceptionFilter (handleCrash);
  113. #else
  114. const int signals[] = { SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT, SIGSYS };
  115. for (int i = 0; i < numElementsInArray (signals); ++i)
  116. {
  117. ::signal (signals[i], handleCrash);
  118. ::siginterrupt (signals[i], 1);
  119. }
  120. #endif
  121. }