add_o3de_handler_extensions.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. diff --git a/ports/crashpad/o3de_handler_extensions.patch b/ports/crashpad/o3de_handler_extensions.patch
  2. new file mode 100644
  3. index 0000000..6f566f8
  4. --- /dev/null
  5. +++ b/ports/crashpad/o3de_handler_extensions.patch
  6. @@ -0,0 +1,180 @@
  7. +diff --git a/client/crashpad_client.h b/client/crashpad_client.h
  8. +index 3c966686..75d01a84 100644
  9. +--- a/client/crashpad_client.h
  10. ++++ b/client/crashpad_client.h
  11. +@@ -12,6 +12,10 @@
  12. + // See the License for the specific language governing permissions and
  13. + // limitations under the License.
  14. +
  15. ++// Modifications Copyright (c) Contributors to the Open 3D Engine Project.
  16. ++// SPDX-License-Identifier: Apache-2.0 OR MIT
  17. ++// (See O3DE tagged section(s) below)
  18. ++
  19. + #ifndef CRASHPAD_CLIENT_CRASHPAD_CLIENT_H_
  20. + #define CRASHPAD_CLIENT_CRASHPAD_CLIENT_H_
  21. +
  22. +@@ -771,6 +775,29 @@ class CrashpadClient {
  23. + static bool DumpAndCrashTargetProcess(HANDLE process,
  24. + HANDLE blame_thread,
  25. + DWORD exception_code);
  26. ++
  27. ++ // O3DE - Handle giving the user the option to react to a crash
  28. ++ //! \brief The type for custom handlers installed by clients.
  29. ++ using FirstChanceHandler = bool (*)(EXCEPTION_POINTERS*);
  30. ++
  31. ++ //! \brief Installs a custom crash signal handler which runs before the
  32. ++ //! currently installed Crashpad handler.
  33. ++ //!
  34. ++ //! Handling signals appropriately can be tricky and use of this method
  35. ++ //! should be avoided, if possible.
  36. ++ //!
  37. ++ //! A handler must have already been installed before calling this method.
  38. ++ //!
  39. ++ //! The custom handler runs in a signal handler context and must be safe for
  40. ++ //! that purpose.
  41. ++ //!
  42. ++ //! If the custom handler returns `true`, the signal is considered handled and
  43. ++ //! the signal handler returns. Otherwise, the currently installed Crashpad
  44. ++ //! signal handler is run.
  45. ++ //!
  46. ++ //! \param[in] handler The custom crash signal handler to install.
  47. ++ static void SetFirstChanceExceptionHandler(FirstChanceHandler handler);
  48. ++
  49. + #endif
  50. +
  51. + #if BUILDFLAG(IS_APPLE) || DOXYGEN
  52. +diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc
  53. +index c10df2b0..71435039 100644
  54. +--- a/client/crashpad_client_win.cc
  55. ++++ b/client/crashpad_client_win.cc
  56. +@@ -12,6 +12,10 @@
  57. + // See the License for the specific language governing permissions and
  58. + // limitations under the License.
  59. +
  60. ++// Modifications Copyright (c) Contributors to the Open 3D Engine Project.
  61. ++// SPDX-License-Identifier: Apache-2.0 OR MIT
  62. ++// (See O3DE tagged section(s) below)
  63. ++
  64. + #include "client/crashpad_client.h"
  65. +
  66. + #include <windows.h>
  67. +@@ -84,6 +88,9 @@ WerRegistration g_wer_registration = {WerRegistration::kWerRegistrationVersion,
  68. + {0},
  69. + {0}};
  70. +
  71. ++// O3DE - Handle storing the crash reaction handler
  72. ++CrashpadClient::FirstChanceHandler g_first_chance_handler = nullptr;
  73. ++
  74. + enum class StartupState : int {
  75. + kNotReady = 0, // This must be value 0 because it is the initial value of a
  76. + // global AtomicWord.
  77. +@@ -134,6 +141,13 @@ LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exception_pointers) {
  78. + return status;
  79. + #endif
  80. +
  81. ++ // O3DE - User react to a crash
  82. ++ if (g_first_chance_handler && g_first_chance_handler(exception_pointers))
  83. ++ {
  84. ++ SafeTerminateProcess(GetCurrentProcess(), kTerminationCodeCrashNoDump);
  85. ++ return EXCEPTION_CONTINUE_SEARCH;
  86. ++ }
  87. ++
  88. + if (BlockUntilHandlerStartedOrFailed() == StartupState::kFailed) {
  89. + // If we know for certain that the handler has failed to start, then abort
  90. + // here, rather than trying to signal to a handler that will never arrive,
  91. +@@ -1126,4 +1140,9 @@ bool CrashpadClient::DumpAndCrashTargetProcess(HANDLE process,
  92. + return result;
  93. + }
  94. +
  95. ++void CrashpadClient::SetFirstChanceExceptionHandler(CrashpadClient::FirstChanceHandler handler)
  96. ++{
  97. ++ g_first_chance_handler = handler;
  98. ++}
  99. ++
  100. + } // namespace crashpad
  101. +diff --git a/handler/crash_report_upload_thread.cc b/handler/crash_report_upload_thread.cc
  102. +index 5bd2889e..e3cc0341 100644
  103. +--- a/handler/crash_report_upload_thread.cc
  104. ++++ b/handler/crash_report_upload_thread.cc
  105. +@@ -12,6 +12,10 @@
  106. + // See the License for the specific language governing permissions and
  107. + // limitations under the License.
  108. +
  109. ++// Modifications Copyright (c) Contributors to the Open 3D Engine Project.
  110. ++// SPDX-License-Identifier: Apache-2.0 OR MIT
  111. ++// (See O3DE tagged section(s) below)
  112. ++
  113. + #include "handler/crash_report_upload_thread.h"
  114. +
  115. + #include <errno.h>
  116. +@@ -48,6 +52,15 @@
  117. + #include "util/ios/scoped_background_task.h"
  118. + #endif // BUILDFLAG(IS_IOS)
  119. +
  120. ++// O3DE - Handle giving the user the option of whether or not to send the report.
  121. ++namespace O3de {
  122. ++ bool CheckConfirmation(const crashpad::CrashReportDatabase::Report& report);
  123. ++ bool AddAttachments(crashpad::HTTPMultipartBuilder& multipartBuilder);
  124. ++ bool UpdateHttpTransport(
  125. ++ std::unique_ptr<crashpad::HTTPTransport>& httpTransport,
  126. ++ const std::string& baseURL);
  127. ++} // namespace O3de
  128. ++
  129. + namespace crashpad {
  130. +
  131. + namespace {
  132. +@@ -194,6 +207,14 @@ void CrashReportUploadThread::ProcessPendingReport(
  133. +
  134. + Settings* const settings = database_->GetSettings();
  135. +
  136. ++ // O3DE - Handle giving the user the option of whether or not to send the report.
  137. ++ if (!O3de::CheckConfirmation(report)) {
  138. ++ database_->SkipReportUpload(report.uuid,
  139. ++ Metrics::CrashSkippedReason::kUploadsDisabled);
  140. ++ database_->DeleteReport(report.uuid);
  141. ++ return;
  142. ++ }
  143. ++
  144. + bool uploads_enabled;
  145. + if (!report.upload_explicitly_requested &&
  146. + (!settings->GetUploadsEnabled(&uploads_enabled) || !uploads_enabled)) {
  147. +@@ -327,6 +348,9 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport(
  148. + reader,
  149. + "application/octet-stream");
  150. +
  151. ++ // O3DE
  152. ++ O3de::AddAttachments(http_multipart_builder);
  153. ++
  154. + std::unique_ptr<HTTPTransport> http_transport(HTTPTransport::Create());
  155. + if (!http_transport) {
  156. + return UploadResult::kPermanentFailure;
  157. +@@ -366,6 +390,9 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport(
  158. + }
  159. + http_transport->SetURL(url);
  160. +
  161. ++ // O3DE
  162. ++ O3de::UpdateHttpTransport(http_transport, url);
  163. ++
  164. + if (!http_transport->ExecuteSynchronously(response_body)) {
  165. + return UploadResult::kRetry;
  166. + }
  167. +diff --git a/tools/BUILD.gn b/tools/BUILD.gn
  168. +index 157ee929..14ca33d2 100644
  169. +--- a/tools/BUILD.gn
  170. ++++ b/tools/BUILD.gn
  171. +@@ -12,9 +12,14 @@
  172. + # See the License for the specific language governing permissions and
  173. + # limitations under the License.
  174. +
  175. ++# Modifications Copyright (c) Contributors to the Open 3D Engine Project.
  176. ++# SPDX-License-Identifier: Apache-2.0 OR MIT
  177. ++# (See O3DE tagged section(s) below)
  178. ++
  179. + import("../build/crashpad_buildconfig.gni")
  180. +
  181. +-source_set("tool_support") {
  182. ++# O3DE - Change the tool_support target type from source set to static library
  183. ++crashpad_static_library("tool_support") {
  184. + sources = [
  185. + "tool_support.cc",
  186. + "tool_support.h",
  187. diff --git a/ports/crashpad/portfile.cmake b/ports/crashpad/portfile.cmake
  188. index 6985a8b..f45bc36 100644
  189. --- a/ports/crashpad/portfile.cmake
  190. +++ b/ports/crashpad/portfile.cmake
  191. @@ -7,6 +7,7 @@ vcpkg_from_git(
  192. PATCHES
  193. fix-linux.patch
  194. fix-lib-name-conflict.patch
  195. + o3de_handler_extensions.patch
  196. )
  197. vcpkg_find_acquire_program(PYTHON3)
  198. @@ -40,41 +41,24 @@ if(NOT EXISTS "${SOURCE_PATH}/third_party/lss/lss/BUILD.gn" AND (VCPKG_TARGET_IS
  199. file(RENAME "${lss}" "${SOURCE_PATH}/third_party/lss/lss")
  200. endif()
  201. -function(replace_gn_dependency INPUT_FILE OUTPUT_FILE LIBRARY_NAMES)
  202. - if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  203. - unset(_LIBRARY_DEB CACHE)
  204. - find_library(_LIBRARY_DEB NAMES ${LIBRARY_NAMES}
  205. - PATHS "${CURRENT_INSTALLED_DIR}/debug/lib"
  206. - NO_DEFAULT_PATH)
  207. -
  208. - if(_LIBRARY_DEB MATCHES "-NOTFOUND")
  209. - message(FATAL_ERROR "Could not find debug library with names: ${LIBRARY_NAMES}")
  210. - endif()
  211. - endif()
  212. -
  213. - unset(_LIBRARY_REL CACHE)
  214. - find_library(_LIBRARY_REL NAMES ${LIBRARY_NAMES}
  215. - PATHS "${CURRENT_INSTALLED_DIR}/lib"
  216. - NO_DEFAULT_PATH)
  217. -
  218. - if(_LIBRARY_REL MATCHES "-NOTFOUND")
  219. - message(FATAL_ERROR "Could not find library with names: ${LIBRARY_NAMES}")
  220. +function(checkout_in_path PATH URL REF)
  221. + if(EXISTS "${PATH}")
  222. + return()
  223. endif()
  224. - if(VCPKG_BUILD_TYPE STREQUAL "release")
  225. - set(_LIBRARY_DEB ${_LIBRARY_REL})
  226. - endif()
  227. -
  228. - set(_INCLUDE_DIR "${CURRENT_INSTALLED_DIR}/include")
  229. -
  230. - file(REMOVE "${OUTPUT_FILE}")
  231. - configure_file("${INPUT_FILE}" "${OUTPUT_FILE}" @ONLY)
  232. + vcpkg_from_git(
  233. + OUT_SOURCE_PATH DEP_SOURCE_PATH
  234. + URL "${URL}"
  235. + REF "${REF}"
  236. + )
  237. + file(RENAME "${DEP_SOURCE_PATH}" "${PATH}")
  238. + file(REMOVE_RECURSE "${DEP_SOURCE_PATH}")
  239. endfunction()
  240. -replace_gn_dependency(
  241. - "${CMAKE_CURRENT_LIST_DIR}/zlib.gn"
  242. - "${SOURCE_PATH}/third_party/zlib/BUILD.gn"
  243. - "z;zlib;zlibd"
  244. +checkout_in_path(
  245. + "${SOURCE_PATH}/third_party/zlib/zlib"
  246. + "https://chromium.googlesource.com/chromium/src/third_party/zlib"
  247. + "1e85c01b15363d11fab81c46fe2b5c2179113f70"
  248. )
  249. set(OPTIONS "target_cpu=\"${VCPKG_TARGET_ARCHITECTURE}\"")
  250. @@ -127,9 +111,14 @@ vcpkg_gn_configure(
  251. OPTIONS_RELEASE "${OPTIONS_REL}"
  252. )
  253. +set(TARGET_MODULES client client:common util third_party/mini_chromium/mini_chromium/base handler handler:common util:net tools:tool_support compat minidump:format minidump snapshot:context snapshot)
  254. +if(VCPKG_TARGET_IS_WINDOWS)
  255. + list(APPEND TARGET_MODULES third_party/getopt third_party/zlib)
  256. +endif()
  257. +
  258. vcpkg_gn_install(
  259. SOURCE_PATH "${SOURCE_PATH}"
  260. - TARGETS client client:common util third_party/mini_chromium/mini_chromium/base handler:crashpad_handler
  261. + TARGETS ${TARGET_MODULES}
  262. )
  263. message(STATUS "Installing headers...")
  264. @@ -138,9 +127,17 @@ function(install_headers DIR)
  265. file(COPY "${DIR}" DESTINATION "${PACKAGES_INCLUDE_DIR}" FILES_MATCHING PATTERN "*.h")
  266. endfunction()
  267. install_headers("${SOURCE_PATH}/client")
  268. +install_headers("${SOURCE_PATH}/compat")
  269. +install_headers("${SOURCE_PATH}/handler")
  270. +install_headers("${SOURCE_PATH}/minidump")
  271. +install_headers("${SOURCE_PATH}/snapshot")
  272. +install_headers("${SOURCE_PATH}/third_party/mini_chromium/mini_chromium")
  273. +install_headers("${SOURCE_PATH}/tools")
  274. install_headers("${SOURCE_PATH}/util")
  275. -install_headers("${SOURCE_PATH}/third_party/mini_chromium/mini_chromium/base")
  276. -install_headers("${SOURCE_PATH}/third_party/mini_chromium/mini_chromium/build")
  277. +if(VCPKG_TARGET_IS_WINDOWS)
  278. + install_headers("${SOURCE_PATH}/third_party/getopt")
  279. + install_headers("${SOURCE_PATH}/third_party/zlib/zlib")
  280. +endif()
  281. file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/gen/build/chromeos_buildflags.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}/build")
  282. file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/gen/build/chromeos_buildflags.h.flags" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}/build")
  283. @@ -152,18 +149,6 @@ if(VCPKG_TARGET_IS_OSX)
  284. file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/obj/util/libmig_output.a" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
  285. endif()
  286. -vcpkg_copy_tools(
  287. - TOOL_NAMES crashpad_handler
  288. - SEARCH_DIR "${CURRENT_PACKAGES_DIR}/tools")
  289. -
  290. -if(NOT VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_MINGW)
  291. - file(CHMOD "${CURRENT_PACKAGES_DIR}/tools/crashpad_handler" FILE_PERMISSIONS
  292. - OWNER_READ OWNER_WRITE OWNER_EXECUTE
  293. - GROUP_READ GROUP_EXECUTE
  294. - WORLD_READ WORLD_EXECUTE
  295. - )
  296. -endif()
  297. -
  298. # remove empty directories
  299. file(REMOVE_RECURSE
  300. "${PACKAGES_INCLUDE_DIR}/util/net/testdata"
  301. diff --git a/ports/crashpad/vcpkg.json b/ports/crashpad/vcpkg.json
  302. index c2e9cd5..a0d7bcf 100644
  303. --- a/ports/crashpad/vcpkg.json
  304. +++ b/ports/crashpad/vcpkg.json
  305. @@ -27,7 +27,6 @@
  306. {
  307. "name": "vcpkg-tool-gn",
  308. "host": true
  309. - },
  310. - "zlib"
  311. + }
  312. ]
  313. }