From c381bc0c982f36b9492975d49e5fed82680a749d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 28 Jun 2019 13:31:19 -0700 Subject: [PATCH] Use regular static variable for EEConfig storage (#25479) Fixes #25475 --- src/vm/ceemain.cpp | 6 +----- src/vm/eeconfig.cpp | 33 ++++++++------------------------- src/vm/eeconfig.h | 2 -- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/vm/ceemain.cpp b/src/vm/ceemain.cpp index 10fd928..b91fe71 100644 --- a/src/vm/ceemain.cpp +++ b/src/vm/ceemain.cpp @@ -630,11 +630,7 @@ void EEStartupHelper(COINITIEE fFlags) // This needs to be done before config because config uses SString::Empty() SString::Startup(); - // Initialize EEConfig - if (!g_pConfig) - { - IfFailGo(EEConfig::Setup()); - } + IfFailGo(EEConfig::Setup()); #ifndef CROSSGEN_COMPILE // Initialize Numa and CPU group information diff --git a/src/vm/eeconfig.cpp b/src/vm/eeconfig.cpp index a0267d4..e3b9d8a 100644 --- a/src/vm/eeconfig.cpp +++ b/src/vm/eeconfig.cpp @@ -122,47 +122,30 @@ LPUTF8 NarrowWideChar(__inout_z LPWSTR str) RETURN NULL; } +/**************************************************************/ +static EEConfig g_EEConfig; + HRESULT EEConfig::Setup() { STANDARD_VM_CONTRACT; ETWOnStartup (EEConfigSetup_V1,EEConfigSetupEnd_V1); - - // This 'new' uses EEConfig's overloaded new, which uses a static memory buffer and will - // not fail - EEConfig *pConfig = new EEConfig(); + + _ASSERTE(g_pConfig == NULL && "EEConfig::Setup called multiple times!"); + + EEConfig *pConfig = &g_EEConfig; HRESULT hr = pConfig->Init(); if (FAILED(hr)) return hr; - EEConfig *pConfigOld = NULL; - pConfigOld = InterlockedCompareExchangeT(&g_pConfig, pConfig, NULL); + g_pConfig = pConfig; - _ASSERTE(pConfigOld == NULL && "EEConfig::Setup called multiple times!"); - return S_OK; } /**************************************************************/ -// For in-place constructor -BYTE g_EEConfigMemory[sizeof(EEConfig)]; - -void *EEConfig::operator new(size_t size) -{ - CONTRACT(void*) { - FORBID_FAULT; - GC_NOTRIGGER; - NOTHROW; - MODE_ANY; - POSTCONDITION(CheckPointer(RETVAL)); - } CONTRACT_END; - - RETURN g_EEConfigMemory; -} - -/**************************************************************/ HRESULT EEConfig::Init() { STANDARD_VM_CONTRACT; diff --git a/src/vm/eeconfig.h b/src/vm/eeconfig.h index c952265..4d80650 100644 --- a/src/vm/eeconfig.h +++ b/src/vm/eeconfig.h @@ -256,8 +256,6 @@ public: static HRESULT Setup(); - void *operator new(size_t size); - HRESULT Init(); HRESULT Cleanup(); -- 2.7.4