From b513517493967d07696805b670e780f7848b527c Mon Sep 17 00:00:00 2001 From: AzureGem Date: Thu, 14 Mar 2024 19:37:31 -0400 Subject: [PATCH] Add support for using Server GC --- Dalamud.Boot/DalamudStartInfo.cpp | 2 ++ Dalamud.Boot/DalamudStartInfo.h | 1 + Dalamud.Boot/dllmain.cpp | 1 + Dalamud.Common/DalamudStartInfo.cs | 5 +++++ Dalamud.Injector.Boot/main.cpp | 1 + Dalamud.Injector/EntryPoint.cs | 1 + lib/CoreCLR/boot.cpp | 2 ++ lib/CoreCLR/boot.h | 1 + 8 files changed, 14 insertions(+) diff --git a/Dalamud.Boot/DalamudStartInfo.cpp b/Dalamud.Boot/DalamudStartInfo.cpp index f5632a2ea..3b1fe2f9e 100644 --- a/Dalamud.Boot/DalamudStartInfo.cpp +++ b/Dalamud.Boot/DalamudStartInfo.cpp @@ -108,6 +108,7 @@ void from_json(const nlohmann::json& json, DalamudStartInfo& config) { config.BootVehEnabled = json.value("BootVehEnabled", config.BootVehEnabled); config.BootVehFull = json.value("BootVehFull", config.BootVehFull); config.BootEnableEtw = json.value("BootEnableEtw", config.BootEnableEtw); + config.BootEnableGcServer = json.value("BootEnableGcServer", config.BootEnableGcServer); config.BootDotnetOpenProcessHookMode = json.value("BootDotnetOpenProcessHookMode", config.BootDotnetOpenProcessHookMode); if (const auto it = json.find("BootEnabledGameFixes"); it != json.end() && it->is_array()) { config.BootEnabledGameFixes.clear(); @@ -133,6 +134,7 @@ void DalamudStartInfo::from_envvars() { BootVehEnabled = utils::get_env(L"DALAMUD_IS_VEH"); BootVehFull = utils::get_env(L"DALAMUD_IS_VEH_FULL"); BootEnableEtw = utils::get_env(L"DALAMUD_ENABLE_ETW"); + BootEnableGcServer = utils::get_env(L"DALAMUD_ENABLE_GCSERVER"); BootDotnetOpenProcessHookMode = static_cast(utils::get_env(L"DALAMUD_DOTNET_OPENPROCESS_HOOKMODE")); for (const auto& item : utils::get_env_list(L"DALAMUD_GAMEFIX_LIST")) BootEnabledGameFixes.insert(unicode::convert(item, &unicode::lower)); diff --git a/Dalamud.Boot/DalamudStartInfo.h b/Dalamud.Boot/DalamudStartInfo.h index e6cc54ab0..5ce3ee2cf 100644 --- a/Dalamud.Boot/DalamudStartInfo.h +++ b/Dalamud.Boot/DalamudStartInfo.h @@ -54,6 +54,7 @@ struct DalamudStartInfo { bool BootVehEnabled = false; bool BootVehFull = false; bool BootEnableEtw = false; + bool BootEnableGcServer = false; DotNetOpenProcessHookMode BootDotnetOpenProcessHookMode = DotNetOpenProcessHookMode::ImportHooks; std::set BootEnabledGameFixes{}; std::set BootUnhookDlls{}; diff --git a/Dalamud.Boot/dllmain.cpp b/Dalamud.Boot/dllmain.cpp index e6aa9c4ac..7402dc6cf 100644 --- a/Dalamud.Boot/dllmain.cpp +++ b/Dalamud.Boot/dllmain.cpp @@ -117,6 +117,7 @@ HRESULT WINAPI InitializeImpl(LPVOID lpParam, HANDLE hMainThreadContinue) { const auto result = InitializeClrAndGetEntryPoint( g_hModule, g_startInfo.BootEnableEtw, + g_startInfo.BootEnableGcServer, runtimeconfig_path, module_path, L"Dalamud.EntryPoint, Dalamud", diff --git a/Dalamud.Common/DalamudStartInfo.cs b/Dalamud.Common/DalamudStartInfo.cs index a84d3b68f..521f91004 100644 --- a/Dalamud.Common/DalamudStartInfo.cs +++ b/Dalamud.Common/DalamudStartInfo.cs @@ -124,6 +124,11 @@ public DalamudStartInfo() /// public bool BootEnableEtw { get; set; } + /// + /// Gets or sets a value indicating whether or not GC Server should be enabled. + /// + public bool BootEnableGcServer { get; set; } + /// /// Gets or sets a value choosing the OpenProcess hookmode. /// diff --git a/Dalamud.Injector.Boot/main.cpp b/Dalamud.Injector.Boot/main.cpp index 7fc44f5e1..c6024da24 100644 --- a/Dalamud.Injector.Boot/main.cpp +++ b/Dalamud.Injector.Boot/main.cpp @@ -26,6 +26,7 @@ int wmain(int argc, wchar_t** argv) const auto result = InitializeClrAndGetEntryPoint( GetModuleHandleW(nullptr), false, + false, runtimeconfig_path, module_path, L"Dalamud.Injector.EntryPoint, Dalamud.Injector", diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index 9085eae04..a8601d459 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -394,6 +394,7 @@ private static DalamudStartInfo ExtractAndInitializeStartInfoFromArguments(Dalam // Set boot defaults startInfo.BootShowConsole = args.Contains("--console"); startInfo.BootEnableEtw = args.Contains("--etw"); + startInfo.BootEnableGcServer = args.Contains("--gc-server"); startInfo.BootLogPath = GetLogPath(startInfo.LogPath, "dalamud.boot", startInfo.LogName); startInfo.BootEnabledGameFixes = new() { diff --git a/lib/CoreCLR/boot.cpp b/lib/CoreCLR/boot.cpp index 54276aad1..8f17ffdf8 100644 --- a/lib/CoreCLR/boot.cpp +++ b/lib/CoreCLR/boot.cpp @@ -30,6 +30,7 @@ std::optional g_clr; HRESULT InitializeClrAndGetEntryPoint( void* calling_module, bool enable_etw, + bool enable_gcServer, std::wstring runtimeconfig_path, std::wstring module_path, std::wstring entrypoint_assembly_name, @@ -55,6 +56,7 @@ HRESULT InitializeClrAndGetEntryPoint( SetEnvironmentVariable(L"DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT", L"0"); SetEnvironmentVariable(L"COMPlus_ETWEnabled", enable_etw ? L"1" : L"0"); + SetEnvironmentVariable(L"DOTNET_gcServer", enable_gcServer ? L"1" : L"0"); wchar_t* dotnet_path; wchar_t* _appdata; diff --git a/lib/CoreCLR/boot.h b/lib/CoreCLR/boot.h index 33bc58bbf..89b833d49 100644 --- a/lib/CoreCLR/boot.h +++ b/lib/CoreCLR/boot.h @@ -4,6 +4,7 @@ void ConsoleTeardown(); HRESULT InitializeClrAndGetEntryPoint( void* calling_module, bool enable_etw, + bool enable_gcServer, std::wstring runtimeconfig_path, std::wstring module_path, std::wstring entrypoint_assembly_name,