From 94ec95335bb23b133b5f476f1e77f299cfbfa27a Mon Sep 17 00:00:00 2001 From: marzent Date: Sat, 13 Apr 2024 23:04:52 +0200 Subject: [PATCH] make legacy corrupted state exceptions policy configurable --- lib/CoreCLR/boot.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/CoreCLR/boot.cpp b/lib/CoreCLR/boot.cpp index 54276aad12..b989f92f69 100644 --- a/lib/CoreCLR/boot.cpp +++ b/lib/CoreCLR/boot.cpp @@ -41,8 +41,6 @@ HRESULT InitializeClrAndGetEntryPoint( int result; SetEnvironmentVariable(L"DOTNET_MULTILEVEL_LOOKUP", L"0"); - SetEnvironmentVariable(L"COMPlus_legacyCorruptedStateExceptionsPolicy", L"1"); - SetEnvironmentVariable(L"DOTNET_legacyCorruptedStateExceptionsPolicy", L"1"); SetEnvironmentVariable(L"COMPLUS_ForceENC", L"1"); SetEnvironmentVariable(L"DOTNET_ForceENC", L"1"); @@ -83,6 +81,25 @@ HRESULT InitializeClrAndGetEntryPoint( dotnet_path = _wcsdup(fs_app_data.append("XIVLauncher").append("runtime").c_str()); } + bool legacy_corrupted_state_exceptions_policy = false; + buffer.resize(0); + result = GetEnvironmentVariableW(L"DALAMUD_LEGACY_CORRUPTED_STATE_EXCEPTION", &buffer[0], 0); + + if (result) + { + buffer.resize(result); // The first pass returns the required length + result = GetEnvironmentVariableW(L"DALAMUD_LEGACY_CORRUPTED_STATE_EXCEPTION", &buffer[0], result); + legacy_corrupted_state_exceptions_policy = buffer == L"1"; + } + else + { + // Legacy fallback is true to preserve past behaviour + legacy_corrupted_state_exceptions_policy = true; + } + + SetEnvironmentVariable(L"COMPlus_legacyCorruptedStateExceptionsPolicy", legacy_corrupted_state_exceptions_policy ? L"1" : L"0"); + SetEnvironmentVariable(L"DOTNET_legacyCorruptedStateExceptionsPolicy", legacy_corrupted_state_exceptions_policy ? L"1" : L"0"); + // =========================================================================== // logging::I("with dotnet_path: {}", dotnet_path);