DllMain.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include "CrySystem_precompiled.h"
  9. #include "System.h"
  10. #include <AZCrySystemInitLogSink.h>
  11. #include "DebugCallStack.h"
  12. #include <AzCore/Module/Environment.h> // for AZ_DECLARE_MODULE_INITIALIZATION
  13. #if defined(AZ_RESTRICTED_PLATFORM)
  14. #undef AZ_RESTRICTED_SECTION
  15. #define DLLMAIN_CPP_SECTION_1 1
  16. #define DLLMAIN_CPP_SECTION_2 2
  17. #define DLLMAIN_CPP_SECTION_3 3
  18. #define DLLMAIN_CPP_SECTION_4 4
  19. #endif
  20. #if defined(AZ_RESTRICTED_PLATFORM)
  21. #define AZ_RESTRICTED_SECTION DLLMAIN_CPP_SECTION_1
  22. #include AZ_RESTRICTED_FILE(DllMain_cpp)
  23. #endif
  24. // For lua debugger
  25. //#include <malloc.h>
  26. HMODULE gDLLHandle = NULL;
  27. #if !defined(AZ_MONOLITHIC_BUILD) && defined(AZ_HAS_DLL_SUPPORT) && AZ_TRAIT_LEGACY_CRYSYSTEM_DEFINE_DLLMAIN
  28. AZ_PUSH_DISABLE_WARNING(4447, "-Wunknown-warning-option")
  29. BOOL APIENTRY DllMain(HANDLE hModule,
  30. DWORD ul_reason_for_call,
  31. [[maybe_unused]] LPVOID lpReserved
  32. )
  33. AZ_POP_DISABLE_WARNING
  34. {
  35. PREVENT_MODULE_AND_ENVIRONMENT_SYMBOL_STRIPPING
  36. gDLLHandle = (HMODULE)hModule;
  37. switch (ul_reason_for_call)
  38. {
  39. case DLL_PROCESS_ATTACH:
  40. break;
  41. case DLL_THREAD_ATTACH:
  42. break;
  43. case DLL_THREAD_DETACH:
  44. case DLL_PROCESS_DETACH:
  45. break;
  46. }
  47. // int sbh = _set_sbh_threshold(1016);
  48. return TRUE;
  49. }
  50. #endif
  51. extern "C"
  52. {
  53. #if !defined(AZ_MONOLITHIC_BUILD)
  54. CRYSYSTEM_API
  55. #endif
  56. ISystem* CreateSystemInterface(const SSystemInitParams& startupParams)
  57. {
  58. CSystem* pSystem = NULL;
  59. pSystem = new CSystem();
  60. ModuleInitISystem(pSystem, "CrySystem");
  61. #if defined(AZ_RESTRICTED_PLATFORM)
  62. #define AZ_RESTRICTED_SECTION DLLMAIN_CPP_SECTION_2
  63. #include AZ_RESTRICTED_FILE(DllMain_cpp)
  64. #endif
  65. // the earliest point the system exists - w2e tell the callback
  66. if (startupParams.pUserCallback)
  67. {
  68. startupParams.pUserCallback->OnSystemConnect(pSystem);
  69. }
  70. #if defined(WIN32)
  71. // Environment Variable to signal we don't want to override our exception handler - our crash report system will set this
  72. auto envVar = AZ::Environment::FindVariable<bool>("ExceptionHandlerIsSet");
  73. const bool handlerIsSet = (envVar && *envVar);
  74. if (!handlerIsSet)
  75. {
  76. ((DebugCallStack*)IDebugCallStack::instance())->installErrorHandler(pSystem);
  77. }
  78. #endif
  79. bool retVal = false;
  80. {
  81. AZ::Debug::StartupLogSinkReporter<AZ::Debug::CrySystemInitLogSink> initLogSink;
  82. retVal = pSystem->Init(startupParams);
  83. if (!retVal)
  84. {
  85. initLogSink.GetContainedLogSink().SetFatalMessageBox();
  86. }
  87. }
  88. if (!retVal)
  89. {
  90. delete pSystem;
  91. gEnv = nullptr;
  92. return 0;
  93. }
  94. return pSystem;
  95. }
  96. };
  97. // declare the functions used by AZ::DynamicModule to [un]initialize the library here
  98. AZ_DECLARE_MODULE_INITIALIZATION