[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>
This commit is contained in:
@@ -49,9 +49,6 @@
|
||||
#include "Include/IObjectManager.h"
|
||||
#include "ActionManager.h"
|
||||
|
||||
// Including this too early will result in a linker error
|
||||
#include <CryCommon/CryLibrary.h>
|
||||
|
||||
// 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<void, AZStd::string> 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<PFNCREATESYSTEMINTERFACE>("CreateSystemInterface");
|
||||
|
||||
SSystemInitParams sip;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ struct IInitializeUIInfo;
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
|
||||
#include <AzCore/Module/DynamicModuleHandle.h>
|
||||
|
||||
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<AZ::DynamicModuleHandle> m_hSystemHandle;
|
||||
enum EPendingGameMode
|
||||
{
|
||||
ePGM_NotPending,
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
// Editor
|
||||
#include "MainStatusBarItems.h"
|
||||
#include "CryLibrary.h"
|
||||
#include "ProcessInfo.h"
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include <AzGameFramework/Application/GameApplication.h>
|
||||
|
||||
#include <CryLibrary.h>
|
||||
#include <ISystem.h>
|
||||
#include <ITimer.h>
|
||||
#include <LegacyAllocator.h>
|
||||
@@ -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<DynamicModuleHandle> Create(const char* fullFileName)
|
||||
{
|
||||
return AZStd::unique_ptr<DynamicModuleHandle>(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<typename Function>
|
||||
Function GetFunction(const char* functionName) const
|
||||
{
|
||||
if (IsLoaded())
|
||||
{
|
||||
return reinterpret_cast<Function>(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<DynamicModuleHandle> Create(const char* fullFileName)
|
||||
{
|
||||
return AZStd::unique_ptr<DynamicModuleHandle>(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<InjectEnvironmentFunction>(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<DetachEnvironmentFunction>(DETACH_ENVIRONMENT_FUNCTION);
|
||||
if (detachEnv)
|
||||
{
|
||||
detachEnv();
|
||||
}
|
||||
}
|
||||
return unloaded;
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
Function GetFunction(const char* functionName) const
|
||||
{
|
||||
return m_moduleHandle->GetFunction<Function>(functionName);
|
||||
}
|
||||
|
||||
private:
|
||||
DynamicModuleHandle(const char* fileFullName)
|
||||
: m_moduleHandle(AZ::DynamicModuleHandle::Create(fileFullName))
|
||||
{
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<AZ::DynamicModuleHandle> 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<DynamicModuleHandle> 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<AZ::DynamicModuleHandle> crySystemLibrary = AZ::DynamicModuleHandle::Create(crySystemLibraryName);
|
||||
if (crySystemLibrary->Load(true))
|
||||
{
|
||||
CreateSystemInterface = crySystemLibrary->GetFunction<PFNCREATESYSTEMINTERFACE>("CreateSystemInterface");
|
||||
PFNCREATESYSTEMINTERFACE CreateSystemInterface =
|
||||
crySystemLibrary->GetFunction<PFNCREATESYSTEMINTERFACE>("CreateSystemInterface");
|
||||
|
||||
if (CreateSystemInterface)
|
||||
{
|
||||
systemInitParams.pSystem = CreateSystemInterface(systemInitParams);
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <AzCore/IO/SystemFile.h> // for AZ_MAX_PATH_LEN
|
||||
#include <AzCore/Math/Vector2.h>
|
||||
|
||||
#include <CryLibrary.h>
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <libgen.h>
|
||||
#include <netdb.h>
|
||||
@@ -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<int>(ReturnCode::ErrExePath);
|
||||
}
|
||||
|
||||
char* runDir = dirname(exePath);
|
||||
SetModulePath(runDir);
|
||||
#endif // !defined(AZ_MONOLITHIC_BUILD)
|
||||
|
||||
PlatformMainInfo mainInfo;
|
||||
|
||||
mainInfo.m_updateResourceLimits = IncreaseResourceLimits;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
#include <Launcher.h>
|
||||
|
||||
#include <CryCommon/CryLibrary.h>
|
||||
#include <AzCore/Math/Vector2.h>
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
|
||||
@@ -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<AZ::SystemAllocator>::Destroy();
|
||||
|
||||
@@ -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 <CryCommon/CryLibrary.h>
|
||||
|
||||
#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<InjectEnvironmentFunction>(::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<DetachEnvironmentFunction>(::GetProcAddress((HMODULE)lib, DETACH_ENVIRONMENT_FUNCTION));
|
||||
if (detachEnv)
|
||||
{
|
||||
detachEnv();
|
||||
}
|
||||
return ::FreeLibrary((HMODULE)lib) != FALSE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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 <stdio.h>
|
||||
#include <AzCore/PlatformIncl.h>
|
||||
#include <AzCore/Module/Environment.h>
|
||||
|
||||
#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 <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include "platform.h"
|
||||
#include <AzCore/Debug/Trace.h>
|
||||
|
||||
// for compatibility with code written for windows
|
||||
#define CrySharedLibrarySupported true
|
||||
#define CrySharedLibraryPrefix "lib"
|
||||
#if AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
#include <mach-o/dyld.h>
|
||||
#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<InjectEnvironmentFunction>(CryGetProcAddress(module, INJECT_ENVIRONMENT_FUNCTION));
|
||||
if (injectEnv)
|
||||
{
|
||||
injectEnv(AZ::Environment::GetInstance());
|
||||
}
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
inline bool CryFreeLibrary(void* lib)
|
||||
{
|
||||
if (lib)
|
||||
{
|
||||
DetachEnvironmentFunction detachEnv = reinterpret_cast<DetachEnvironmentFunction>(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))
|
||||
@@ -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"
|
||||
|
||||
@@ -73,7 +73,6 @@ unsigned int g_EnableMultipleAssert = 0;//set to something else than 0 if to ena
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include "CryLibrary.h"
|
||||
#endif
|
||||
|
||||
#if defined(APPLE)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<AZ::EnvironmentInstance>(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<void*>(&ModuleInitISystem);
|
||||
@@ -126,16 +110,6 @@ void* GetModuleShutdownISystemSymbol()
|
||||
{
|
||||
return reinterpret_cast<void*>(&ModuleShutdownISystem);
|
||||
}
|
||||
void* GetInjectEnvironmentSymbol()
|
||||
{
|
||||
return reinterpret_cast<void*>(&InjectEnvironment);
|
||||
}
|
||||
void* GetDetachEnvironmentSymbol()
|
||||
{
|
||||
return reinterpret_cast<void*>(&DetachEnvironment);
|
||||
}
|
||||
|
||||
bool g_bProfilerEnabled = false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// global random number generator used by cry_random functions
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <AZCrySystemInitLogSink.h>
|
||||
#include "DebugCallStack.h"
|
||||
|
||||
#include <AzCore/Module/Environment.h> // 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
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <AzCore/Console/Console.h>
|
||||
#include <AzCore/IO/IStreamer.h>
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include "CryLibrary.h"
|
||||
#include <CryPath.h>
|
||||
#include <CrySystemBus.h>
|
||||
#include <CryCommon/IFont.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;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#define SYSTEMINIT_CPP_SECTION_17 17
|
||||
#endif
|
||||
|
||||
#include "CryLibrary.h"
|
||||
#include "CryPath.h"
|
||||
|
||||
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <IRenderer.h>
|
||||
#include <IMovieSystem.h>
|
||||
#include <ILog.h>
|
||||
#include <CryLibrary.h>
|
||||
#include <AzCore/Debug/StackTracer.h>
|
||||
#include <AzCore/IO/SystemFile.h> // for AZ_MAX_PATH_LEN
|
||||
#include <AzCore/std/allocator_stack.h>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user