From ab37eb138ca0fb106ac3ed39eaa7322eef3549fe Mon Sep 17 00:00:00 2001 From: Scott Romero <24445312+AMZN-ScottR@users.noreply.github.com> Date: Wed, 10 Nov 2021 08:43:13 -0800 Subject: [PATCH] [development] removed CryLibrary (#5474) * [redcode_crylibrary] replaced CrySystem loading in launcher and editor with new custom wrapper that uses AZ::DynamicModuleHandle Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> * [redcode_crylibrary] removed all remaining references to CryLibrary Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> * [redcode_crylibrary] migrate CrySystem loading to use AZ::DynamicModuleHandle directly instead Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> * [redcode_crylibrary] clean up of CrySystemModuleHandle and old CrySystem module [un]init functions Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> * [redcode_crylibrary] added trailing newline to DllMain.cpp in CrySystem Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> --- Code/Editor/GameEngine.cpp | 29 +-- Code/Editor/GameEngine.h | 10 +- Code/Editor/MainStatusBar.cpp | 1 - Code/LauncherUnified/Launcher.cpp | 153 +------------- .../Platform/Linux/Launcher_Linux.cpp | 13 -- .../Platform/Windows/Launcher_Windows.cpp | 19 -- Code/Legacy/CryCommon/CryLibrary.cpp | 47 ----- Code/Legacy/CryCommon/CryLibrary.h | 193 ------------------ Code/Legacy/CryCommon/ISystem.h | 10 +- Code/Legacy/CryCommon/WinBase.cpp | 1 - Code/Legacy/CryCommon/crycommon_files.cmake | 2 - Code/Legacy/CryCommon/platform_impl.cpp | 26 --- Code/Legacy/CrySystem/DllMain.cpp | 6 +- Code/Legacy/CrySystem/System.cpp | 1 - Code/Legacy/CrySystem/System.h | 5 - Code/Legacy/CrySystem/SystemInit.cpp | 1 - Code/Legacy/CrySystem/SystemWin32.cpp | 34 --- 17 files changed, 24 insertions(+), 527 deletions(-) delete mode 100644 Code/Legacy/CryCommon/CryLibrary.cpp delete mode 100644 Code/Legacy/CryCommon/CryLibrary.h diff --git a/Code/Editor/GameEngine.cpp b/Code/Editor/GameEngine.cpp index 5f3545e593..ff247c1e6c 100644 --- a/Code/Editor/GameEngine.cpp +++ b/Code/Editor/GameEngine.cpp @@ -49,9 +49,6 @@ #include "Include/IObjectManager.h" #include "ActionManager.h" -// Including this too early will result in a linker error -#include - // Implementation of System Callback structure. struct SSystemUserCallback : public ISystemUserCallback @@ -242,8 +239,7 @@ private: AZ_PUSH_DISABLE_WARNING(4273, "-Wunknown-warning-option") CGameEngine::CGameEngine() - : m_gameDll(nullptr) - , m_bIgnoreUpdates(false) + : m_bIgnoreUpdates(false) , m_ePendingGameMode(ePGM_NotPending) , m_modalWindowDismisser(nullptr) AZ_POP_DISABLE_WARNING @@ -253,7 +249,7 @@ AZ_POP_DISABLE_WARNING m_bInGameMode = false; m_bSimulationMode = false; m_bSyncPlayerPosition = true; - m_hSystemHandle = nullptr; + m_hSystemHandle.reset(nullptr); m_bJustCreated = false; m_levelName = "Untitled"; m_levelExtension = EditorUtils::LevelFile::GetDefaultFileExtension(); @@ -268,18 +264,10 @@ AZ_POP_DISABLE_WARNING GetIEditor()->UnregisterNotifyListener(this); m_pISystem->GetIMovieSystem()->SetCallback(nullptr); - if (m_gameDll) - { - CryFreeLibrary(m_gameDll); - } - delete m_pISystem; m_pISystem = nullptr; - if (m_hSystemHandle) - { - CryFreeLibrary(m_hSystemHandle); - } + m_hSystemHandle.reset(nullptr); delete m_pSystemUserCallback; } @@ -347,18 +335,19 @@ AZ::Outcome CGameEngine::Init( HWND hwndForInputSystem) { m_pSystemUserCallback = new SSystemUserCallback(logo); - m_hSystemHandle = CryLoadLibraryDefName("CrySystem"); - if (!m_hSystemHandle) + constexpr const char* crySystemLibraryName = AZ_TRAIT_OS_DYNAMIC_LIBRARY_PREFIX "CrySystem" AZ_TRAIT_OS_DYNAMIC_LIBRARY_EXTENSION; + + m_hSystemHandle = AZ::DynamicModuleHandle::Create(crySystemLibraryName); + if (!m_hSystemHandle->Load(true)) { - auto errorMessage = AZStd::string::format("%s Loading Failed", CryLibraryDefName("CrySystem")); + auto errorMessage = AZStd::string::format("%s Loading Failed", crySystemLibraryName); Error(errorMessage.c_str()); return AZ::Failure(errorMessage); } PFNCREATESYSTEMINTERFACE pfnCreateSystemInterface = - (PFNCREATESYSTEMINTERFACE)CryGetProcAddress(m_hSystemHandle, "CreateSystemInterface"); - + m_hSystemHandle->GetFunction("CreateSystemInterface"); SSystemInitParams sip; diff --git a/Code/Editor/GameEngine.h b/Code/Editor/GameEngine.h index 4d183cc38e..4104e9aeac 100644 --- a/Code/Editor/GameEngine.h +++ b/Code/Editor/GameEngine.h @@ -28,6 +28,8 @@ struct IInitializeUIInfo; #include #include +#include + class ThreadedOnErrorHandler : public QObject { Q_OBJECT @@ -124,11 +126,6 @@ public: return s_pakModifyMutex; } - inline HMODULE GetGameModule() const - { - return m_gameDll; - } - private: void SetGameMode(bool inGame); void SwitchToInGame(); @@ -150,8 +147,7 @@ private: AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING Matrix34 m_playerViewTM; struct SSystemUserCallback* m_pSystemUserCallback; - HMODULE m_hSystemHandle; - HMODULE m_gameDll; + AZStd::unique_ptr m_hSystemHandle; enum EPendingGameMode { ePGM_NotPending, diff --git a/Code/Editor/MainStatusBar.cpp b/Code/Editor/MainStatusBar.cpp index acc7f664df..65502eaba5 100644 --- a/Code/Editor/MainStatusBar.cpp +++ b/Code/Editor/MainStatusBar.cpp @@ -27,7 +27,6 @@ // Editor #include "MainStatusBarItems.h" -#include "CryLibrary.h" #include "ProcessInfo.h" diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 0f832ff1a5..c37f70c3b7 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -25,7 +25,6 @@ #include -#include #include #include #include @@ -80,146 +79,6 @@ namespace } } -#if AZ_TRAIT_LAUNCHER_USE_CRY_DYNAMIC_MODULE_HANDLE - // mimics AZ::DynamicModuleHandle but uses CryLibrary under the hood, - // which is necessary to properly load legacy Cry libraries on some platforms - class DynamicModuleHandle - { - public: - AZ_CLASS_ALLOCATOR(DynamicModuleHandle, AZ::OSAllocator, 0) - - static AZStd::unique_ptr Create(const char* fullFileName) - { - return AZStd::unique_ptr(aznew DynamicModuleHandle(fullFileName)); - } - - DynamicModuleHandle(const DynamicModuleHandle&) = delete; - DynamicModuleHandle& operator=(const DynamicModuleHandle&) = delete; - - ~DynamicModuleHandle() - { - Unload(); - } - - // argument is strictly to match the API of AZ::DynamicModuleHandle - bool Load(bool unused) - { - AZ_UNUSED(unused); - - if (IsLoaded()) - { - return true; - } - - m_moduleHandle = CryLoadLibrary(m_fileName.c_str()); - return IsLoaded(); - } - - bool Unload() - { - if (!IsLoaded()) - { - return false; - } - - return CryFreeLibrary(m_moduleHandle); - } - - bool IsLoaded() const - { - return m_moduleHandle != nullptr; - } - - const AZ::OSString& GetFilename() const - { - return m_fileName; - } - - template - Function GetFunction(const char* functionName) const - { - if (IsLoaded()) - { - return reinterpret_cast(CryGetProcAddress(m_moduleHandle, functionName)); - } - else - { - return nullptr; - } - } - - - private: - DynamicModuleHandle(const char* fileFullName) - : m_fileName() - , m_moduleHandle(nullptr) - { - m_fileName = AZ::OSString::format("%s%s%s", - CrySharedLibraryPrefix, fileFullName, CrySharedLibraryExtension); - } - - AZ::OSString m_fileName; - HMODULE m_moduleHandle; - }; -#else - // mimics AZ::DynamicModuleHandle but also calls InjectEnvironmentFunction on - // the loaded module which is necessary to properly load legacy Cry libraries - class DynamicModuleHandle - { - public: - AZ_CLASS_ALLOCATOR(DynamicModuleHandle, AZ::OSAllocator, 0); - - static AZStd::unique_ptr Create(const char* fullFileName) - { - return AZStd::unique_ptr(aznew DynamicModuleHandle(fullFileName)); - } - - bool Load(bool isInitializeFunctionRequired) - { - const bool loaded = m_moduleHandle->Load(isInitializeFunctionRequired); - if (loaded) - { - // We need to inject the environment first thing so that allocators are available immediately - InjectEnvironmentFunction injectEnv = GetFunction(INJECT_ENVIRONMENT_FUNCTION); - if (injectEnv) - { - auto env = AZ::Environment::GetInstance(); - injectEnv(env); - } - } - return loaded; - } - - bool Unload() - { - bool unloaded = m_moduleHandle->Unload(); - if (unloaded) - { - DetachEnvironmentFunction detachEnv = GetFunction(DETACH_ENVIRONMENT_FUNCTION); - if (detachEnv) - { - detachEnv(); - } - } - return unloaded; - } - - template - Function GetFunction(const char* functionName) const - { - return m_moduleHandle->GetFunction(functionName); - } - - private: - DynamicModuleHandle(const char* fileFullName) - : m_moduleHandle(AZ::DynamicModuleHandle::Create(fileFullName)) - { - } - - AZStd::unique_ptr m_moduleHandle; - }; -#endif // AZ_TRAIT_LAUNCHER_USE_CRY_DYNAMIC_MODULE_HANDLE - void RunMainLoop(AzGameFramework::GameApplication& gameApplication) { // Ideally we'd just call GameApplication::RunMainLoop instead, but @@ -649,13 +508,13 @@ namespace O3DELauncher // Create CrySystem. #if !defined(AZ_MONOLITHIC_BUILD) - AZStd::unique_ptr crySystemLibrary; - PFNCREATESYSTEMINTERFACE CreateSystemInterface = nullptr; - - crySystemLibrary = DynamicModuleHandle::Create("CrySystem"); - if (crySystemLibrary->Load(false)) + constexpr const char* crySystemLibraryName = AZ_TRAIT_OS_DYNAMIC_LIBRARY_PREFIX "CrySystem" AZ_TRAIT_OS_DYNAMIC_LIBRARY_EXTENSION; + AZStd::unique_ptr crySystemLibrary = AZ::DynamicModuleHandle::Create(crySystemLibraryName); + if (crySystemLibrary->Load(true)) { - CreateSystemInterface = crySystemLibrary->GetFunction("CreateSystemInterface"); + PFNCREATESYSTEMINTERFACE CreateSystemInterface = + crySystemLibrary->GetFunction("CreateSystemInterface"); + if (CreateSystemInterface) { systemInitParams.pSystem = CreateSystemInterface(systemInitParams); diff --git a/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp b/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp index 3030dcc740..e210a59738 100644 --- a/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp +++ b/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp @@ -12,8 +12,6 @@ #include // for AZ_MAX_PATH_LEN #include -#include - #include #include #include @@ -86,17 +84,6 @@ int main(int argc, char** argv) using namespace O3DELauncher; -#if !defined(AZ_MONOLITHIC_BUILD) - char exePath[AZ_MAX_PATH_LEN] = { 0 }; - if (readlink("/proc/self/exe", exePath, AZ_MAX_PATH_LEN) == -1) - { - return static_cast(ReturnCode::ErrExePath); - } - - char* runDir = dirname(exePath); - SetModulePath(runDir); -#endif // !defined(AZ_MONOLITHIC_BUILD) - PlatformMainInfo mainInfo; mainInfo.m_updateResourceLimits = IncreaseResourceLimits; diff --git a/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp b/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp index d1e6a69e5e..0d0ca3e8b0 100644 --- a/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp +++ b/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp @@ -7,7 +7,6 @@ */ #include -#include #include #include @@ -43,24 +42,6 @@ int APIENTRY WinMain([[maybe_unused]] HINSTANCE hInstance, [[maybe_unused]] HINS MessageBoxA(0, GetReturnCodeString(status), "Error", MB_OK | MB_DEFAULT_DESKTOP_ONLY | MB_ICONERROR); } -#if !defined(AZ_MONOLITHIC_BUILD) - - { - // HACK HACK HACK - is this still needed?!?! - // CrySystem module can get loaded multiple times (even from within CrySystem itself) - // so we will release it as many times as it takes until it actually unloads. - void* hModule = CryLoadLibraryDefName("CrySystem"); - if (hModule) - { - // loop until we fail (aka unload the DLL) - while (CryFreeLibrary(hModule)) - { - ; - } - } - } -#endif // !defined(AZ_MONOLITHIC_BUILD) - // there is no way to transfer ownership of the allocator to the component application // without altering the app descriptor, so it must be destroyed here AZ::AllocatorInstance::Destroy(); diff --git a/Code/Legacy/CryCommon/CryLibrary.cpp b/Code/Legacy/CryCommon/CryLibrary.cpp deleted file mode 100644 index 07c74f5b97..0000000000 --- a/Code/Legacy/CryCommon/CryLibrary.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#include - -#if !defined(AZ_RESTRICTED_PLATFORM) && defined(WIN32) - -HMODULE CryLoadLibrary(const char* libName) -{ - HMODULE module = ::LoadLibraryA(libName); - if (module != NULL) - { - // We need to inject the environment first thing so that allocators are available immediately - InjectEnvironmentFunction injectEnv = reinterpret_cast(::GetProcAddress(module, INJECT_ENVIRONMENT_FUNCTION)); - if (injectEnv) - { - auto env = AZ::Environment::GetInstance(); - injectEnv(env); - } - } - - return module; -} - -// Cry code seems to have used void* as their abstraction for HMODULE across -// platforms. -bool CryFreeLibrary(void* lib) -{ - if (lib != NULL) - { - DetachEnvironmentFunction detachEnv = reinterpret_cast(::GetProcAddress((HMODULE)lib, DETACH_ENVIRONMENT_FUNCTION)); - if (detachEnv) - { - detachEnv(); - } - return ::FreeLibrary((HMODULE)lib) != FALSE; - } - return false; -} - -#endif diff --git a/Code/Legacy/CryCommon/CryLibrary.h b/Code/Legacy/CryCommon/CryLibrary.h deleted file mode 100644 index 995ba0abc5..0000000000 --- a/Code/Legacy/CryCommon/CryLibrary.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#pragma once - - -/*! - CryLibrary - - Convenience-Macros which abstract the use of DLLs/shared libraries in a platform independent way. - A short explanation of the different macros follows: - - CrySharedLibrarySupported: - This macro can be used to test if the current active platform supports shared library calls. The default - value is false. This gets redefined if a certain platform (WIN32 or LINUX) is desired. - - CrySharedLibraryPrefix: - The default prefix which will get prepended to library names in calls to CryLoadLibraryDefName - (see below). - - CrySharedLibraryExtension: - The default extension which will get appended to library names in calls to CryLoadLibraryDefName - (see below). - - CryLoadLibrary(libName): - Loads a shared library. - - CryLoadLibraryDefName(libName): - Loads a shared library. The platform-specific default library prefix and extension are appended to the libName. - This allows writing of somewhat platform-independent library loading code and is therefore the function - which should be used most of the time, unless some special extensions are used (e.g. for plugins). - - CryGetProcAddress(libHandle, procName): - Import function from the library presented by libHandle. - - CryFreeLibrary(libHandle): - Unload the library presented by libHandle. - - HISTORY: - 03.03.2004 MarcoK - - initial version - - added to CryPlatform -*/ - -#include -#include -#include - -#define INJECT_ENVIRONMENT_FUNCTION "InjectEnvironment" -#define DETACH_ENVIRONMENT_FUNCTION "DetachEnvironment" -using InjectEnvironmentFunction = void(*)(void*); -using DetachEnvironmentFunction = void(*)(); - -#if defined(AZ_RESTRICTED_PLATFORM) - #include AZ_RESTRICTED_FILE(CryLibrary_h) -#elif defined(WIN32) - #if !defined(WIN32_LEAN_AND_MEAN) - #define WIN32_LEAN_AND_MEAN - #endif - - HMODULE CryLoadLibrary(const char* libName); - - // Cry code seems to have used void* as their abstraction for HMODULE across - // platforms. - bool CryFreeLibrary(void* lib); - - #define CRYLIBRARY_H_TRAIT_USE_WINDOWS_DLL 1 -#elif ((defined(LINUX) || AZ_TRAIT_OS_PLATFORM_APPLE)) - #include - #include - #include - #include "platform.h" - #include - -// for compatibility with code written for windows - #define CrySharedLibrarySupported true - #define CrySharedLibraryPrefix "lib" -#if AZ_TRAIT_OS_PLATFORM_APPLE - #include - #define CrySharedLibraryExtension ".dylib" -#else - #define CrySharedLibraryExtension ".so" -#endif - - #define CryGetProcAddress(libHandle, procName) ::dlsym(libHandle, procName) - #define HMODULE void* -static const char* gEnvName("MODULE_PATH"); - -inline const char* GetModulePath() -{ - return getenv(gEnvName); -} - -inline void SetModulePath(const char* pModulePath) -{ - setenv(gEnvName, pModulePath ? pModulePath : "", true); -} - -// bInModulePath is only ever set to false in RC, because rc needs to load dlls from a $PATH that -// it has modified to include .. -inline HMODULE CryLoadLibrary(const char* libName, bool bLazy = false, bool bInModulePath = true) -{ - const char* libPath = nullptr; - libPath = libName; - -#if !defined(AZ_PLATFORM_ANDROID) - if (bInModulePath) - { - char exePath[MAX_PATH + 1] = { 0 }; - const char* modulePath = GetModulePath(); - if (!modulePath) - { - modulePath = "."; - #if defined(LINUX) - int len = readlink("/proc/self/exe", exePath, MAX_PATH); - if (len != -1) - { - exePath[len] = 0; - modulePath = dirname(exePath); - } - #elif AZ_TRAIT_OS_PLATFORM_APPLE - uint32_t bufsize = MAX_PATH; - if (_NSGetExecutablePath(exePath, &bufsize) == 0) - { - exePath[bufsize] = 0; - modulePath = dirname(exePath); - } - #endif - } - char pathBuffer[MAX_PATH] = {0}; - sprintf_s(pathBuffer, "%s/%s", modulePath, libName); - libPath = pathBuffer; - } -#endif - - HMODULE module; - #if defined(LINUX) && !defined(ANDROID) - module = ::dlopen(libPath, (bLazy ? RTLD_LAZY : RTLD_NOW) | RTLD_DEEPBIND); - #else - module = ::dlopen(libPath, bLazy ? RTLD_LAZY : RTLD_NOW); - #endif - AZ_Warning("LMBR", module, "Can't load library [%s]: %s", libName, dlerror()); - - if (module) - { - // We need to inject the environment first thing so that allocators are available immediately - InjectEnvironmentFunction injectEnv = reinterpret_cast(CryGetProcAddress(module, INJECT_ENVIRONMENT_FUNCTION)); - if (injectEnv) - { - injectEnv(AZ::Environment::GetInstance()); - } - } - - return module; -} - -inline bool CryFreeLibrary(void* lib) -{ - if (lib) - { - DetachEnvironmentFunction detachEnv = reinterpret_cast(CryGetProcAddress(lib, DETACH_ENVIRONMENT_FUNCTION)); - if (detachEnv) - { - detachEnv(); - } - return (::dlclose(lib) == 0); - } - return false; -} -#endif - -#if CRYLIBRARY_H_TRAIT_USE_WINDOWS_DLL -#define CrySharedLibrarySupported true -#define CrySharedLibraryPrefix "" -#define CrySharedLibraryExtension ".dll" -#define CryGetProcAddress(libHandle, procName) ::GetProcAddress((HMODULE)(libHandle), procName) -#elif !defined(CrySharedLibrarySupported) -#define CrySharedLibrarySupported false -#define CrySharedLibraryPrefix "" -#define CrySharedLibraryExtension "" -#define CryLoadLibrary(libName) NULL -#define CryGetProcAddress(libHandle, procName) NULL -#define CryFreeLibrary(libHandle) -#define GetModuleHandle(x) 0 -#endif -#define CryLibraryDefName(libName) CrySharedLibraryPrefix libName CrySharedLibraryExtension -#define CryLoadLibraryDefName(libName) CryLoadLibrary(CryLibraryDefName(libName)) diff --git a/Code/Legacy/CryCommon/ISystem.h b/Code/Legacy/CryCommon/ISystem.h index 103e7b50c2..a243f00ea2 100644 --- a/Code/Legacy/CryCommon/ISystem.h +++ b/Code/Legacy/CryCommon/ISystem.h @@ -1104,23 +1104,15 @@ inline ISystem* GetISystem() // This function must be called once by each module at the beginning, to setup global pointers. void ModuleInitISystem(ISystem* pSystem, const char* moduleName); void ModuleShutdownISystem(ISystem* pSystem); -extern "C" AZ_DLL_EXPORT void InjectEnvironment(void* env); -extern "C" AZ_DLL_EXPORT void DetachEnvironment(); void* GetModuleInitISystemSymbol(); void* GetModuleShutdownISystemSymbol(); -void* GetInjectEnvironmentSymbol(); -void* GetDetachEnvironmentSymbol(); #define PREVENT_MODULE_AND_ENVIRONMENT_SYMBOL_STRIPPING \ AZ_UNUSED(GetModuleInitISystemSymbol()); \ - AZ_UNUSED(GetModuleShutdownISystemSymbol()); \ - AZ_UNUSED(GetInjectEnvironmentSymbol()); \ - AZ_UNUSED(GetDetachEnvironmentSymbol()); + AZ_UNUSED(GetModuleShutdownISystemSymbol()); -extern bool g_bProfilerEnabled; - // Summary: // Interface of the DLL. extern "C" diff --git a/Code/Legacy/CryCommon/WinBase.cpp b/Code/Legacy/CryCommon/WinBase.cpp index 9f7cdfd609..cb1b2aadfd 100644 --- a/Code/Legacy/CryCommon/WinBase.cpp +++ b/Code/Legacy/CryCommon/WinBase.cpp @@ -73,7 +73,6 @@ unsigned int g_EnableMultipleAssert = 0;//set to something else than 0 if to ena #include #include #include -#include "CryLibrary.h" #endif #if defined(APPLE) diff --git a/Code/Legacy/CryCommon/crycommon_files.cmake b/Code/Legacy/CryCommon/crycommon_files.cmake index c1cdcf094a..b3db694ca1 100644 --- a/Code/Legacy/CryCommon/crycommon_files.cmake +++ b/Code/Legacy/CryCommon/crycommon_files.cmake @@ -100,8 +100,6 @@ set(FILES CryAssert_iOS.h CryAssert_Linux.h CryAssert_Mac.h - CryLibrary.cpp - CryLibrary.h Linux32Specific.h Linux64Specific.h Linux_Win32Wrapper.h diff --git a/Code/Legacy/CryCommon/platform_impl.cpp b/Code/Legacy/CryCommon/platform_impl.cpp index 845a1101a4..6e61e64c4b 100644 --- a/Code/Legacy/CryCommon/platform_impl.cpp +++ b/Code/Legacy/CryCommon/platform_impl.cpp @@ -102,22 +102,6 @@ void ModuleShutdownISystem([[maybe_unused]] ISystem* pSystem) AZ::Environment::Detach(); } -extern "C" AZ_DLL_EXPORT void InjectEnvironment(void* env) -{ - static bool injected = false; - if (!injected) - { - AZ::Environment::Attach(reinterpret_cast(env)); - AZ::AllocatorManager::Instance(); // Force the AllocatorManager to instantiate and register any allocators defined in data sections - injected = true; - } -} - -extern "C" AZ_DLL_EXPORT void DetachEnvironment() -{ - AZ::Environment::Detach(); -} - void* GetModuleInitISystemSymbol() { return reinterpret_cast(&ModuleInitISystem); @@ -126,16 +110,6 @@ void* GetModuleShutdownISystemSymbol() { return reinterpret_cast(&ModuleShutdownISystem); } -void* GetInjectEnvironmentSymbol() -{ - return reinterpret_cast(&InjectEnvironment); -} -void* GetDetachEnvironmentSymbol() -{ - return reinterpret_cast(&DetachEnvironment); -} - -bool g_bProfilerEnabled = false; ////////////////////////////////////////////////////////////////////////// // global random number generator used by cry_random functions diff --git a/Code/Legacy/CrySystem/DllMain.cpp b/Code/Legacy/CrySystem/DllMain.cpp index 4a31cb51a0..cbfec93ed9 100644 --- a/Code/Legacy/CrySystem/DllMain.cpp +++ b/Code/Legacy/CrySystem/DllMain.cpp @@ -12,6 +12,8 @@ #include #include "DebugCallStack.h" +#include // for AZ_DECLARE_MODULE_INITIALIZATION + #if defined(AZ_RESTRICTED_PLATFORM) #undef AZ_RESTRICTED_SECTION #define DLLMAIN_CPP_SECTION_1 1 @@ -67,7 +69,7 @@ CRYSYSTEM_API ISystem* CreateSystemInterface(const SSystemInitParams& startupPar // We must attach to the environment prior to allocating CSystem, as opposed to waiting // for ModuleInitISystem(), because the log message sink uses buses. - // Environment should have been attached via InjectEnvironment + // Environment should have been attached via InitializeDynamicModule AZ_Assert(AZ::Environment::IsReady(), "Environment is not attached, must be attached before CreateSystemInterface can be called"); pSystem = new CSystem(startupParams.pSharedEnvironment); @@ -115,3 +117,5 @@ CRYSYSTEM_API ISystem* CreateSystemInterface(const SSystemInitParams& startupPar } }; +// declare the functions used by AZ::DynamicModule to [un]initialize the library here +AZ_DECLARE_MODULE_INITIALIZATION diff --git a/Code/Legacy/CrySystem/System.cpp b/Code/Legacy/CrySystem/System.cpp index 65facba4dd..a6ffdec4e8 100644 --- a/Code/Legacy/CrySystem/System.cpp +++ b/Code/Legacy/CrySystem/System.cpp @@ -16,7 +16,6 @@ #include #include #include -#include "CryLibrary.h" #include #include #include diff --git a/Code/Legacy/CrySystem/System.h b/Code/Legacy/CrySystem/System.h index a10c1f8ed8..fd5c917a94 100644 --- a/Code/Legacy/CrySystem/System.h +++ b/Code/Legacy/CrySystem/System.h @@ -85,10 +85,6 @@ class CWatchdogThread; #endif -#if defined(LINUX) - #include "CryLibrary.h" -#endif - #ifdef WIN32 using WIN_HMODULE = void*; #else @@ -226,7 +222,6 @@ public: void Quit() override; bool IsQuitting() const override; void ShutdownFileSystem(); // used to cleanup any file resources, such as cache handle. - void SetAffinity(); const char* GetUserName() override; int GetApplicationInstance() override; int GetApplicationLogInstance(const char* logFilePath) override; diff --git a/Code/Legacy/CrySystem/SystemInit.cpp b/Code/Legacy/CrySystem/SystemInit.cpp index d9ba3bb4c9..5bef42dc3e 100644 --- a/Code/Legacy/CrySystem/SystemInit.cpp +++ b/Code/Legacy/CrySystem/SystemInit.cpp @@ -30,7 +30,6 @@ #define SYSTEMINIT_CPP_SECTION_17 17 #endif -#include "CryLibrary.h" #include "CryPath.h" #include diff --git a/Code/Legacy/CrySystem/SystemWin32.cpp b/Code/Legacy/CrySystem/SystemWin32.cpp index 4f0a154afe..2303ff286e 100644 --- a/Code/Legacy/CrySystem/SystemWin32.cpp +++ b/Code/Legacy/CrySystem/SystemWin32.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include // for AZ_MAX_PATH_LEN #include @@ -70,39 +69,6 @@ const char* g_szModuleGroups[][2] = { {"CrySystem.dll", g_szGroupCore} }; -////////////////////////////////////////////////////////////////////////// -void CSystem::SetAffinity() -{ - // the following code is only for Windows -#ifdef WIN32 - // set the process affinity - ICVar* pcvAffinityMask = GetIConsole()->GetCVar("sys_affinity"); - if (!pcvAffinityMask) - { - pcvAffinityMask = REGISTER_INT("sys_affinity", 0, VF_NULL, ""); - } - - if (pcvAffinityMask) - { - unsigned nAffinity = pcvAffinityMask->GetIVal(); - if (nAffinity) - { - typedef BOOL (WINAPI * FnSetProcessAffinityMask)(IN HANDLE hProcess, IN DWORD_PTR dwProcessAffinityMask); - HMODULE hKernel = CryLoadLibrary ("kernel32.dll"); - if (hKernel) - { - FnSetProcessAffinityMask SetProcessAffinityMask = (FnSetProcessAffinityMask)GetProcAddress(hKernel, "SetProcessAffinityMask"); - if (SetProcessAffinityMask && !SetProcessAffinityMask(GetCurrentProcess(), nAffinity)) - { - GetILog()->LogError("Error: Cannot set affinity mask %d, error code %d", nAffinity, GetLastError()); - } - FreeLibrary (hKernel); - } - } - } -#endif -} - #if defined(WIN32) #pragma pack(push,1) struct PEHeader_DLL