diff --git a/FEXCore/Source/Interface/Config/Config.cpp b/FEXCore/Source/Interface/Config/Config.cpp index be169803f4..c9ea2bcefe 100644 --- a/FEXCore/Source/Interface/Config/Config.cpp +++ b/FEXCore/Source/Interface/Config/Config.cpp @@ -49,22 +49,24 @@ enum Paths { PATH_CONFIG_TELEMETRY_FOLDER, PATH_LAST, }; -static std::array Paths; +using PathsType = std::array; +static PathsType* Paths {}; +alignas(alignof(PathsType)) static char PathsPlacement[sizeof(PathsType)]; void SetDataDirectory(const std::string_view Path, bool Global) { - Paths[PATH_DATA_DIR_LOCAL + Global] = Path; + (*Paths)[PATH_DATA_DIR_LOCAL + Global] = Path; } void SetConfigDirectory(const std::string_view Path, bool Global) { - Paths[PATH_CONFIG_DIR_LOCAL + Global] = Path; + (*Paths)[PATH_CONFIG_DIR_LOCAL + Global] = Path; } void SetConfigFileLocation(const std::string_view Path, bool Global) { - Paths[PATH_CONFIG_FILE_LOCAL + Global] = Path; + (*Paths)[PATH_CONFIG_FILE_LOCAL + Global] = Path; } const fextl::string& GetTelemetryDirectory() { - auto& Path = Paths[PATH_CONFIG_TELEMETRY_FOLDER]; + auto& Path = (*Paths)[PATH_CONFIG_TELEMETRY_FOLDER]; if (Path.empty()) { FEX_CONFIG_OPT(TelemetryDirectory, TELEMETRYDIRECTORY); if (!TelemetryDirectory().empty()) { @@ -79,15 +81,15 @@ const fextl::string& GetTelemetryDirectory() { } const fextl::string& GetDataDirectory(bool Global) { - return Paths[PATH_DATA_DIR_LOCAL + Global]; + return (*Paths)[PATH_DATA_DIR_LOCAL + Global]; } const fextl::string& GetConfigDirectory(bool Global) { - return Paths[PATH_CONFIG_DIR_LOCAL + Global]; + return (*Paths)[PATH_CONFIG_DIR_LOCAL + Global]; } const fextl::string& GetConfigFileLocation(bool Global) { - return Paths[PATH_CONFIG_FILE_LOCAL + Global]; + return (*Paths)[PATH_CONFIG_FILE_LOCAL + Global]; } fextl::string GetApplicationConfig(const std::string_view Program, bool Global) { @@ -110,7 +112,9 @@ fextl::string GetApplicationConfig(const std::string_view Program, bool Global) return fextl::fmt::format("{}{}.json", ConfigFile, Program); } -static fextl::map> ConfigLayers; +using ConfigLayerType = fextl::map>; +static ConfigLayerType* ConfigLayers; +alignas(alignof(ConfigLayerType)) static char ConfigLayersPlacement[sizeof(ConfigLayerType)]; class MetaLayer; static FEXCore::Config::MetaLayer* Meta {}; @@ -172,8 +176,8 @@ void MetaLayer::Load() { OptionMap.clear(); for (auto CurrentLayer = LoadOrder.begin(); CurrentLayer != LoadOrder.end(); ++CurrentLayer) { - auto it = ConfigLayers.find(*CurrentLayer); - if (it != ConfigLayers.end() && *CurrentLayer != Type) { + auto it = ConfigLayers->find(*CurrentLayer); + if (it != ConfigLayers->end() && *CurrentLayer != Type) { // Merge this layer's options to this layer MergeConfigMap(it->second->GetOptionMap()); } @@ -234,19 +238,21 @@ void MetaLayer::MergeConfigMap(const LayerOptions& Options) { } void Initialize() { + Paths = new (PathsPlacement) PathsType {}; + ConfigLayers = new (ConfigLayersPlacement) ConfigLayerType {}; AddLayer(fextl::make_unique(FEXCore::Config::LayerType::LAYER_TOP)); - Meta = dynamic_cast(ConfigLayers.begin()->second.get()); + Meta = dynamic_cast(ConfigLayers->begin()->second.get()); } void Shutdown() { - ConfigLayers.clear(); + ConfigLayers->clear(); Meta = nullptr; } void Load() { for (auto CurrentLayer = LoadOrder.begin(); CurrentLayer != LoadOrder.end(); ++CurrentLayer) { - auto it = ConfigLayers.find(*CurrentLayer); - if (it != ConfigLayers.end()) { + auto it = ConfigLayers->find(*CurrentLayer); + if (it != ConfigLayers->end()) { it->second->Load(); } } @@ -412,7 +418,7 @@ void ReloadMetaLayer() { } void AddLayer(fextl::unique_ptr _Layer) { - ConfigLayers.emplace(_Layer->GetLayerType(), std::move(_Layer)); + ConfigLayers->emplace(_Layer->GetLayerType(), std::move(_Layer)); } bool Exists(ConfigOption Option) { diff --git a/Source/Common/Config.cpp b/Source/Common/Config.cpp index 62fa61f94b..45dd260f66 100644 --- a/Source/Common/Config.cpp +++ b/Source/Common/Config.cpp @@ -456,8 +456,8 @@ ApplicationNames GetApplicationNames(const fextl::vector& Args, b void LoadConfig(fextl::string ProgramName, char** const envp, const PortableInformation& PortableInfo) { const bool IsPortable = PortableInfo.IsPortable; - FEX::Config::InitializeConfigs(PortableInfo); FEXCore::Config::Initialize(); + FEX::Config::InitializeConfigs(PortableInfo); if (!IsPortable) { FEXCore::Config::AddLayer(CreateGlobalMainLayer()); } diff --git a/Source/Tools/FEXGetConfig/Main.cpp b/Source/Tools/FEXGetConfig/Main.cpp index d7510aa99e..d0a7ffd37a 100644 --- a/Source/Tools/FEXGetConfig/Main.cpp +++ b/Source/Tools/FEXGetConfig/Main.cpp @@ -95,8 +95,8 @@ TSOEmulationFacts GetTSOEmulationFacts() { } // namespace int main(int argc, char** argv, char** envp) { - FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {}); FEXCore::Config::Initialize(); + FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {}); FEXCore::Config::AddLayer(FEX::Config::CreateGlobalMainLayer()); FEXCore::Config::AddLayer(FEX::Config::CreateMainLayer()); // No FEX arguments passed through command line diff --git a/Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp b/Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp index 4a0f851155..45d48c066c 100644 --- a/Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp +++ b/Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp @@ -196,8 +196,8 @@ int main(int argc, char** argv, char** const envp) { LogMan::Throw::InstallHandler(AssertHandler); LogMan::Msg::InstallHandler(MsgHandler); - FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {}); FEXCore::Config::Initialize(); + FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {}); FEXCore::Config::AddLayer(FEX::Config::CreateEnvironmentLayer(envp)); FEXCore::Config::Load();