Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge REGUTIL logic for environment variables into CLRConfig #50393

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 19 additions & 57 deletions src/coreclr/inc/clrconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
//

//
// Unified method of accessing configuration values from environment variables, registry and config file(s).
// This class replaces all GetConfigDWORD and GetConfigString methods in EEConfig and REGUTIL. To define a
// flag, add an entry in the table in file:CLRConfigValues.h.
//
//
//
//
// Unified method of accessing configuration values.
// To define a flag, add an entry in the table in file:CLRConfigValues.h.
// --------------------------------------------------------------------------------------------------


Expand All @@ -25,28 +20,18 @@
class CLRConfig
{
public:
//
// Types
//
// Setting each option results in some change to the config value.
enum class LookupOptions
{
// Default options.
Default = 0,

// Setting each option results in some change to the config value lookup method. Default behavior is (in
// the following order):
// * Look at environment variables (prepending COMPlus to the name)
// * Look at the framework registry keys (HKCU\Software\Microsoft\.NETFramework then
// HKLM\Software\Microsoft\.NETFramework)
// * Look at the available config files (system, application, host and user). For details see TODO:
// Link to BOTR documentation
enum LookupOptions {
// If set, don't look in environment variables.
IgnoreEnv = 0x1,
// If set, do not prepend "COMPlus_" when doing environment variable lookup.
DontPrependCOMPlus_ = 0x2,
DontPrependCOMPlus_ = 0x1,

// Remove any whitespace at beginning and end of value. (Only applicable for
// *string* configuration values.)
TrimWhiteSpaceFromStringValue = 0x100,

// Legacy EEConfig-style lookup.
EEConfig_default = 0,
TrimWhiteSpaceFromStringValue = 0x2,
};

// Struct used to store information about where/how to find a Config DWORD.
Expand Down Expand Up @@ -100,6 +85,7 @@ class CLRConfig
#define CONFIG_STRING_INFO(symbol, name, description)
#define CONFIG_STRING_INFO_EX(symbol, name, description, lookupOptions)
#endif // _DEBUG

// Now that we have defined what what the macros in file:CLRConfigValues.h mean, include it to generate the code.
#include "clrconfigvalues.h"

Expand Down Expand Up @@ -144,46 +130,22 @@ class CLRConfig
static BOOL IsConfigOptionSpecified(LPCWSTR name);

// Free a string returned by GetConfigValue
static void FreeConfigString(__in __in_z LPWSTR name);

private:

// Helper method to translate LookupOptions to REGUTIL::CORConfigLevel
static REGUTIL::CORConfigLevel GetConfigLevel(LookupOptions options);
static void FreeConfigString(__in __in_z LPWSTR name);

//
// Helper methods.
//

// Helper method to check if a certain option is set in a ConfigDWORDInfo struct.
static inline BOOL CheckLookupOption(const ConfigDWORDInfo & info, LookupOptions option)
{
LIMITED_METHOD_CONTRACT;
return ((info.options & option) == option) ? TRUE : FALSE;
}

// Helper method to check if a certain option is set in a ConfigStringInfo struct.
static inline BOOL CheckLookupOption(const ConfigStringInfo & info, LookupOptions option)
{
LIMITED_METHOD_CONTRACT;
return ((info.options & option) == option) ? TRUE : FALSE;
}

// Helper method to check if a certain option is set in an options enum.
static inline BOOL CheckLookupOption(LookupOptions infoOptions, LookupOptions optionToCheck)
{
LIMITED_METHOD_CONTRACT;
return ((infoOptions & optionToCheck) == optionToCheck) ? TRUE : FALSE;
}

static HRESULT TrimWhiteSpace(LPCWSTR wszOrig, __deref_out_z LPWSTR * pwszTrimmed);
// Populate the caches with current state to improve lookup times.
static void InitCache();
};

inline CLRConfig::LookupOptions operator|(CLRConfig::LookupOptions lhs, CLRConfig::LookupOptions rhs)
{
return static_cast<CLRConfig::LookupOptions>(static_cast<DWORD>(lhs) | static_cast<DWORD>(rhs));
}

inline CLRConfig::LookupOptions operator&(CLRConfig::LookupOptions lhs, CLRConfig::LookupOptions rhs)
{
return static_cast<CLRConfig::LookupOptions>(static_cast<DWORD>(lhs) & static_cast<DWORD>(rhs));
}

typedef Wrapper<LPWSTR, DoNothing, CLRConfig::FreeConfigString, NULL> CLRConfigStringHolder;

#endif //__CLRConfig_h__
367 changes: 178 additions & 189 deletions src/coreclr/inc/clrconfigvalues.h

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions src/coreclr/inc/corhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
#ifndef __CORHDR_H__
#define __CORHDR_H__

#define FRAMEWORK_REGISTRY_KEY "Software\\Microsoft\\.NETFramework"
#define FRAMEWORK_REGISTRY_KEY_W W("Software\\Microsoft\\.NETFramework")

// keys for HKCU
#ifdef HOST_64BIT
#define USER_FRAMEWORK_REGISTRY_KEY "Software\\Microsoft\\.NETFramework64"
#define USER_FRAMEWORK_REGISTRY_KEY_W W("Software\\Microsoft\\.NETFramework64")
#else
#define USER_FRAMEWORK_REGISTRY_KEY "Software\\Microsoft\\.NETFramework"
#define USER_FRAMEWORK_REGISTRY_KEY_W W("Software\\Microsoft\\.NETFramework")
#endif

#include <stdint.h>

#ifdef _MSC_VER
Expand Down
132 changes: 3 additions & 129 deletions src/coreclr/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,134 +1010,6 @@ void SplitPath(__in SString const &path,
__inout_opt SString *fname,
__inout_opt SString *ext);

#if !defined(NO_CLRCONFIG)

//*****************************************************************************
//
// **** REGUTIL - Static helper functions for reading/writing to Windows registry.
//
//*****************************************************************************


class REGUTIL
{
public:
//*****************************************************************************

enum CORConfigLevel
{
COR_CONFIG_ENV = 0x01,
COR_CONFIG_USER = 0x02,
COR_CONFIG_MACHINE = 0x04,

COR_CONFIG_REGISTRY = (COR_CONFIG_USER|COR_CONFIG_MACHINE),
COR_CONFIG_ALL = (COR_CONFIG_ENV|COR_CONFIG_USER|COR_CONFIG_MACHINE),
};

//
// NOTE: The following function is deprecated; use the CLRConfig class instead.
// To access a configuration value through CLRConfig, add an entry in file:../inc/CLRConfigValues.h.
//
static DWORD GetConfigDWORD_DontUse_(
LPCWSTR name,
DWORD defValue,
CORConfigLevel level = COR_CONFIG_ALL,
BOOL fPrependCOMPLUS = TRUE);

//
// NOTE: The following function is deprecated; use the CLRConfig class instead.
// To access a configuration value through CLRConfig, add an entry in file:../inc/CLRConfigValues.h.
//
static HRESULT GetConfigDWORD_DontUse_(
LPCWSTR name,
DWORD defValue,
__out DWORD * result,
CORConfigLevel level = COR_CONFIG_ALL,
BOOL fPrependCOMPLUS = TRUE);

static ULONGLONG GetConfigULONGLONG_DontUse_(
LPCWSTR name,
ULONGLONG defValue,
CORConfigLevel level = COR_CONFIG_ALL,
BOOL fPrependCOMPLUS = TRUE);

//
// NOTE: The following function is deprecated; use the CLRConfig class instead.
// To access a configuration value through CLRConfig, add an entry in file:../inc/CLRConfigValues.h.
//
static DWORD GetConfigFlag_DontUse_(
LPCWSTR name,
DWORD bitToSet,
BOOL defValue = FALSE);

//
// NOTE: The following function is deprecated; use the CLRConfig class instead.
// To access a configuration value through CLRConfig, add an entry in file:../inc/CLRConfigValues.h.
//
static LPWSTR GetConfigString_DontUse_(
LPCWSTR name,
BOOL fPrependCOMPLUS = TRUE,
CORConfigLevel level = COR_CONFIG_ALL,
BOOL fUsePerfCache = TRUE);

static void FreeConfigString(__in __in_z LPWSTR name);

private:
static LPWSTR EnvGetString(LPCWSTR name, BOOL fPrependCOMPLUS);

private:
//*****************************************************************************
// Get either a DWORD or ULONGLONG. Always puts the result in a ULONGLONG that
// you can safely cast to a DWORD if fGetDWORD is TRUE.
//*****************************************************************************
static HRESULT GetConfigInteger(
LPCWSTR name,
ULONGLONG defValue,
__out ULONGLONG * result,
BOOL fGetDWORD = TRUE,
CORConfigLevel level = COR_CONFIG_ALL,
BOOL fPrependCOMPLUS = TRUE);
public:


//*****************************************************************************
// (Optional) Initialize the config registry cache
// (see ConfigCacheValueNameSeenPerhaps, below.)
//*****************************************************************************
static void InitOptionalConfigCache();

private:


//*****************************************************************************
// Return TRUE if the registry value name might have been seen in the registry
// at startup;
// return FALSE if the value was definitely not seen at startup.
//
// Perf Optimization for VSWhidbey:113373.
//*****************************************************************************
static BOOL RegCacheValueNameSeenPerhaps(
LPCWSTR name);
//*****************************************************************************
// Return TRUE if the environment variable name might have been seen at startup;
// return FALSE if the value was definitely not seen at startup.
//*****************************************************************************
static BOOL EnvCacheValueNameSeenPerhaps(
LPCWSTR name);

static BOOL s_fUseRegCache; // Enable registry cache; if FALSE, CCVNSP
// always returns TRUE.
static BOOL s_fUseEnvCache; // Enable env cache.

// Open the .NetFramework keys once and cache the handles
static HKEY s_hMachineFrameworkKey;
static HKEY s_hUserFrameworkKey;
};

#include "clrconfig.h"

#endif // defined(NO_CLRCONFIG)

#include "ostype.h"

#define CLRGetTickCount64() GetTickCount64()
Expand Down Expand Up @@ -3743,8 +3615,10 @@ class MethodNamesList : public MethodNamesListBase

#if !defined(NO_CLRCONFIG)
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

#include "clrconfig.h"

/**************************************************************************/
/* simple wrappers around the REGUTIL and MethodNameList routines that make
/* simple wrappers around the CLRConfig and MethodNameList routines that make
the lookup lazy */

/* to be used as static variable - no constructor/destructor, assumes zero
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/md/debug_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#pragma once

// Include for REGUTIL class used in Debug_ReportError
// Include for CLRConfig class used in Debug_ReportError
#include <utilcode.h>

// --------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/utilcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ set(UTILCODE_COMMON_SOURCES
corimage.cpp
format1.cpp
prettyprintsig.cpp
regutil.cpp
sha1.cpp
sigbuilder.cpp
sigparser.cpp
Expand Down
Loading