/reporting/crashrpt/SharedMem.h

http://crashrpt.googlecode.com/ · C Header · 165 lines · 112 code · 22 blank · 31 comment · 0 complexity · bfb5e458c5e5ba025799f665c284cd5b MD5 · raw file

  1. /*************************************************************************************
  2. This file is a part of CrashRpt library.
  3. Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved.
  4. Use of this source code is governed by a BSD-style license
  5. that can be found in the License.txt file in the root of the source
  6. tree. All contributing project authors may
  7. be found in the Authors.txt file in the root of the source tree.
  8. ***************************************************************************************/
  9. // File: SharedMem.h
  10. // Description: Shared memory class. Used for transferring data from crashed app to crash sender process.
  11. // Authors: zexspectrum
  12. // Date: 2010
  13. #pragma once
  14. #include "stdafx.h"
  15. #include "CritSec.h"
  16. // Generic block header.
  17. struct GENERIC_HEADER
  18. {
  19. BYTE m_uchMagic[3]; // Magic sequence.
  20. WORD m_wSize; // Total bytes occupied by this block.
  21. };
  22. // String block description.
  23. struct STRING_DESC
  24. {
  25. BYTE m_uchMagic[3]; // Magic sequence "STR".
  26. WORD m_wSize; // Total bytes occupied by this block.
  27. // This structure is followed by (m_wSize-sizeof(STRING_DESC) bytes of string data.
  28. };
  29. // File item entry.
  30. struct FILE_ITEM
  31. {
  32. BYTE m_uchMagic[3]; // Magic sequence "FIL"
  33. WORD m_wSize; // Total bytes occupied by this block.
  34. DWORD m_dwSrcFilePathOffs; // Path to the original file.
  35. DWORD m_dwDstFileNameOffs; // Name of the destination file.
  36. DWORD m_dwDescriptionOffs; // File description.
  37. BOOL m_bMakeCopy; // Should we make a copy of this file on crash?
  38. BOOL m_bAllowDelete; // Should allow user to delete the file from crash report?
  39. };
  40. // Registry key entry.
  41. struct REG_KEY
  42. {
  43. BYTE m_uchMagic[3]; // Magic sequence "REG"
  44. WORD m_wSize; // Total bytes occupied by this block.
  45. BOOL m_bAllowDelete; // Should allow user to delete the file from crash report?
  46. DWORD m_dwRegKeyNameOffs; // Registry key name.
  47. DWORD m_dwDstFileNameOffs; // Destination file name.
  48. };
  49. // User-defined property.
  50. struct CUSTOM_PROP
  51. {
  52. BYTE m_uchMagic[3]; // Magic sequence "CPR"
  53. WORD m_wSize; // Total bytes occupied by this block.
  54. DWORD m_dwNameOffs; // Property name.
  55. DWORD m_dwValueOffs; // Property value.
  56. };
  57. // Crash description.
  58. struct CRASH_DESCRIPTION
  59. {
  60. BYTE m_uchMagic[3]; // Magic sequence "CRD"
  61. WORD m_wSize; // Total bytes occupied by this block.
  62. DWORD m_dwTotalSize; // Total size of the whole used shared mem.
  63. DWORD m_dwCrashRptVer; // Version of CrashRpt.
  64. UINT m_uFileItems; // Count of file item records.
  65. UINT m_uRegKeyEntries; // Count of registry key entries.
  66. UINT m_uCustomProps; // Count of user-defined properties.
  67. DWORD m_dwInstallFlags; // Flags passed to crInstall() function.
  68. int m_nSmtpPort; // Smtp port.
  69. int m_nSmtpProxyPort; // Smtp proxy port.
  70. UINT m_uPriorities[3]; // Delivery priorities.
  71. MINIDUMP_TYPE m_MinidumpType; // Minidump type.
  72. //BOOL m_bAppRestart; // Packed into flags
  73. BOOL m_bAddScreenshot; // Add screenshot?
  74. DWORD m_dwScreenshotFlags; // Screenshot flags.
  75. int m_nJpegQuality; // Jpeg image quality.
  76. DWORD m_dwUrlOffs; // Offset of recipient URL.
  77. DWORD m_dwAppNameOffs; // Offset of application name.
  78. DWORD m_dwAppVersionOffs; // Offset of app version.
  79. DWORD m_dwLangFileNameOffs; // Offset of language INI file name.
  80. DWORD m_dwRestartCmdLineOffs; // Offset of app restart command line.
  81. int m_nRestartTimeout; // Restart timeout
  82. DWORD m_dwEmailToOffs; // Offset to E-mail recipient.
  83. DWORD m_dwCrashGUIDOffs; // Offset to crash GUID.
  84. DWORD m_dwUnsentCrashReportsFolderOffs; // Offset of folder name where error reports are stored.
  85. DWORD m_dwPrivacyPolicyURLOffs; // Offset of privacy policy URL.
  86. DWORD m_dwEmailSubjectOffs; // Offset of E-mail subject.
  87. DWORD m_dwEmailTextOffs; // Offset of E-mail text.
  88. DWORD m_dwSmtpProxyServerOffs; // Offset of SMTP proxy server name.
  89. DWORD m_dwPathToDebugHelpDllOffs; // Offset of dbghelp path.
  90. DWORD m_dwCustomSenderIconOffs; // Offset of custom Error Report dialog icon resource name.
  91. DWORD m_dwImageNameOffs; // Offset to image name.
  92. DWORD m_dwProcessId; // Process ID.
  93. DWORD m_dwThreadId; // Thread ID.
  94. int m_nExceptionType; // Exception type.
  95. DWORD m_dwExceptionCode; // SEH exception code.
  96. DWORD m_dwInvParamExprOffs; // Invalid parameter expression.
  97. DWORD m_dwInvParamFunctionOffs; // Invalid parameter function.
  98. DWORD m_dwInvParamFileOffs; // Invalid parameter file.
  99. UINT m_uInvParamLine; // Invalid parameter line.
  100. UINT m_uFPESubcode; // FPE subcode.
  101. PEXCEPTION_POINTERS m_pExceptionPtrs; // Exception pointers.
  102. BOOL m_bSendRecentReports; // If TRUE, CrashSender.exe needs to send queued error reports.
  103. // If FALSE, CrashSender.exe needs to send single report.
  104. DWORD m_dwSmtpLoginOffs; // Offset of SMTP login name.
  105. DWORD m_dwSmtpPasswordOffs; // Offset of SMTP login name.
  106. BOOL m_bAddVideo; // Wether to add video recording.
  107. DWORD m_dwVideoFlags; // Flags for video recording.
  108. int m_nVideoDuration; // Video duration.
  109. int m_nVideoFrameInterval; // Video frame interval.
  110. SIZE m_DesiredFrameSize; // Video frame size.
  111. HWND m_hWndVideoParent; // Parent window for video recording dialog.
  112. BOOL m_bClientAppCrashed; // If TRUE, the client app has crashed; otherwise the client has exited without crash.
  113. };
  114. #define SHARED_MEM_MAX_SIZE 10*1024*1024 /* 10 MB */
  115. // Used to share memory between CrashRpt.dll and CrashSender.exe
  116. class CSharedMem
  117. {
  118. public:
  119. // Construction/destruction
  120. CSharedMem();
  121. ~CSharedMem();
  122. // Initializes shared memory
  123. BOOL Init(LPCTSTR szName, BOOL bOpenExisting, ULONG64 uSize);
  124. // Whether initialized or not
  125. BOOL IsInitialized();
  126. // Destroys the object
  127. BOOL Destroy();
  128. // Returns file mapping name
  129. CString GetName();
  130. // Returns file mapping size
  131. ULONG64 GetSize();
  132. // Creates a view and returns its start pointer
  133. LPBYTE CreateView(DWORD dwOffset, DWORD dwLength);
  134. // Destroys a view
  135. void DestroyView(LPBYTE pViewPtr);
  136. private:
  137. CString m_sName; // Name of the file mapping.
  138. HANDLE m_hFileMapping; // Memory mapped object
  139. DWORD m_dwAllocGranularity; // System allocation granularity
  140. ULONG64 m_uSize; // Size of the file mapping.
  141. std::map<LPBYTE, LPBYTE> m_aViewStartPtrs; // Base of the view of the file mapping.
  142. };