CrashHandler_win.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // LY Base Crashpad Windows implementation
  9. #include <CrashHandler.h>
  10. #include <AzCore/PlatformIncl.h>
  11. namespace CrashHandler
  12. {
  13. const char* crashHandlerPath = "ToolsCrashUploader.exe";
  14. const char* CrashHandlerBase::GetCrashHandlerExecutableName() const
  15. {
  16. return crashHandlerPath;
  17. }
  18. void CrashHandlerBase::GetOSAnnotations(CrashHandlerAnnotations& annotations) const
  19. {
  20. annotations["os"] = "windows";
  21. // Disable warning about GetVersion deprecation
  22. // Windows now encourages users to check for the specific capability they need rather
  23. // than relying on a version ID due to badly written/lazy code (If buildID >= NUM then I certainly can do x...)
  24. // In this case we really just want a build ID to report
  25. AZ_PUSH_DISABLE_WARNING(4996, "-Wdeprecated-declarations")
  26. DWORD winVersion = GetVersion();
  27. AZ_POP_DISABLE_WARNING
  28. // VersionMajor lives in the low byte of the low word
  29. int versionMajor = winVersion & 0xFF;
  30. // VersionMinor lives in the high byte of the low word
  31. int versionMinor = (winVersion & (0xFF << 8)) >> 8;
  32. int osBuild = 0;
  33. if (winVersion < 0x80000000)
  34. {
  35. // BuildID lives in the high word
  36. osBuild = (winVersion & (0xFFFF << 16)) >> 16;
  37. }
  38. std::string annotationBuf;
  39. annotationBuf = std::to_string(versionMajor) + "." + std::to_string(versionMinor);
  40. annotations["os.version"] = annotationBuf;
  41. annotationBuf = std::to_string(osBuild);
  42. annotations["os.build"] = annotationBuf;
  43. const size_t kbSize = 1024;
  44. MEMORYSTATUSEX statex;
  45. statex.dwLength = sizeof(statex);
  46. GlobalMemoryStatusEx(&statex);
  47. annotationBuf = std::to_string(statex.dwMemoryLoad);
  48. annotations["vm.used"] = annotationBuf;
  49. annotationBuf = std::to_string(statex.ullTotalPhys / kbSize);
  50. annotations["vm.total"] = annotationBuf;
  51. annotationBuf = std::to_string(statex.ullAvailPhys / kbSize);
  52. annotations["vm.free"] = annotationBuf;
  53. annotationBuf = std::to_string(statex.ullTotalPageFile / kbSize);
  54. annotations["vm.swap.size"] = annotationBuf;
  55. RECT desktopRect;
  56. const HWND desktopWind = GetDesktopWindow();
  57. GetWindowRect(desktopWind, &desktopRect);
  58. annotationBuf = std::to_string(desktopRect.right) + "x" + std::to_string(desktopRect.bottom);
  59. annotations["resolution"] = annotationBuf;
  60. ULARGE_INTEGER freeBytes;
  61. auto queryResult = GetDiskFreeSpaceExA(".", &freeBytes, nullptr, nullptr);
  62. if (queryResult)
  63. {
  64. annotationBuf = std::to_string(freeBytes.QuadPart);
  65. annotations["disk_free"] = annotationBuf;
  66. }
  67. else
  68. {
  69. annotations["disk_free"] = "error";
  70. }
  71. }
  72. }