diff options
author | danmosemsft <danmose@microsoft.com> | 2017-02-10 17:12:53 -0800 |
---|---|---|
committer | danmosemsft <danmose@microsoft.com> | 2017-02-10 21:36:06 -0800 |
commit | 54891e0650e69f08832f75a40dc102efc6115d38 (patch) | |
tree | 0e032a0b337767801f696cbaeacded267c694f32 /src/utilcode | |
parent | 396f7d43b3c0f3ca7034a6d1d9cd7d6914778a1e (diff) | |
download | coreclr-54891e0650e69f08832f75a40dc102efc6115d38.tar.gz coreclr-54891e0650e69f08832f75a40dc102efc6115d38.tar.bz2 coreclr-54891e0650e69f08832f75a40dc102efc6115d38.zip |
Remove always defined FEATURE_CORECLR
Diffstat (limited to 'src/utilcode')
-rw-r--r-- | src/utilcode/appxutil.cpp | 820 | ||||
-rw-r--r-- | src/utilcode/ccomprc.cpp | 83 | ||||
-rw-r--r-- | src/utilcode/clrhost.cpp | 6 | ||||
-rw-r--r-- | src/utilcode/dlwrap.cpp | 152 | ||||
-rw-r--r-- | src/utilcode/ex.cpp | 4 | ||||
-rw-r--r-- | src/utilcode/longfilepathwrappers.cpp | 2 | ||||
-rw-r--r-- | src/utilcode/makepath.cpp | 203 | ||||
-rw-r--r-- | src/utilcode/newapis.cpp | 45 | ||||
-rw-r--r-- | src/utilcode/pedecoder.cpp | 67 | ||||
-rw-r--r-- | src/utilcode/registrywrapper.cpp | 285 | ||||
-rw-r--r-- | src/utilcode/regutil.cpp | 697 | ||||
-rw-r--r-- | src/utilcode/sortversioning.cpp | 244 | ||||
-rw-r--r-- | src/utilcode/stacktrace.cpp | 2 | ||||
-rw-r--r-- | src/utilcode/stresslog.cpp | 27 | ||||
-rw-r--r-- | src/utilcode/util.cpp | 212 | ||||
-rw-r--r-- | src/utilcode/utilmessagebox.cpp | 26 |
16 files changed, 3 insertions, 2872 deletions
diff --git a/src/utilcode/appxutil.cpp b/src/utilcode/appxutil.cpp index 759fbffcb1..5d095a4873 100644 --- a/src/utilcode/appxutil.cpp +++ b/src/utilcode/appxutil.cpp @@ -19,7 +19,6 @@ #include "shlwapi.h" // Path manipulation APIs -#ifdef FEATURE_CORECLR GVAL_IMPL(bool, g_fAppX); INDEBUG(bool g_fIsAppXAsked;) @@ -49,822 +48,3 @@ namespace AppX #endif }; -#else // FEATURE_CORECLR - -//--------------------------------------------------------------------------------------------- -// Convenience values - -#ifndef E_INSUFFICIENT_BUFFER - #define E_INSUFFICIENT_BUFFER (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) -#endif - -#ifndef E_FILE_NOT_FOUND - #define E_FILE_NOT_FOUND (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) -#endif - -//--------------------------------------------------------------------------------------------- -using clr::str::IsNullOrEmpty; - -//--------------------------------------------------------------------------------------------- -typedef decltype(GetCurrentPackageId) GetCurrentPackageId_t; -typedef decltype(GetCurrentPackageInfo) GetCurrentPackageInfo_t; -typedef decltype(GetCurrentPackagePath) GetCurrentPackagePath_t; -typedef decltype(OpenPackageInfoByFullName) OpenPackageInfoByFullName_t; -typedef decltype(ClosePackageInfo) ClosePackageInfo_t; -typedef decltype(GetPackageInfo) GetPackageInfo_t; - -//--------------------------------------------------------------------------------------------- -// Caches AppX ARI API-related information. -struct AppXRTInfo -{ - HMODULE m_hAppXRTMod; - bool m_fIsAppXProcess; - bool m_fIsAppXAdaptiveApp; - bool m_fIsAppXNGen; - - GetCurrentPackageId_t * m_pfnGetCurrentPackageId; - GetCurrentPackageInfo_t * m_pfnGetCurrentPackageInfo; - GetCurrentPackagePath_t * m_pfnGetCurrentPackagePath; - - NewArrayHolder<BYTE> m_pbAppContainerInfo; - DWORD m_cbAppContainerInfo; - - struct CurrentPackageInfo - { - UINT32 m_cbCurrentPackageInfo; - PBYTE m_pbCurrentPackageInfo; - UINT32 m_nCount; - - CurrentPackageInfo(UINT32 cbPkgInfo, PBYTE pbPkgInfo, UINT32 nCount) - : m_cbCurrentPackageInfo(cbPkgInfo) - , m_pbCurrentPackageInfo(pbPkgInfo) - , m_nCount(nCount) - { LIMITED_METHOD_CONTRACT; } - - ~CurrentPackageInfo() - { - LIMITED_METHOD_CONTRACT; - if (m_pbCurrentPackageInfo != nullptr) - { - delete [] m_pbCurrentPackageInfo; - m_pbCurrentPackageInfo = nullptr; - } - } - }; - - CurrentPackageInfo * m_pCurrentPackageInfo; - - NewArrayHolder<WCHAR> m_AdaptiveAppWinmetadataDir; - - AppXRTInfo() : - m_hAppXRTMod(nullptr), - m_fIsAppXProcess(false), - m_fIsAppXAdaptiveApp(false), - m_fIsAppXNGen(false), - m_pfnGetCurrentPackageId(nullptr), - m_pfnGetCurrentPackageInfo(nullptr), - m_pfnGetCurrentPackagePath(nullptr), - m_pbAppContainerInfo(nullptr), - m_pCurrentPackageInfo(nullptr), - m_AdaptiveAppWinmetadataDir(nullptr) - { LIMITED_METHOD_CONTRACT; } - - ~AppXRTInfo() - { - LIMITED_METHOD_CONTRACT; - if (m_pCurrentPackageInfo != nullptr) - { - delete m_pCurrentPackageInfo; - m_pCurrentPackageInfo = nullptr; - } - - if (m_hAppXRTMod != nullptr) - { - FreeLibrary(m_hAppXRTMod); - m_hAppXRTMod = nullptr; - } - } -}; // struct AppXRTInfo - -GPTR_IMPL(AppXRTInfo, g_pAppXRTInfo); // Relies on zero init static memory. - -#ifndef DACCESS_COMPILE - -//--------------------------------------------------------------------------------------------- -static -HRESULT GetAppContainerTokenInfoForProcess( - DWORD pid, - NewArrayHolder<BYTE>& pbAppContainerTokenInfo, - DWORD* pcbAppContainerTokenInfo) -{ - PRECONDITION(CheckPointer(pcbAppContainerTokenInfo, NULL_OK)); - - HRESULT hr = S_OK; - - pbAppContainerTokenInfo = nullptr; - - // In order to get the AppContainer SID we need to open the process token - HandleHolder hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); - if (hProcess == NULL) - return HRESULT_FROM_GetLastError(); - - HandleHolder hToken; - if (!OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) - return HRESULT_FROM_GetLastError(); - - // Query the process to see if it's inside an AppContainer - ULONG isAppContainer = 0; - DWORD actualLength = 0; - if (!GetTokenInformation(hToken, static_cast<TOKEN_INFORMATION_CLASS>(TokenIsAppContainer), &isAppContainer, sizeof(isAppContainer), &actualLength)) - return HRESULT_FROM_GetLastError(); - - _ASSERTE(actualLength > 0); - - // Not an AppContainer so bail - if (!isAppContainer) - { - return S_FALSE; - } - - // Now we need the AppContainer SID so first get the required buffer length - actualLength = 0; - VERIFY(!GetTokenInformation(hToken, static_cast<TOKEN_INFORMATION_CLASS>(TokenAppContainerSid), NULL, 0, &actualLength)); - hr = HRESULT_FROM_GetLastError(); - _ASSERTE(hr == E_INSUFFICIENT_BUFFER); - - // Something unexpected happened - if (hr != E_INSUFFICIENT_BUFFER) - return hr; - - // Now we know the length of the AppContainer SID so create a buffer and retrieve it - pbAppContainerTokenInfo = new (nothrow) BYTE[actualLength]; - IfNullRet(pbAppContainerTokenInfo); - - if (!GetTokenInformation(hToken, static_cast<TOKEN_INFORMATION_CLASS>(TokenAppContainerSid), pbAppContainerTokenInfo.GetValue(), actualLength, &actualLength)) - return HRESULT_FROM_GetLastError(); - - if (pcbAppContainerTokenInfo != nullptr) - *pcbAppContainerTokenInfo = actualLength; - - return S_OK; -} - -//--------------------------------------------------------------------------------------------- -// Initializes a global AppXRTInfo structure if it has not already been initialized. Returns -// false only in the event of OOM; otherwise caches the result of ARI information in -// g_pAppXRTInfo. Thread safe. -static -HRESULT InitAppXRT() -{ - // This will be used for catastrophic errors. - HRESULT hr = S_OK; - - if (VolatileLoad(&g_pAppXRTInfo) == nullptr) - { - NewHolder<AppXRTInfo> pAppXRTInfo = new (nothrow) AppXRTInfo(); - IfNullRet(pAppXRTInfo); // Catastrophic error. - - pAppXRTInfo->m_fIsAppXProcess = false; - - do - { - if (!RunningOnWin8()) - { - break; - } - - LPCWSTR wzAppXRTDll = W("api-ms-win-appmodel-runtime-l1-1-0.dll"); - // Does not use GetLoadWithAlteredSearchPathFlag() because that would cause infinite recursion. - pAppXRTInfo->m_hAppXRTMod = WszLoadLibraryEx(wzAppXRTDll, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (pAppXRTInfo->m_hAppXRTMod == nullptr) - { // Error is catastrophic: can't find kernel32.dll? - hr = HRESULT_FROM_GetLastError(); - break; - } - - pAppXRTInfo->m_pfnGetCurrentPackageId = reinterpret_cast<GetCurrentPackageId_t *>( - GetProcAddress(pAppXRTInfo->m_hAppXRTMod, "GetCurrentPackageId")); - if (pAppXRTInfo->m_pfnGetCurrentPackageId == nullptr) - { // Error is non-catastrophic: could be running downlevel - break; - } - - pAppXRTInfo->m_pfnGetCurrentPackageInfo = reinterpret_cast<GetCurrentPackageInfo_t *>( - GetProcAddress(pAppXRTInfo->m_hAppXRTMod, "GetCurrentPackageInfo")); - if (pAppXRTInfo->m_pfnGetCurrentPackageInfo == nullptr) - { // Error is catastrophic: GetCurrentPackageId is available but not GetCurrentPackageInfo? - hr = HRESULT_FROM_GetLastError(); - break; - } - - pAppXRTInfo->m_pfnGetCurrentPackagePath = reinterpret_cast<GetCurrentPackagePath_t *>( - GetProcAddress(pAppXRTInfo->m_hAppXRTMod, "GetCurrentPackagePath")); - if (pAppXRTInfo->m_pfnGetCurrentPackagePath == nullptr) - { // Error is catastrophic: GetCurrentPackageInfo is available but not GetCurrentPackagePath? - hr = HRESULT_FROM_GetLastError(); - break; - } - - // Determine if this is an AppX process - UINT32 cbBuffer = 0; - LONG lRes = (*pAppXRTInfo->m_pfnGetCurrentPackageId)(&cbBuffer, nullptr); - pAppXRTInfo->m_fIsAppXProcess = (lRes == ERROR_INSUFFICIENT_BUFFER); - - _ASSERTE(AppX::IsAppXSupported()); - - hr = GetAppContainerTokenInfoForProcess( - GetCurrentProcessId(), - pAppXRTInfo->m_pbAppContainerInfo, - &pAppXRTInfo->m_cbAppContainerInfo); - - if (FAILED(hr)) - { - if (pAppXRTInfo->m_fIsAppXProcess) - { // Error is catastrophic: running in true immersive process but no token info? - } - else - { // Error is non-catastrophic: reset HRESULT to S_OK. - hr = S_OK; - } - break; - } - } - while (false); - - if (InterlockedCompareExchangeT<AppXRTInfo>(&g_pAppXRTInfo, pAppXRTInfo, nullptr) == nullptr) - { - pAppXRTInfo.SuppressRelease(); - } - } - - return hr; -} - -//--------------------------------------------------------------------------------------------- -// Inline helper to check first an only init when required. -static inline HRESULT CheckInitAppXRT() -{ - return (VolatileLoad(&g_pAppXRTInfo) != nullptr) ? S_OK : InitAppXRT(); -} - -#endif // !DACCESS_COMPILE - -//--------------------------------------------------------------------------------------------- -// Contains general helper methods for interacting with AppX functionality. This code will -// gracefully fail on downlevel OS by returning false from AppX::IsAppXProcess, so always -// call this API first to check before calling any of the others defined in this namespace. -// -// See http://windows/windows8/docs/Windows%208%20Feature%20Documents/Developer%20Experience%20(DEVX)/Apps%20Experience%20(APPX)/Modern%20Client/App%20Runtime%20Improvements%20API%20Developer%20Platform%20Spec.docm -// for more information. - -namespace AppX -{ -#ifdef DACCESS_COMPILE - - //----------------------------------------------------------------------------------------- - // DAC-only IsAppXProcess. Returns false if g_pAppXRTInfo has not been initialized. - bool DacIsAppXProcess() - { - LIMITED_METHOD_DAC_CONTRACT; - return (g_pAppXRTInfo != nullptr && g_pAppXRTInfo->m_fIsAppXProcess); - } - -#else // DACCESS_COMPILE - - //--------------------------------------------------------------------------------------------- - // cleans up resources allocated in InitAppXRT() - void ShutDown() - { - if (VolatileLoad(&g_pAppXRTInfo) != nullptr) - { - delete g_pAppXRTInfo; - g_pAppXRTInfo = nullptr; - } - } - - //----------------------------------------------------------------------------------------- - // Returns true if the current process is immersive. - // NOTE: a return value of true doesn't necessarily indicate that the process is a - // real Metro app, e.g. it could be an ngen process compiling an AppX assembly. - bool IsAppXProcess() - { - LIMITED_METHOD_CONTRACT; - HRESULT hr = S_OK; - - if (FAILED(hr = CheckInitAppXRT())) - { - SetLastError(hr); // HRESULT_FROM_WIN32 is idempotent when error value is HRESULT. - return false; - } - - return g_pAppXRTInfo->m_fIsAppXProcess; - } - - //----------------------------------------------------------------------------------------- - // Returns true if the current process is immersive. - // Only produces reliable results after IsAppXProcess is inititalized - bool IsAppXProcess_Initialized_NoFault() - { - LIMITED_METHOD_CONTRACT; - if (VolatileLoad(&g_pAppXRTInfo) == nullptr) - { - return false; - } - return g_pAppXRTInfo->m_fIsAppXProcess; - } - - bool IsAppXNGen() - { - LIMITED_METHOD_CONTRACT; - return VolatileLoad(&g_pAppXRTInfo) != nullptr && g_pAppXRTInfo->m_fIsAppXNGen; - } - - //----------------------------------------------------------------------------------------- - HRESULT InitCurrentPackageInfoCache() - { - LIMITED_METHOD_CONTRACT; - HRESULT hr = S_OK; - - UINT32 cbBuffer = 0; - hr = HRESULT_FROM_WIN32((*g_pAppXRTInfo->m_pfnGetCurrentPackageInfo)(PACKAGE_FILTER_CLR_DEFAULT, &cbBuffer, nullptr, nullptr)); - if (hr != E_INSUFFICIENT_BUFFER) - return hr; - - NewArrayHolder<BYTE> pbBuffer(new (nothrow) BYTE[cbBuffer]); - IfNullRet(pbBuffer); - - UINT32 nCount = 0; - IfFailRet(HRESULT_FROM_WIN32((*g_pAppXRTInfo->m_pfnGetCurrentPackageInfo)(PACKAGE_FILTER_CLR_DEFAULT, &cbBuffer, pbBuffer, &nCount))); - - NewHolder<AppXRTInfo::CurrentPackageInfo> pPkgInfo( - new (nothrow) AppXRTInfo::CurrentPackageInfo(cbBuffer, pbBuffer.Extract(), nCount)); - IfNullRet(pPkgInfo); - - if (InterlockedCompareExchangeT<AppXRTInfo::CurrentPackageInfo>( - &g_pAppXRTInfo->m_pCurrentPackageInfo, pPkgInfo, nullptr) == nullptr) - { - pPkgInfo.SuppressRelease(); - } - - return S_OK; - } - - //----------------------------------------------------------------------------------------- - FORCEINLINE HRESULT CheckInitCurrentPackageInfoCache() - { - WRAPPER_NO_CONTRACT; - PRECONDITION(IsAppXProcess()); - - if (!IsAppXProcess()) - return E_UNEXPECTED; - - if (g_pAppXRTInfo->m_pCurrentPackageInfo == nullptr) - return InitCurrentPackageInfoCache(); - else - return S_OK; - } - - //----------------------------------------------------------------------------------------- - LPCWSTR GetHeadPackageMoniker() - { - STANDARD_VM_CONTRACT; - - IfFailThrow(CheckInitCurrentPackageInfoCache()); - return reinterpret_cast<PPACKAGE_INFO>( - g_pAppXRTInfo->m_pCurrentPackageInfo->m_pbCurrentPackageInfo)->packageFullName; - } - - //----------------------------------------------------------------------------------------- - // Returns the current process' PACKAGE_ID in the provided buffer. See the ARI spec (above) - // for more information. - HRESULT GetCurrentPackageId( - PUINT32 pBufferLength, - PBYTE pBuffer) - { - LIMITED_METHOD_CONTRACT; - HRESULT hr = S_OK; - - IfFailRet(CheckInitAppXRT()); - IfFailRet(HRESULT_FROM_WIN32((*g_pAppXRTInfo->m_pfnGetCurrentPackageId)(pBufferLength, pBuffer))); - - return S_OK; - } - - //----------------------------------------------------------------------------------------- - // Returns the current process' PACKAGE_INFO in the provided buffer. See the ARI spec - // (above) for more information. - HRESULT GetCurrentPackageInfo( - UINT32 uiFlags, - PUINT32 pcbBuffer, - PBYTE pbBuffer, - PUINT32 pnCount) - { - LIMITED_METHOD_CONTRACT; - PRECONDITION(IsAppXProcess()); - PRECONDITION(CheckPointer(pcbBuffer)); - - HRESULT hr = S_OK; - - IfFailRet(CheckInitAppXRT()); - - if (pcbBuffer == nullptr) - return E_INVALIDARG; - - if (uiFlags == PACKAGE_FILTER_CLR_DEFAULT) - { - IfFailRet(CheckInitCurrentPackageInfoCache()); - - DWORD cbBuffer = *pcbBuffer; - *pcbBuffer = g_pAppXRTInfo->m_pCurrentPackageInfo->m_cbCurrentPackageInfo; - if (pnCount != nullptr) - { - *pnCount = g_pAppXRTInfo->m_pCurrentPackageInfo->m_nCount; - } - - if (pbBuffer == nullptr || cbBuffer < g_pAppXRTInfo->m_pCurrentPackageInfo->m_cbCurrentPackageInfo) - { - return E_INSUFFICIENT_BUFFER; - } - memcpy(pbBuffer, g_pAppXRTInfo->m_pCurrentPackageInfo->m_pbCurrentPackageInfo, g_pAppXRTInfo->m_pCurrentPackageInfo->m_cbCurrentPackageInfo); - } - else - { - IfFailRet(HRESULT_FROM_WIN32((*g_pAppXRTInfo->m_pfnGetCurrentPackageInfo)(uiFlags, pcbBuffer, pbBuffer, pnCount))); - } - - return S_OK; - } - - //----------------------------------------------------------------------------------------- - bool IsAdaptiveApp() - { - LIMITED_METHOD_CONTRACT; - - HRESULT hr = S_OK; - static bool cachedIsAdaptiveApp = false; - - if (!IsAppXProcess()) - { - return false; - } - - if (!cachedIsAdaptiveApp) - { - cachedIsAdaptiveApp = true; - LPWSTR adaptiveAppWinmetaDataDir = NULL; - - if (SUCCEEDED(hr = AppX::GetWinMetadataDirForAdaptiveApps(&adaptiveAppWinmetaDataDir))) - { - g_pAppXRTInfo->m_fIsAppXAdaptiveApp = clr::fs::Dir::Exists(adaptiveAppWinmetaDataDir); - - } - else - { - SetLastError(hr); - g_pAppXRTInfo->m_fIsAppXAdaptiveApp = false; - } - - } - - return g_pAppXRTInfo->m_fIsAppXAdaptiveApp; - } - - - //----------------------------------------------------------------------------------------- - // length : Upon success, contains the the length of packagePath - // [in/out] - // - // packageRoot : Upon success, contains the full packagePath - // [out] [ Note: The memory has to be preallocated for the above length] - // - HRESULT GetCurrentPackagePath(_Inout_ UINT32* length, _Out_opt_ PWSTR packageRoot) - { - PRECONDITION(IsAppXProcess()); - PRECONDITION(CheckPointer(length)); - - HRESULT hr; - IfFailRet(CheckInitAppXRT()); - - IfFailRet(HRESULT_FROM_WIN32((*g_pAppXRTInfo->m_pfnGetCurrentPackagePath)(length, packageRoot))); - return S_OK; - } - - //----------------------------------------------------------------------------------------- - // winMetadDataDir : Upon success, contains the absolute path for the winmetadata directory for the adaptive app - // [out] NOTE: The string the pointer points to is global memory and never should be modified - // - HRESULT GetWinMetadataDirForAdaptiveApps(_Out_ LPWSTR* winMetadDataDir) - { - - PRECONDITION(IsAppXProcess()); - - HRESULT hr; - - IfFailRet(CheckInitAppXRT()); - - if (g_pAppXRTInfo->m_AdaptiveAppWinmetadataDir == nullptr) - { - LPCWSTR wzWinMetadataFolder=W("\\WinMetadata"); - NewArrayHolder<WCHAR> wzCompletePath; - UINT32 length=0; - - hr = GetCurrentPackagePath(&length, NULL); - if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) - return hr; - - NewArrayHolder<WCHAR> wzPath_holder = new (nothrow) WCHAR[length]; - - IfNullRet(wzPath_holder); - IfFailRet(GetCurrentPackagePath(&length, wzPath_holder.GetValue())); - - DWORD cchFullPathBuf = length + (DWORD)wcslen(wzWinMetadataFolder) + 1; - IfNullRet(wzCompletePath = new (nothrow) WCHAR[cchFullPathBuf]); - IfFailRet(clr::fs::Path::Combine(wzPath_holder.GetValue(), wzWinMetadataFolder, &cchFullPathBuf, wzCompletePath.GetValue())); - g_pAppXRTInfo->m_AdaptiveAppWinmetadataDir = wzCompletePath.Extract(); - } - - *winMetadDataDir = g_pAppXRTInfo->m_AdaptiveAppWinmetadataDir; - - return S_OK; - } - -#if defined(FEATURE_APPX_BINDER) - //----------------------------------------------------------------------------------------- - // Iterates the current process' packages and returns the first package that contains a - // file matching wzFileName. - // - // wzFileName : The file to look for in the current process' packages. If this is a - // [in] relative path, then it appends the path to the root of each package in - // sequence to see if the resulting path points to an existing file. If this - // is an absolute path, then for each package it determines if the package - // root is a prefix of wzFileName. - // pcchPathName : Upon entry contains the length of the buffer pwzPathName, and upon return - // [in/out] contains either the number of characters written or the buffer size - // required. - // pwzPathName : Upon success, contains the absolute path for the first matching file. - // [out] - HRESULT FindFileInCurrentPackage( - PCWSTR wzFileName, - PUINT32 pcchPathName, - PWSTR pwzPathName, - UINT32 uiFlags, - __in PCWSTR *rgwzAltPaths, - __in UINT32 cAltPaths, - FindFindInPackageFlags findInCurrentPackageFlags) - { - LIMITED_METHOD_CONTRACT; - PRECONDITION(IsAppXProcess()); - PRECONDITION(CheckPointer(wzFileName)); - PRECONDITION(CheckPointer(pcchPathName)); - PRECONDITION(CheckPointer(pwzPathName)); - - HRESULT hr = S_OK; - - if (!IsAppXProcess()) - return E_UNEXPECTED; - - // PACKAGE_FILTER_ALL_LOADED is obsolete, and shouldn't be used. - // We also don't currently handle the case where PACKAGE_FILTER_HEAD isn't set. - _ASSERTE(uiFlags != PACKAGE_FILTER_ALL_LOADED && (uiFlags & PACKAGE_FILTER_HEAD) != 0); - if (uiFlags == PACKAGE_FILTER_ALL_LOADED || (uiFlags & PACKAGE_FILTER_HEAD) == 0) - return E_NOTIMPL; - - // File name must be non-null and relative - if (IsNullOrEmpty(wzFileName) || pcchPathName == nullptr || pwzPathName == nullptr) - return E_INVALIDARG; - - // If we've been provided a full path and the file doesn't actually exist - // then we can immediately say that this function will fail with "file not found". - bool fIsRelative = clr::fs::Path::IsRelative(wzFileName); - if (!fIsRelative && !clr::fs::File::Exists(wzFileName)) - return E_FILE_NOT_FOUND; - - IfFailRet(CheckInitCurrentPackageInfoCache()); - - DWORD const cchFileName = static_cast<DWORD>(wcslen(wzFileName)); - DWORD cchFullPathBuf = _MAX_PATH; - NewArrayHolder<WCHAR> wzFullPathBuf = new (nothrow) WCHAR[cchFullPathBuf]; - IfNullRet(wzFullPathBuf); - - auto FindFileInCurrentPackageHelper = [&](LPCWSTR wzPath) -> HRESULT - { - HRESULT hr = S_OK; - - if (!(findInCurrentPackageFlags & FindFindInPackageFlags_AllowLongFormatPath) && clr::fs::Path::HasLongFormatPrefix(wzPath)) - return COR_E_BAD_PATHNAME; // We can't handle long format paths. - - // If the path is relative, concatenate the package root and the file name and see - // if the file exists. - if (fIsRelative) - { - DWORD cchFullPath = cchFullPathBuf; - hr = clr::fs::Path::Combine(wzPath, wzFileName, &cchFullPath, wzFullPathBuf); - if (hr == E_INSUFFICIENT_BUFFER) - { - IfNullRet(wzFullPathBuf = new (nothrow) WCHAR[cchFullPathBuf = (cchFullPath + 1)]); - hr = clr::fs::Path::Combine(wzPath, wzFileName, &cchFullPath, wzFullPathBuf); - } - IfFailRet(hr); - - if (!clr::fs::Path::IsValid(wzFullPathBuf, cchFullPath, !!(findInCurrentPackageFlags & FindFindInPackageFlags_AllowLongFormatPath))) - return COR_E_BAD_PATHNAME; - - if (clr::fs::File::Exists(wzFullPathBuf)) - { - DWORD cchPathName = *pcchPathName; - *pcchPathName = cchFullPath; - return StringCchCopy(pwzPathName, cchPathName, wzFullPathBuf); - } - } - // If the path is absolute, see if the file name contains the pacakge root as a prefix - // and if the file exists. - else - { - DWORD cchPath = static_cast<DWORD>(wcslen(wzPath)); - - // Determine if wzPath is a path prefix of wzFileName - if (cchPath < cchFileName && - _wcsnicmp(wzPath, wzFileName, cchPath) == 0 && - (wzFileName[cchPath] == W('\\') || wzPath[cchPath-1] == W('\\'))) // Ensure wzPath is not just a prefix, but a path prefix - { - if (clr::fs::File::Exists(wzFileName)) - { - DWORD cchPathName = *pcchPathName; - *pcchPathName = cchFileName; - return StringCchCopy(pwzPathName, cchPathName, wzFileName); - } - } - } - - return S_FALSE; - }; // FindFileInCurrentPackageHelper - - if (!(findInCurrentPackageFlags & FindFindInPackageFlags_SkipCurrentPackageGraph)) - { - PCPACKAGE_INFO pCurNode = reinterpret_cast<PPACKAGE_INFO>( - g_pAppXRTInfo->m_pCurrentPackageInfo->m_pbCurrentPackageInfo); - PCPACKAGE_INFO pEndNode = pCurNode + g_pAppXRTInfo->m_pCurrentPackageInfo->m_nCount; - for (; pCurNode != pEndNode; ++pCurNode) - { - IfFailRet(FindFileInCurrentPackageHelper(pCurNode->path)); - - if (hr == S_OK) - { - return hr; - } - - // End search if dependent packages should not be checked. - if ((uiFlags & PACKAGE_FILTER_DIRECT) == 0) - { - break; - } - } - } - - // Process alternative paths - for (UINT iAltPath = 0; iAltPath < cAltPaths; iAltPath++) - { - IfFailRet(FindFileInCurrentPackageHelper(rgwzAltPaths[iAltPath])); - - if (hr == S_OK) - { - return hr; - } - } - - return E_FILE_NOT_FOUND; - } -#endif // FEATURE_APPX_BINDER - - //----------------------------------------------------------------------------------------- - HRESULT GetAppContainerTokenInfoForProcess( - DWORD dwPid, - NewArrayHolder<BYTE>& pbAppContainerTokenInfo, - DWORD* pcbAppContainerTokenInfo) - { - LIMITED_METHOD_CONTRACT; - - HRESULT hr = S_OK; - - pbAppContainerTokenInfo = nullptr; - - if (!IsAppXSupported()) - { - return S_FALSE; - } - - if (dwPid == GetCurrentProcessId()) - { - if (FAILED(hr = CheckInitAppXRT())) - { - SetLastError(hr); - return S_FALSE; - } - - if (g_pAppXRTInfo->m_pbAppContainerInfo == nullptr) - { - return S_FALSE; - } - else - { - pbAppContainerTokenInfo = g_pAppXRTInfo->m_pbAppContainerInfo.GetValue(); - pbAppContainerTokenInfo.SuppressRelease(); // Caller does not need to free mem. - if (pcbAppContainerTokenInfo != nullptr) - { - *pcbAppContainerTokenInfo = g_pAppXRTInfo->m_cbAppContainerInfo; - } - return S_OK; - } - } - else - { - return ::GetAppContainerTokenInfoForProcess(dwPid, pbAppContainerTokenInfo, pcbAppContainerTokenInfo); - } - } - - // Called during NGen to pretend that we're in a certain package. Due to Windows restriction, we can't - // start NGen worker processes in the right package environment (only in the right AppContainer). So - // NGen calls this function with a package name, to indicate that all AppX-related code should behave as - // if the current process is running in that package. - HRESULT SetCurrentPackageForNGen(__in PCWSTR pszPackageFullName) - { - LIMITED_METHOD_CONTRACT; - - HRESULT hr = S_OK; - - IfFailRet(CheckInitAppXRT()); - - _ASSERTE(IsAppXSupported()); - _ASSERTE(g_pAppXRTInfo->m_hAppXRTMod != nullptr); - - HMODULE hAppXRTMod = g_pAppXRTInfo->m_hAppXRTMod; - OpenPackageInfoByFullName_t *pfnOpenPackageInfoByFullName - = reinterpret_cast<OpenPackageInfoByFullName_t*>(GetProcAddress(hAppXRTMod, "OpenPackageInfoByFullName")); - _ASSERTE(pfnOpenPackageInfoByFullName != nullptr); - if (pfnOpenPackageInfoByFullName == nullptr) - return HRESULT_FROM_GetLastError(); - - ClosePackageInfo_t *pfnClosePackageInfo - = reinterpret_cast<ClosePackageInfo_t*>(GetProcAddress(hAppXRTMod, "ClosePackageInfo")); - _ASSERTE(pfnClosePackageInfo != nullptr); - if (pfnClosePackageInfo == nullptr) - return HRESULT_FROM_GetLastError(); - - GetPackageInfo_t *pfnGetPackageInfo - = reinterpret_cast<GetPackageInfo_t*>(GetProcAddress(hAppXRTMod, "GetPackageInfo")); - _ASSERTE(pfnGetPackageInfo != nullptr); - if (pfnGetPackageInfo == nullptr) - return HRESULT_FROM_GetLastError(); - - PACKAGE_INFO_REFERENCE packageInfoReference; - hr = HRESULT_FROM_WIN32(pfnOpenPackageInfoByFullName(pszPackageFullName, 0, &packageInfoReference)); - if (FAILED(hr)) - return hr; - - // Automatically close packageInfoReference before we return. - class PackageInfoReferenceHolder - { - public: - PackageInfoReferenceHolder(ClosePackageInfo_t *pfnClosePackageInfo, PACKAGE_INFO_REFERENCE &packageInfoReference) - :m_pfnClosePackageInfo(pfnClosePackageInfo), - m_packageInfoReference(packageInfoReference) - { - } - ~PackageInfoReferenceHolder() { m_pfnClosePackageInfo(m_packageInfoReference); } - private: - ClosePackageInfo_t *m_pfnClosePackageInfo; - PACKAGE_INFO_REFERENCE &m_packageInfoReference; - } pirh(pfnClosePackageInfo, packageInfoReference); - - UINT32 cbBuffer = 0; - hr = HRESULT_FROM_WIN32(pfnGetPackageInfo(packageInfoReference, PACKAGE_FILTER_CLR_DEFAULT, &cbBuffer, nullptr, nullptr)); - if (hr != E_INSUFFICIENT_BUFFER) - return hr; - - NewArrayHolder<BYTE> pbBuffer(new (nothrow) BYTE[cbBuffer]); - IfNullRet(pbBuffer); - - UINT32 nCount = 0; - IfFailRet(HRESULT_FROM_WIN32(pfnGetPackageInfo(packageInfoReference, PACKAGE_FILTER_CLR_DEFAULT, &cbBuffer, pbBuffer, &nCount))); - - NewHolder<AppXRTInfo::CurrentPackageInfo> pPkgInfo( - new (nothrow) AppXRTInfo::CurrentPackageInfo(cbBuffer, pbBuffer.Extract(), nCount)); - IfNullRet(pPkgInfo); - - if (InterlockedCompareExchangeT<AppXRTInfo::CurrentPackageInfo>( - &g_pAppXRTInfo->m_pCurrentPackageInfo, pPkgInfo, nullptr) == nullptr) - { - pPkgInfo.SuppressRelease(); - } - - g_pAppXRTInfo->m_fIsAppXProcess = true; - g_pAppXRTInfo->m_fIsAppXNGen = true; - - return hr; - } - -#endif // DACCESS_COMPILE -} // namespace AppX - - -#endif // FEATURE_CORECLR diff --git a/src/utilcode/ccomprc.cpp b/src/utilcode/ccomprc.cpp index a4c79fc127..ed902dc6ca 100644 --- a/src/utilcode/ccomprc.cpp +++ b/src/utilcode/ccomprc.cpp @@ -261,12 +261,8 @@ HRESULT CCompRC::AddMapNode(LocaleID langId, HRESOURCEDLL hInst, BOOL fMissing) //***************************************************************************** // Initialize //***************************************************************************** -#ifndef FEATURE_CORECLR -LPCWSTR CCompRC::m_pDefaultResource = W("mscorrc.dll"); -#else // !FEATURE_CORECLR LPCWSTR CCompRC::m_pDefaultResource = W("mscorrc.debug.dll"); LPCWSTR CCompRC::m_pFallbackResource= W("mscorrc.dll"); -#endif // !FEATURE_CORECLR #ifdef FEATURE_PAL LPCSTR CCompRC::m_pDefaultResourceDomain = "mscorrc.debug"; @@ -482,7 +478,6 @@ CCompRC* CCompRC::GetDefaultResourceDll() return &m_DefaultResourceDll; } -#ifdef FEATURE_CORECLR LONG CCompRC::m_dwFallbackInitialized = 0; CCompRC CCompRC::m_FallbackResourceDll; @@ -510,7 +505,6 @@ CCompRC* CCompRC::GetFallbackResourceDll() return &m_FallbackResourceDll; } -#endif // FEATURE_CORECLR //***************************************************************************** @@ -747,7 +741,6 @@ HRESULT CCompRC::LoadString(ResourceCategory eCategory, LocaleID langId, UINT iR // Failed to load string if ( hr != E_OUTOFMEMORY && ShouldUseFallback()) { -#ifdef FEATURE_CORECLR CCompRC* pFallback=CCompRC::GetFallbackResourceDll(); if (pFallback) { @@ -761,13 +754,11 @@ HRESULT CCompRC::LoadString(ResourceCategory eCategory, LocaleID langId, UINT iR if(SUCCEEDED(hr)) return hr; } -#endif switch (eCategory) { case Optional: hr = E_FAIL; break; -#ifdef FEATURE_CORECLR case DesktopCLR: hr = E_FAIL; break; @@ -837,12 +828,6 @@ HRESULT CCompRC::LoadString(ResourceCategory eCategory, LocaleID langId, UINT iR // if we got here then we couldn't get the fallback message // the fallback message is required so just falling through into "Required" -#else // FEATURE_CORECLR - // everything that's not optional goes here for Desktop - case DesktopCLR: - case Debugging: - case Error: -#endif case Required: if ( hr != E_OUTOFMEMORY) @@ -1035,7 +1020,6 @@ HRESULT CCompRC::LoadLibraryThrows(HRESOURCEDLL * pHInst) PathString rcPath; // Path to resource DLL. // Try first in the same directory as this dll. -#if defined(FEATURE_CORECLR) VALIDATECORECLRCALLBACKS(); @@ -1046,73 +1030,6 @@ HRESULT CCompRC::LoadLibraryThrows(HRESOURCEDLL * pHInst) hr = LoadLibraryHelper(pHInst, rcPath); -#else // FEATURE_CORECLR - - if (!WszGetModuleFileName(GetModuleInst(), rcPath)) - return HRESULT_FROM_GetLastError(); - - CopySystemDirectory(rcPath, rcPath); - - hr = LoadLibraryHelper(pHInst, rcPath); - if (hr == E_OUTOFMEMORY) - return hr; - - // In case of default rc file, also try CORSystemDirectory. - // Note that GetRequestedRuntimeInfo is a function in ths shim. As of 12/06, this is the only - // place where utilcode appears to take a dependency on the shim. This forces everyone that links - // with us to also dynamically link to mscoree.dll. Perhaps this should be a delay-load to prevent - // that static dependency and have a gracefull fallback when the shim isn't installed. - // We don't do this in DAC builds because mscordacwks.dll cannot take a dependency on other CLR - // dlls (eg. you must be able to examine a managed dump on a machine without any CLR installed). -#ifndef DACCESS_COMPILE - if (FAILED(hr) && m_pResourceFile == m_pDefaultResource) - { -#ifdef SELF_NO_HOST - WCHAR rcVersion[MAX_VERSION_STRING]; - DWORD rcVersionSize; - - DWORD corSystemPathSize; - - // The reason for using GetRequestedRuntimeInfo is the ability to suppress message boxes - // with RUNTIME_INFO_DONT_SHOW_ERROR_DIALOG. - COUNT_T size = MAX_PATH; - hr = LegacyActivationShim::GetRequestedRuntimeInfo( - NULL, - W("v")VER_PRODUCTVERSION_NO_QFE_STR_L, - NULL, - 0, - RUNTIME_INFO_UPGRADE_VERSION|RUNTIME_INFO_DONT_SHOW_ERROR_DIALOG|RUNTIME_INFO_CONSIDER_POST_2_0, - rcPath.OpenUnicodeBuffer(size-1), - size, - &corSystemPathSize, - rcVersion, - NumItems(rcVersion), - &rcVersionSize); - - rcPath.CloseBuffer(corSystemPathSize); - - if (SUCCEEDED(hr)) - { - if (rcVersionSize > 0) - { - rcPath.Append(rcVersion); - rcPath.Append(W("\\")); - } - } -#else - // If we're hosted, we have the advantage of a CoreClrCallbacks reference. - // More importantly, we avoid calling back to mscoree.dll. - - hr = GetClrCallbacks().m_pfnGetCORSystemDirectory(rcPath); -#endif - if (SUCCEEDED(hr)) - { - hr = LoadLibraryHelper(pHInst, rcPath); - } - } -#endif // !DACCESS_COMPILE - -#endif // FEATURE_CORECLR #endif // CROSSGEN_COMPILE diff --git a/src/utilcode/clrhost.cpp b/src/utilcode/clrhost.cpp index 8a61eee966..5b28018514 100644 --- a/src/utilcode/clrhost.cpp +++ b/src/utilcode/clrhost.cpp @@ -16,9 +16,7 @@ #include "contract.h" #include "tls.h" -#if defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE) || defined(CROSSGEN_COMPILE) CoreClrCallbacks g_CoreClrCallbacks; -#endif // In some cirumstance (e.g, the thread suspecd another thread), allocation on heap @@ -206,7 +204,6 @@ int RFS_HashStack () #endif // FAILPOINTS_ENABLED -#if defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE) //----------------------------------------------------------------------------------- // This is the approved way to get a module handle to mscorwks.dll (or coreclr.dll). @@ -264,7 +261,6 @@ HMODULE GetCLRModule () return g_CoreClrCallbacks.m_hmodCoreCLR; } -#endif // defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE) #if defined(SELF_NO_HOST) @@ -402,7 +398,6 @@ LoadsTypeHolder::~LoadsTypeHolder() // versions in the same process. //-------------------------------------------------------------------------- -#if defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE) //-------------------------------------------------------------------------- // One-time initialized called by coreclr.dll in its dllmain. @@ -456,4 +451,3 @@ void OnUninitializedCoreClrCallbacks() } #endif // _DEBUG -#endif // defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE) diff --git a/src/utilcode/dlwrap.cpp b/src/utilcode/dlwrap.cpp index 0c9026a421..a6771c9daa 100644 --- a/src/utilcode/dlwrap.cpp +++ b/src/utilcode/dlwrap.cpp @@ -77,155 +77,3 @@ VerQueryValueW_NoThrow( } -#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) -// The following functions are not used in CoreCLR. Normally LINKER can remove these functions -// from generated files. But LINKER does it in two steps: -// 1. If no function in a source file is used, the file is ignored by LINKER -// 2. If one function is used, LINKER will first make sure all imported functions in the file -// is available, and then it will remove unused functions. -// Instead of specifying all libs for imported functions needed by the following codes, we just -// remove them from compiling phase. -__success(return) -BOOL -CreateUrlCacheEntryW_NoThrow( - IN LPCWSTR lpszUrlName, - IN DWORD dwExpectedFileSize, - IN LPCWSTR lpszFileExtension, - __out_ecount(MAX_LONGPATH+1) LPWSTR lpszFileName, - IN DWORD dwReserved - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - BOOL bRet=FALSE; - EX_TRY - { - bRet=CreateUrlCacheEntryW(lpszUrlName,dwExpectedFileSize,lpszFileExtension, - lpszFileName,dwReserved); - } - EX_CATCH_HRESULT(hr); - if (hr!=S_OK) - SetLastError(hr); - return bRet; - -} - -BOOL -CommitUrlCacheEntryW_NoThrow( - IN LPCWSTR lpszUrlName, - IN LPCWSTR lpszLocalFileName, - IN FILETIME ExpireTime, - IN FILETIME LastModifiedTime, - IN DWORD CacheEntryType, - IN LPCWSTR lpHeaderInfo, - IN DWORD dwHeaderSize, - IN LPCWSTR lpszFileExtension, - IN LPCWSTR lpszOriginalUrl - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - BOOL bRet=FALSE; - EX_TRY - { - bRet=CommitUrlCacheEntryW(lpszUrlName,lpszLocalFileName,ExpireTime, - LastModifiedTime,CacheEntryType,(LPWSTR)lpHeaderInfo, - dwHeaderSize,lpszFileExtension,lpszOriginalUrl); - } - EX_CATCH_HRESULT(hr); - if (hr!=S_OK) - SetLastError(hr); - return bRet; - -} - -BOOL -InternetTimeToSystemTimeA_NoThrow( - IN LPCSTR lpszTime, // NULL terminated string - OUT SYSTEMTIME *pst, // output in GMT time - IN DWORD dwReserved - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - BOOL bRet=FALSE; - EX_TRY - { - bRet=InternetTimeToSystemTimeA(lpszTime,pst,dwReserved); - } - EX_CATCH_HRESULT(hr); - if (hr!=S_OK) - SetLastError(hr); - return bRet; - -} - -HRESULT -CoInternetCreateSecurityManager_NoThrow( - IServiceProvider *pSP, - IInternetSecurityManager **ppSM, - DWORD dwReserved - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - EX_TRY - { - hr=CoInternetCreateSecurityManager(pSP,ppSM, dwReserved); - } - EX_CATCH_HRESULT(hr); - return hr; -} - -HRESULT -URLDownloadToCacheFileW_NoThrow( - LPUNKNOWN lpUnkcaller, - LPCWSTR szURL, - __out_ecount(dwBufLength) LPWSTR szFileName, - DWORD dwBufLength, - DWORD dwReserved, - IBindStatusCallback *pBSC - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - EX_TRY - { - hr=URLDownloadToCacheFileW(lpUnkcaller,szURL,szFileName,dwBufLength,dwReserved,pBSC); - } - EX_CATCH_HRESULT(hr); - return hr; -} - -HRESULT -CoInternetGetSession_NoThrow( - WORD dwSessionMode, - IInternetSession **ppIInternetSession, - DWORD dwReserved - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - EX_TRY - { - hr=CoInternetGetSession(dwSessionMode,ppIInternetSession,dwReserved); - } - EX_CATCH_HRESULT(hr); - return hr; -} - -HRESULT -CopyBindInfo_NoThrow( - const BINDINFO * pcbiSrc, BINDINFO * pbiDest - ) -{ - WRAPPER_NO_CONTRACT; - HRESULT hr=S_OK; - EX_TRY - { - hr=CopyBindInfo(pcbiSrc,pbiDest ); - } - EX_CATCH_HRESULT(hr); - return hr; -} -#endif // FEATURE_CORECLR && !CROSSGEN_COMPILE diff --git a/src/utilcode/ex.cpp b/src/utilcode/ex.cpp index bb164571ad..5d060660e3 100644 --- a/src/utilcode/ex.cpp +++ b/src/utilcode/ex.cpp @@ -2037,7 +2037,7 @@ static DWORD MarkAsThrownByUsWorker(UINT numArgs, /*out*/ ULONG_PTR exceptionArg exceptionArgs[0] = arg0; -#if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) && (defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE)) +#if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] = (ULONG_PTR) (GetCLRModule()); #endif // !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) && defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE) @@ -2086,7 +2086,7 @@ BOOL WasThrownByUs(const EXCEPTION_RECORD *pcER, DWORD dwExceptionCode) { return FALSE; } -#if!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) && (defined(FEATURE_CORECLR) || !defined(SELF_NO_HOST) || defined(DACCESS_COMPILE)) +#if!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) if ( ((ULONG_PTR)(GetCLRModule())) != pcER->ExceptionInformation[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] ) { return FALSE; diff --git a/src/utilcode/longfilepathwrappers.cpp b/src/utilcode/longfilepathwrappers.cpp index 5272d35807..2e493d02b5 100644 --- a/src/utilcode/longfilepathwrappers.cpp +++ b/src/utilcode/longfilepathwrappers.cpp @@ -1187,7 +1187,6 @@ FindFirstFileExWrapper( } #endif //!FEATURE_PAL -#if defined(FEATURE_CORECLR) || defined(CROSSGEN_COMPILE) #ifndef FEATURE_PAL @@ -1247,7 +1246,6 @@ BOOL PAL_GetPALDirectoryWrapper(SString& pbuffer) #endif // FEATURE_PAL -#endif // FEATURE_CORECLR || CROSSGEN_COMPILE //Implementation of LongFile Helpers const WCHAR LongFile::DirectorySeparatorChar = W('\\'); diff --git a/src/utilcode/makepath.cpp b/src/utilcode/makepath.cpp index 701c525cf4..6e0b56281c 100644 --- a/src/utilcode/makepath.cpp +++ b/src/utilcode/makepath.cpp @@ -15,158 +15,6 @@ #include "utilcode.h" #include "ex.h" -#ifndef FEATURE_CORECLR -/*** -*void MakePath() - build path name from components -* -*Purpose: -* create a path name from its individual components -* -*Entry: -* WCHAR *path - pointer to buffer for constructed path -* WCHAR *drive - pointer to drive component, may or may not contain -* trailing ':' -* WCHAR *dir - pointer to subdirectory component, may or may not include -* leading and/or trailing '/' or '\' characters -* WCHAR *fname - pointer to file base name component -* WCHAR *ext - pointer to extension component, may or may not contain -* a leading '.'. -* -*Exit: -* path - pointer to constructed path name -* -*Exceptions: -* -*******************************************************************************/ - -void MakePath ( - __out_ecount (MAX_LONGPATH) WCHAR *path, - __in LPCWSTR drive, - __in LPCWSTR dir, - __in LPCWSTR fname, - __in LPCWSTR ext - ) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - FORBID_FAULT; - } - CONTRACTL_END - - const WCHAR *p; - DWORD count = 0; - - /* we assume that the arguments are in the following form (although we - * do not diagnose invalid arguments or illegal filenames (such as - * names longer than 8.3 or with illegal characters in them) - * - * drive: - * A ; or - * A: - * dir: - * \top\next\last\ ; or - * /top/next/last/ ; or - * either of the above forms with either/both the leading - * and trailing / or \ removed. Mixed use of '/' and '\' is - * also tolerated - * fname: - * any valid file name - * ext: - * any valid extension (none if empty or null ) - */ - - /* copy drive */ - - if (drive && *drive) { - *path++ = *drive; - *path++ = _T(':'); - count += 2; - } - - /* copy dir */ - - if ((p = dir)) { - while (*p) { - *path++ = *p++; - count++; - - if (count == MAX_LONGPATH) { - --path; - *path = _T('\0'); - return; - } - } - -#ifdef _MBCS - if (*(p=_mbsdec(dir,p)) != _T('/') && *p != _T('\\')) { -#else /* _MBCS */ - // suppress warning for the following line; this is safe but would require significant code - // delta for prefast to understand. -#ifdef _PREFAST_ - #pragma warning( suppress: 26001 ) -#endif - if (*(p-1) != _T('/') && *(p-1) != _T('\\')) { -#endif /* _MBCS */ - *path++ = _T('\\'); - count++; - - if (count == MAX_LONGPATH) { - --path; - *path = _T('\0'); - return; - } - } - } - - /* copy fname */ - - if ((p = fname)) { - while (*p) { - *path++ = *p++; - count++; - - if (count == MAX_LONGPATH) { - --path; - *path = _T('\0'); - return; - } - } - } - - /* copy ext, including 0-terminator - check to see if a '.' needs - * to be inserted. - */ - - if ((p = ext)) { - if (*p && *p != _T('.')) { - *path++ = _T('.'); - count++; - - if (count == MAX_LONGPATH) { - --path; - *path = _T('\0'); - return; - } - } - - while ((*path++ = *p++)) { - count++; - - if (count == MAX_LONGPATH) { - --path; - *path = _T('\0'); - return; - } - } - } - else { - /* better add the 0-terminator */ - *path = _T('\0'); - } -} -#endif // !FEATURE_CORECLR /*** *void Makepath() - build path name from components @@ -307,57 +155,6 @@ void MakePath ( szPath.Shrink(count + 1); } -#if !defined(FEATURE_CORECLR) -static LPCWSTR g_wszProcessExePath = NULL; - -HRESULT GetProcessExePath(LPCWSTR *pwszProcessExePath) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - CONSISTENCY_CHECK(CheckPointer(pwszProcessExePath)); - } - CONTRACTL_END; - - HRESULT hr = S_OK; - - if (g_wszProcessExePath == NULL) - { - DWORD cchProcName = 0; - NewArrayHolder<WCHAR> wszProcName; - EX_TRY - { - PathString wszProcNameString; - cchProcName = WszGetModuleFileName(NULL, wszProcNameString); - if (cchProcName == 0) - { - hr = HRESULT_FROM_GetLastError(); - } - else - { - wszProcName = wszProcNameString.GetCopyOfUnicodeString(); - } - } - EX_CATCH_HRESULT(hr); - - if (FAILED(hr)) - { - return hr; - } - - if (InterlockedCompareExchangeT(&g_wszProcessExePath, const_cast<LPCWSTR>(wszProcName.GetValue()), NULL) == NULL) - { - wszProcName.SuppressRelease(); - } - } - _ASSERTE(g_wszProcessExePath != NULL); - _ASSERTE(SUCCEEDED(hr)); - - *pwszProcessExePath = g_wszProcessExePath; - return hr; -} -#endif // Returns the directory for HMODULE. So, if HMODULE was for "C:\Dir1\Dir2\Filename.DLL", // then this would return "C:\Dir1\Dir2\" (note the trailing backslash). diff --git a/src/utilcode/newapis.cpp b/src/utilcode/newapis.cpp index 3717f0280d..c05d024b7e 100644 --- a/src/utilcode/newapis.cpp +++ b/src/utilcode/newapis.cpp @@ -32,27 +32,6 @@ namespace NewApis FARPROC result = NULL; -#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) - - // First try to use the function defined in the culture dll - // if we are running on a platform prior to Win7 - if(!IsWindows7Platform()) - { - // only need to load the culture dll's handle once then we can hold onto it - static HMODULE hCulture = NULL; - // if we haven't loaded the culture dll yet - if (hCulture == NULL) - { - UtilCode::LoadLibraryShim(MAKEDLLNAME_W(W("culture")), NULL, 0, &hCulture); - } - - // make sure we were successful before using the handle - if (hCulture != NULL) - { - result=GetProcAddress(hCulture,lpProcName); - } - } -#endif // !FEATURE_CORECLR && !CROSSGEN_COMPILE // next try the kernel if(result==NULL) @@ -1094,9 +1073,7 @@ inline BOOL IsInvariantCasing(__in LPCWSTR lpLocaleName, __in DWORD dwMapFlags) retVal = ::LCIDToLocaleName(Locale, lpName, cchName, dwFlags | LOCALE_ALLOW_NEUTRAL_NAMES); #else -#ifdef FEATURE_CORECLR retVal = DownLevel::LCIDToLocaleName(Locale, lpName,cchName,dwFlags | LOCALE_ALLOW_NEUTRAL_NAMES); -#endif // FEATURE_CORECLR typedef int (WINAPI *PFNLCIDToLocaleName)(LCID, LPWSTR,int ,DWORD); static PFNLCIDToLocaleName pFNLCIDToLocaleName=NULL; @@ -1138,9 +1115,7 @@ inline BOOL IsInvariantCasing(__in LPCWSTR lpLocaleName, __in DWORD dwMapFlags) #if !defined(ENABLE_DOWNLEVEL_FOR_NLS) return ::LocaleNameToLCID(lpName, dwFlags | LOCALE_ALLOW_NEUTRAL_NAMES); #else -#ifdef FEATURE_CORECLR retVal = DownLevel::LocaleNameToLCID(lpName, dwFlags | LOCALE_ALLOW_NEUTRAL_NAMES); -#endif // FEATURE_CORECLR typedef int (WINAPI *PFNLocaleNameToLCID)(LPCWSTR,DWORD); static PFNLocaleNameToLCID pFNLocaleNameToLCID=NULL; @@ -1278,26 +1253,6 @@ inline BOOL IsInvariantCasing(__in LPCWSTR lpLocaleName, __in DWORD dwMapFlags) } -#if !defined(FEATURE_CORECLR) - BOOL GetNlsVersionEx(__in NLS_FUNCTION Function, __in LPCWSTR lpLocaleName, __inout LPNLSVERSIONINFOEX lpVersionInfo) - { - - typedef BOOL (WINAPI *PFNGetNLSVersionEx)(NLS_FUNCTION, LPCWSTR, LPNLSVERSIONINFOEX); - - static PFNGetNLSVersionEx pFNGetNLSVersionEx=NULL; - - // See if we still need to find our function - if (pFNGetNLSVersionEx == NULL) - { - // We only call this on Win8 and above, so this should always work. - pFNGetNLSVersionEx = (PFNGetNLSVersionEx) GetSystemProcAddressForSortingApi("GetNLSVersionEx", NULL); - } - - _ASSERTE(pFNGetNLSVersionEx != NULL); - - return pFNGetNLSVersionEx(Function, lpLocaleName, lpVersionInfo); - } -#endif // This is a Windows 7 and above function // This returns the "specific" locale from an input name, ie: "en" returns "en-US", diff --git a/src/utilcode/pedecoder.cpp b/src/utilcode/pedecoder.cpp index c437c21c35..0ab1cf3563 100644 --- a/src/utilcode/pedecoder.cpp +++ b/src/utilcode/pedecoder.cpp @@ -1173,12 +1173,6 @@ CHECK PEDecoder::CheckCorHeader() const CHECK_OK; } -#if !defined(FEATURE_CORECLR) -#define WHIDBEY_SP2_VERSION_MAJOR 2 -#define WHIDBEY_SP2_VERSION_MINOR 0 -#define WHIDBEY_SP2_VERSION_BUILD 50727 -#define WHIDBEY_SP2_VERSION_PRIVATE_BUILD 3053 -#endif // !defined(FEATURE_CORECLR) // This function exists to provide compatibility between two different native image @@ -1236,71 +1230,10 @@ IMAGE_DATA_DIRECTORY *PEDecoder::GetMetaDataHelper(METADATA_SECTION_TYPE type) c // COR_HEADER and so the value of pDirRet is correct if (HasNativeHeader()) { -#ifdef FEATURE_CORECLR if (type == METADATA_SECTION_MANIFEST) pDirRet = &GetNativeHeader()->ManifestMetaData; -#else // FEATURE_CORECLR - - IMAGE_DATA_DIRECTORY *pDirNativeHeader = &GetNativeHeader()->ManifestMetaData; - - // This code leverages the fact that pre-Whidbey SP2 private build numbers can never - // be greater than Whidbey SP2 private build number, because otherwise major setup - // issues would arise. To prevent this, it is standard to bump the private build - // number up a significant amount for SPs, as was the case between Whidbey SP1 and - // Whidbey SP2. - // - // Since we could be reading an older version of native image, we tell - // GetNativeVersionInfoMaybeNull to skip checking the native header. - CORCOMPILE_VERSION_INFO *pVerInfo = GetNativeVersionInfoMaybeNull(true); - bool fIsPreWhidbeySP2 = false; - - // If pVerInfo is NULL, we assume that we're in an NGEN compilation domain and that - // the information has not yet been written. Since an NGEN compilation domain running - // in the v4.0 runtime can only complie v4.0 native images, we'll assume the default - // fIsPreWhidbeySP2 value (false) is correct. - if (pVerInfo != NULL && pVerInfo->wVersionMajor <= WHIDBEY_SP2_VERSION_MAJOR) - { - if (pVerInfo->wVersionMajor < WHIDBEY_SP2_VERSION_MAJOR) - fIsPreWhidbeySP2 = true; - else if (pVerInfo->wVersionMajor == WHIDBEY_SP2_VERSION_MAJOR) - { - // If the sp2 minor version isn't 0, we need this logic: - // if (pVerInfo->wVersionMinor < WHIDBEY_SP2_VERSION_MINOR) - // fIsPreWhidbeySP2 = true; - // else - // However, if it is zero, with that logic we get a warning about the comparison - // of an unsigned variable to zero always being false. - _ASSERTE(WHIDBEY_SP2_VERSION_MINOR == 0); - - if (pVerInfo->wVersionMinor == WHIDBEY_SP2_VERSION_MINOR) - { - if (pVerInfo->wVersionBuildNumber < WHIDBEY_SP2_VERSION_BUILD) - fIsPreWhidbeySP2 = true; - else if (pVerInfo->wVersionBuildNumber == WHIDBEY_SP2_VERSION_BUILD) - { - if (pVerInfo->wVersionPrivateBuildNumber < WHIDBEY_SP2_VERSION_PRIVATE_BUILD) - fIsPreWhidbeySP2 = true; - } - } - } - } - - // In pre-Whidbey SP2, pDirRet points to manifest and pDirNativeHeader points to full. - if (fIsPreWhidbeySP2) - { - if (type == METADATA_SECTION_FULL) - pDirRet = pDirNativeHeader; - } - // In Whidbey SP2 and later, pDirRet points to full and pDirNativeHeader points to manifest. - else - { - if (type == METADATA_SECTION_MANIFEST) - pDirRet = pDirNativeHeader; - } - -#endif // FEATURE_CORECLR } diff --git a/src/utilcode/registrywrapper.cpp b/src/utilcode/registrywrapper.cpp index f6b88db977..b3c4b42946 100644 --- a/src/utilcode/registrywrapper.cpp +++ b/src/utilcode/registrywrapper.cpp @@ -74,288 +74,3 @@ #include "clrconfig.h" #include "strsafe.h" -#if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) && !defined(FEATURE_CORECLR) - -static LPCWSTR kRegistryRootKey = W("SOFTWARE\\"); -static const HKEY kRegistryRootHive = HKEY_LOCAL_MACHINE; -static LPCWSTR kWow6432Node = W("Wow6432Node\\"); -static LPCWSTR kMicrosoftDotNetFrameworkPolicy = W("Microsoft\\.NETFramework\\Policy"); -static LPCWSTR wszHKLM = W("HKLM\\"); -static WCHAR * g_registryRoot = NULL; -static volatile bool g_initialized = false; -static const WCHAR BACKSLASH_CHARACTER[] = W("\\"); - -// -// Called the first time we use ClrRegCreateKeyEx or ClrRegOpenKeyEx to determine if the registry redirection -// config value has been set. If so, we parse it into g_registryRoot -// If the config string is mal-formed, we don't set the global variable. -// -HRESULT ParseRegistryRootConfigValue() -{ - if (!IsNgenOffline()) - { - return ERROR_SUCCESS; - } - - CLRConfigStringHolder configValue(CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_RegistryRoot)); - // Since IsNgenOffline returned true, this better not be NULL - if (configValue == NULL) - return ERROR_BAD_ARGUMENTS; - - if (_wcsnicmp(configValue, wszHKLM, wcslen(wszHKLM)) != 0) - { - return ERROR_BAD_ARGUMENTS; - } - - // The rest of the string is the location of the redirected registry key - LPWSTR configValueKey = (LPWSTR)configValue; - configValueKey = _wcsninc(configValueKey, wcslen(wszHKLM)); - - size_t len = wcslen(configValueKey) + 1; - - bool appendBackslash = false; - if (configValueKey[wcslen(configValueKey) - 1] != W('\\')) - { - appendBackslash = true; - len += wcslen(BACKSLASH_CHARACTER); - } - g_registryRoot = new (nothrow) WCHAR[len]; - - if (g_registryRoot == NULL) - { - return ERROR_NOT_ENOUGH_MEMORY; - } - - wcscpy_s(g_registryRoot, len, configValueKey); - if (appendBackslash) - { - StringCchCat(g_registryRoot, len, BACKSLASH_CHARACTER); - } - - return ERROR_SUCCESS; -} - -// -// This is our check that the target machine is 32/64bit -// If 32bit only, there will be no Wow6432Node key -// If 64bit, there will be a Wow6432Node key -// -HRESULT CheckWow6432NodeNetFxExists(bool * fResult) -{ - static bool bInitialized = false; - static bool bNodeExists = false; - HRESULT hr = ERROR_SUCCESS; - - if (!bInitialized) - { - size_t redirectedLength = wcslen(g_registryRoot) + wcslen(kWow6432Node) + wcslen(kMicrosoftDotNetFrameworkPolicy) + 1; - LPWSTR lpRedirectedKey = new (nothrow) WCHAR[redirectedLength]; - - if (lpRedirectedKey == NULL) - { - return ERROR_NOT_ENOUGH_MEMORY; - } - - wcscpy_s(lpRedirectedKey, redirectedLength, g_registryRoot); - StringCchCat(lpRedirectedKey, redirectedLength, kWow6432Node); - StringCchCat(lpRedirectedKey, redirectedLength, kMicrosoftDotNetFrameworkPolicy); - - HKEY hkey; - hr = RegOpenKeyExW(HKEY_LOCAL_MACHINE, lpRedirectedKey, 0, KEY_READ, &hkey); - bNodeExists = hr == ERROR_SUCCESS; - - if (hr == ERROR_FILE_NOT_FOUND) - { - hr = ERROR_SUCCESS; - } - - if (hkey) - { - RegCloseKey(hkey); - } - bInitialized = true; - } - *fResult = bNodeExists; - return hr; -} - -HRESULT CheckUseWow6432Node(REGSAM samDesired, bool * fResult) -{ - HRESULT hr = ERROR_SUCCESS; - bool fWow6432NodeExists = false; - - hr = CheckWow6432NodeNetFxExists(&fWow6432NodeExists); - if (hr == ERROR_SUCCESS) - { - if (!fWow6432NodeExists) - { - *fResult = false; - } else - { -#if defined(_WIN64) - *fResult = false; -#else - *fResult = true; -#endif - // If KEY_WOW64_64KEY or KEY_WOW64_32KEY are set, override - // If both are set, the actual registry call will fail with ERROR_INVALID_PARAMETER - // so no worries here - if (samDesired & KEY_WOW64_64KEY) - { - *fResult = false; - } else if (samDesired & KEY_WOW64_32KEY) - { - *fResult = true; - } - } - } - return hr; -} - -// -// lpRedirectedKey is allocated and returned from this method. Caller owns the new string and -// should release -// -__success(return == ERROR_SUCCESS) -HRESULT RedirectKey(REGSAM samDesired, HKEY hKey, LPCWSTR lpKey, __deref_out_z LPWSTR * lpRedirectedKey) -{ - if (hKey != kRegistryRootHive || _wcsnicmp(lpKey, kRegistryRootKey, wcslen(kRegistryRootKey)) != 0) - { - *lpRedirectedKey = NULL; - return ERROR_SUCCESS; - } - - LPCWSTR lpRootStrippedKey = lpKey + wcslen(kRegistryRootKey); - size_t redirectedLength = wcslen(g_registryRoot) + wcslen(lpRootStrippedKey) + 1; - - bool bUseWow = false; - HRESULT hr = CheckUseWow6432Node(samDesired, &bUseWow); - - if (hr != ERROR_SUCCESS) - { - return hr; - } - - if (bUseWow) - { - redirectedLength += wcslen(kWow6432Node); - } - - *lpRedirectedKey = new (nothrow) WCHAR[redirectedLength]; - - if (*lpRedirectedKey == NULL) - { - return ERROR_NOT_ENOUGH_MEMORY; - } - - wcscpy_s(*lpRedirectedKey, redirectedLength, g_registryRoot); - if (bUseWow) - { - StringCchCat(*lpRedirectedKey, redirectedLength, kWow6432Node); - } - - StringCchCat(*lpRedirectedKey, redirectedLength, lpRootStrippedKey); - - return ERROR_SUCCESS; -} - -LONG ClrRegCreateKeyEx( - HKEY hKey, - LPCWSTR lpSubKey, - DWORD Reserved, - __in_opt LPWSTR lpClass, - DWORD dwOptions, - REGSAM samDesired, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - PHKEY phkResult, - LPDWORD lpdwDisposition - ) -{ - HRESULT hr; - if (!g_initialized) - { - hr = ParseRegistryRootConfigValue(); - if (hr != ERROR_SUCCESS) - return hr; - g_initialized = true; - } - - if (g_registryRoot != NULL) - { - NewArrayHolder<WCHAR> lpRedirectedKey(NULL); - hr = RedirectKey(samDesired, hKey, lpSubKey, &lpRedirectedKey); - // We don't want to touch the registry if we're low on memory and can't redirect properly. It could lead - // to use reading and writing to two separate registries and corrupting both in the process - if (hr != ERROR_SUCCESS) - return hr; - LPCWSTR lpKeyToUse = lpRedirectedKey == NULL ? lpSubKey : lpRedirectedKey; - return RegCreateKeyExW(hKey, lpKeyToUse, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); - } - return RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); -} // ClrRegCreateKeyEx - -LONG ClrRegOpenKeyEx( - HKEY hKey, - LPCWSTR lpSubKey, - DWORD ulOptions, - REGSAM samDesired, - PHKEY phkResult - ) -{ - HRESULT hr; - if (!g_initialized) - { - hr = ParseRegistryRootConfigValue(); - if (hr != ERROR_SUCCESS) - return hr; - g_initialized = true; - } - - if (g_registryRoot != NULL) - { - NewArrayHolder<WCHAR> lpRedirectedKey(NULL); - hr = RedirectKey(samDesired, hKey, lpSubKey, &lpRedirectedKey); - // We don't want to touch the registry if we're low on memory and can't redirect properly. It could lead - // to use reading and writing to two separate registries and corrupting both in the process - if (hr != ERROR_SUCCESS) - return hr; - LPCWSTR lpKeyToUse = lpRedirectedKey == NULL ? lpSubKey : lpRedirectedKey; - return RegOpenKeyExW(hKey, lpKeyToUse, ulOptions, samDesired, phkResult); - } - return RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult); -} - -// -// Determine whether we're running Offline Ngen for Build Lab based on the settings of several Config Values. -// -bool IsNgenOffline() -{ - static volatile bool fInitialized = false; - static volatile bool fNgenOffline = false; - - if (!fInitialized) - { - REGUTIL::CORConfigLevel kCorConfigLevel = static_cast<REGUTIL::CORConfigLevel>(REGUTIL::COR_CONFIG_ENV); - CLRConfigStringHolder pwzConfigInstallRoot = REGUTIL::GetConfigString_DontUse_(CLRConfig::INTERNAL_InstallRoot, - TRUE /* Prepend Complus */, - kCorConfigLevel, - FALSE /* fUsePerfCache */); - CLRConfigStringHolder pwzConfigNicPath(CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_NicPath)); - CLRConfigStringHolder pwzRegistryRoot(CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_RegistryRoot)); - CLRConfigStringHolder pwzConfigAssemblyPath(CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_AssemblyPath)); - CLRConfigStringHolder pwzConfigAssemblyPath2(CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_AssemblyPath2)); - if (pwzConfigInstallRoot != NULL && - pwzConfigNicPath != NULL && - pwzConfigAssemblyPath != NULL && - pwzConfigAssemblyPath2 != NULL && - pwzRegistryRoot != NULL) - { - fNgenOffline = true; - } - fInitialized = true; - } - - return fNgenOffline; -} - -#endif //!FEATURE_UTILCODE_NO_DEPENDENCIES && !FEATURE_CORECLR diff --git a/src/utilcode/regutil.cpp b/src/utilcode/regutil.cpp index d611ef965f..c38c38907a 100644 --- a/src/utilcode/regutil.cpp +++ b/src/utilcode/regutil.cpp @@ -111,19 +111,6 @@ LPWSTR REGUTIL::EnvGetString(LPCWSTR name, BOOL fPrependCOMPLUS) #ifdef ALLOW_REGISTRY -#ifndef FEATURE_CORECLR - -//***************************************************************************** -// Gives the use the ability to turn on/off REGUTIL's ability to read from -// the registry. This is useful in mscoree.dll on startup, in order to avoid -// loading advapi32 and rpcrt4 until we're ready for them -//***************************************************************************** -void REGUTIL::AllowRegistryUse(BOOL fAllowUse) -{ - s_fUseRegistry = fAllowUse; -}// AllowRegistryUse - -#endif // !FEATURE_CORECLR #endif // ALLOW_REGISTRY @@ -522,690 +509,6 @@ DWORD REGUTIL::GetConfigFlag_DontUse_(LPCWSTR name, DWORD bitToSet, BOOL defValu #ifdef ALLOW_REGISTRY -#ifndef FEATURE_CORECLR - -//***************************************************************************** -// Open's the given key and returns the value desired. If the key or value is -// not found, then the default is returned. -//***************************************************************************** -long REGUTIL::GetLong( // Return value from registry or default. - LPCTSTR szName, // Name of value to get. - long iDefault, // Default value to return if not found. - LPCTSTR szKey, // Name of key, NULL==default. - HKEY hKeyVal) // What key to work on. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - FORBID_FAULT; - SO_TOLERANT; - } - CONTRACTL_END; - - long iValue; // The value to read. - DWORD iType; // Type of value to get. - DWORD iSize; // Size of buffer. - HKEY hKey; // Key for the registry entry. - - _ASSERTE(UseRegistry()); - - FAULT_NOT_FATAL(); // We don't report OOM errors here, we return a default value. - - // Open the key if it is there. - if (ERROR_SUCCESS != WszRegOpenKeyEx(hKeyVal, (szKey) ? szKey : FRAMEWORK_REGISTRY_KEY_W, 0, KEY_READ, &hKey)) - return (iDefault); - - // Read the key value if found. - iType = REG_DWORD; - iSize = sizeof(long); - if (ERROR_SUCCESS != WszRegQueryValueEx(hKey, szName, NULL, - &iType, (LPBYTE)&iValue, &iSize) || iType != REG_DWORD) - iValue = iDefault; - - // We're done with the key now. - VERIFY(!RegCloseKey(hKey)); - return (iValue); -} - - -// Opens or creates desired reg key, then writes iValue -//***************************************************************************** -long REGUTIL::SetOrCreateLong( // Return value from registry or default. - LPCTSTR szName, // Name of value to get. - long iValue, // Value to set. - LPCTSTR szKey, // Name of key, NULL==default. - HKEY hKeyVal) // What key to work on. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - _ASSERTE(UseRegistry()); - - long lRtn; // Return code. - HKEY hKey; // Key for the registry entry. - - - // Open the key if it is there, else create it - if (WszRegCreateKeyEx(hKeyVal, - (szKey) ? szKey : FRAMEWORK_REGISTRY_KEY_W, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - KEY_WRITE, - NULL, - &hKey, - NULL) != ERROR_SUCCESS) - { - return (-1); - } - - // Read the key value if found. - lRtn = WszRegSetValueEx(hKey, szName, NULL, REG_DWORD, (const BYTE *) &iValue, sizeof(DWORD)); - - // We're done with the key now. - VERIFY(!RegCloseKey(hKey)); - return (lRtn); -} - - -//***************************************************************************** -// Open's the given key and returns the value desired. If the key or value is -// not found, then the default is returned. -//***************************************************************************** -long REGUTIL::SetLong( // Return value from registry or default. - LPCTSTR szName, // Name of value to get. - long iValue, // Value to set. - LPCTSTR szKey, // Name of key, NULL==default. - HKEY hKeyVal) // What key to work on. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - _ASSERTE(UseRegistry()); - - long lRtn; // Return code. - HKEY hKey; // Key for the registry entry. - - // Open the key if it is there. - if (ERROR_SUCCESS != WszRegOpenKey(hKeyVal, (szKey) ? szKey : FRAMEWORK_REGISTRY_KEY_W, &hKey)) - return (-1); - - // Read the key value if found. - lRtn = WszRegSetValueEx(hKey, szName, NULL, REG_DWORD, (const BYTE *) &iValue, sizeof(DWORD)); - - // We're done with the key now. - VERIFY(!RegCloseKey(hKey)); - return (lRtn); -} - -//***************************************************************************** -// Set an entry in the registry of the form: -// HKEY_CLASSES_ROOT\szKey\szSubkey = szValue. If szSubkey or szValue are -// NULL, omit them from the above expression. -//***************************************************************************** -BOOL REGUTIL::SetKeyAndValue( // TRUE or FALSE. - LPCTSTR szKey, // Name of the reg key to set. - LPCTSTR szSubkey, // Optional subkey of szKey. - LPCTSTR szValue) // Optional value for szKey\szSubkey. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - _ASSERTE(UseRegistry()); - - size_t nLen = _tcslen(szKey) + 1; - if (szSubkey) - nLen += (_tcslen(szSubkey) + 1); - - NewArrayHolder<TCHAR> rcKey = new (nothrow) TCHAR[nLen]; // Buffer for the full key name. - if (rcKey == NULL) - return FALSE; - - HKEY hKey = NULL; // Handle to the new reg key. - - // Init the key with the base key name. - _tcscpy_s(rcKey, nLen, szKey); - - // Append the subkey name (if there is one). - if (szSubkey != NULL) - { - _tcscat_s(rcKey, nLen, _T("\\")); - _tcscat_s(rcKey, nLen, szSubkey); - } - - // Create the registration key. - if (WszRegCreateKeyEx(HKEY_CLASSES_ROOT, rcKey, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, - &hKey, NULL) != ERROR_SUCCESS) - return(FALSE); - - // Set the value (if there is one). - if (szValue != NULL) - if( WszRegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE *) szValue, - (Wszlstrlen(szValue)+1) * sizeof(TCHAR)) != ERROR_SUCCESS ) { - VERIFY(!RegCloseKey(hKey)); - return(FALSE); - } - - VERIFY(!RegCloseKey(hKey)); - return(TRUE); -} - - -//***************************************************************************** -// Delete an entry in the registry of the form: -// HKEY_CLASSES_ROOT\szKey\szSubkey. -//***************************************************************************** -LONG REGUTIL::DeleteKey( // TRUE or FALSE. - LPCTSTR szKey, // Name of the reg key to set. - LPCTSTR szSubkey) // Subkey of szKey. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - _ASSERTE(UseRegistry()); - - size_t nLen = _tcslen(szKey) + 1; - if (szSubkey) - nLen += (_tcslen(szSubkey) + 1); - - NewArrayHolder<TCHAR> rcKey = new (nothrow) TCHAR[nLen]; // Buffer for the full key name. - if (rcKey == NULL) - return ERROR_NOT_ENOUGH_MEMORY; - - // Init the key with the base key name. - _tcscpy_s(rcKey, nLen, szKey); - - // Append the subkey name (if there is one). - if (szSubkey != NULL) - { - _tcscat_s(rcKey, nLen, _T("\\")); - _tcscat_s(rcKey, nLen, szSubkey); - } - - // Delete the registration key. - return WszRegDeleteKey(HKEY_CLASSES_ROOT, rcKey); -} - - -//***************************************************************************** -// Open the key, create a new keyword and value pair under it. -//***************************************************************************** -BOOL REGUTIL::SetRegValue( // Return status. - LPCTSTR szKeyName, // Name of full key. - LPCTSTR szKeyword, // Name of keyword. - LPCTSTR szValue) // Value of keyword. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - _ASSERTE(UseRegistry()); - - HKEY hKey; // Handle to the new reg key. - - // Create the registration key. - if (WszRegCreateKeyEx(HKEY_CLASSES_ROOT, szKeyName, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, - &hKey, NULL) != ERROR_SUCCESS) - return (FALSE); - - // Set the value (if there is one). - if (szValue != NULL) - if( WszRegSetValueEx(hKey, szKeyword, 0, REG_SZ, (BYTE *)szValue, - (Wszlstrlen(szValue)+1) * sizeof(TCHAR)) != ERROR_SUCCESS) { - VERIFY(!RegCloseKey(hKey)); - return(FALSE); - } - - VERIFY(!RegCloseKey(hKey)); - return (TRUE); -} - - -//***************************************************************************** -// Does standard registration of a CoClass with a progid. -//***************************************************************************** -HRESULT REGUTIL::RegisterCOMClass( // Return code. - REFCLSID rclsid, // Class ID. - LPCTSTR szDesc, // Description of the class. - LPCTSTR szProgIDPrefix, // Prefix for progid. - int iVersion, // Version # for progid. - LPCTSTR szClassProgID, // Class progid. - LPCTSTR szThreadingModel, // What threading model to use. - LPCTSTR szModule, // Path to class. - HINSTANCE hInst, // Handle to module being registered - LPCTSTR szAssemblyName, // Optional Assembly, - LPCTSTR szVersion, // Optional Runtime version (directory containing runtime) - BOOL fExternal, // flag - External to mscoree. - BOOL fRelativePath) // flag - Relative path in szModule -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - WCHAR rcCLSID[256]; // CLSID\\szID. - WCHAR rcInproc[_MAX_PATH+64]; // CLSID\\InprocServer32 - WCHAR rcProgID[256]; // szProgIDPrefix.szClassProgID - WCHAR rcIndProgID[256]; // rcProgID.iVersion - WCHAR rcShim[_MAX_PATH]; - HRESULT hr; - - // Format the prog ID values. - VERIFY(_snwprintf_s(rcIndProgID, _countof(rcIndProgID), _TRUNCATE, W("%s.%s"), szProgIDPrefix, szClassProgID)); - - VERIFY(_snwprintf_s(rcProgID, _countof(rcProgID), _TRUNCATE, W("%s.%d"), rcIndProgID, iVersion)); - - // Do the initial portion. - if (FAILED(hr = RegisterClassBase(rclsid, szDesc, rcProgID, rcIndProgID, rcCLSID, NumItems(rcCLSID)))) - return (hr); - - VERIFY(_snwprintf_s(rcInproc, _countof(rcInproc), _TRUNCATE, W("%s\\%s"), rcCLSID, W("InprocServer32"))); - - if (!fExternal){ - SetKeyAndValue(rcCLSID, W("InprocServer32"), szModule); - } - else{ - LPCTSTR pSep = szModule; - if (!fRelativePath && szModule) { - pSep = wcsrchr(szModule, W('\\')); - if(pSep == NULL) - pSep = szModule; - else - pSep++; - } - HMODULE hMod = WszLoadLibrary(W("mscoree.dll")); - if (!hMod) - return E_FAIL; - - DWORD ret; - VERIFY(ret = WszGetModuleFileName(hMod, rcShim, NumItems(rcShim))); - FreeLibrary(hMod); - if( !ret ) - return E_FAIL; - - // Set the server path. - SetKeyAndValue(rcCLSID, W("InprocServer32"), rcShim); - if(pSep) - SetKeyAndValue(rcCLSID, W("Server"), pSep); - - if(szAssemblyName) { - SetRegValue(rcInproc, W("Assembly"), szAssemblyName); - SetRegValue(rcInproc, W("Class"), rcIndProgID); - } - } - - // Set the runtime version, it needs to be passed in from the outside - if(szVersion != NULL) { - LPCTSTR pSep2 = NULL; - LPTSTR pSep1 = const_cast<LPTSTR>(wcsrchr(szVersion, W('\\'))); - if(pSep1 != NULL) { - *pSep1 = '\0'; - pSep2 = wcsrchr(szVersion, W('\\')); - if (!pSep2) - pSep2 = szVersion; - else - pSep2 = pSep2++; // exclude '\\' - } - else - pSep2 = szVersion; - - size_t bufLen = wcslen(rcInproc)+wcslen(pSep2)+2; - WCHAR* rcVersion = new (nothrow) WCHAR[bufLen]; - if(rcVersion==NULL) - return (E_OUTOFMEMORY); - wcscpy_s(rcVersion, bufLen, rcInproc); - wcscat_s(rcVersion, bufLen, W("\\")); - wcscat_s(rcVersion, bufLen, pSep2); - SetRegValue(rcVersion, W("ImplementedInThisVersion"), W("")); - delete[] rcVersion; - - if(pSep1 != NULL) - *pSep1 = W('\\'); - } - - // Add the threading model information. - SetRegValue(rcInproc, W("ThreadingModel"), szThreadingModel); - return (S_OK); -} - - - -//***************************************************************************** -// Does standard registration of a CoClass with a progid. -// NOTE: This is the non-side-by-side execution version. -//***************************************************************************** -HRESULT REGUTIL::RegisterCOMClass( // Return code. - REFCLSID rclsid, // Class ID. - LPCTSTR szDesc, // Description of the class. - LPCTSTR szProgIDPrefix, // Prefix for progid. - int iVersion, // Version # for progid. - LPCTSTR szClassProgID, // Class progid. - LPCTSTR szThreadingModel, // What threading model to use. - LPCTSTR szModule, // Path to class. - BOOL bInprocServer) // Whether we register the server as inproc or local -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - WCHAR rcCLSID[256]; // CLSID\\szID. - WCHAR rcInproc[_MAX_PATH+64]; // CLSID\\InprocServer32 - WCHAR rcProgID[256]; // szProgIDPrefix.szClassProgID - WCHAR rcIndProgID[256]; // rcProgID.iVersion - HRESULT hr; - - // Format the prog ID values. - VERIFY(_snwprintf_s(rcIndProgID, _countof(rcIndProgID), _TRUNCATE, W("%s.%s"), szProgIDPrefix, szClassProgID)); - - VERIFY(_snwprintf_s(rcProgID, _countof(rcProgID), _TRUNCATE, W("%s.%d"), rcIndProgID, iVersion)); - - // Do the initial portion. - if (FAILED(hr = RegisterClassBase(rclsid, szDesc, rcProgID, rcIndProgID, rcCLSID, NumItems(rcCLSID)))) - return (hr); - - WCHAR *szServerType = bInprocServer ? W("InprocServer32") : W("LocalServer32"); - - // Set the server path. - SetKeyAndValue(rcCLSID, szServerType , szModule); - - // Add the threading model information. - VERIFY(_snwprintf_s(rcInproc, _countof(rcInproc), _TRUNCATE, W("%s\\%s"), rcCLSID, szServerType)); - - SetRegValue(rcInproc, W("ThreadingModel"), szThreadingModel); - return (S_OK); -} - - - -//***************************************************************************** -// Register the basics for a in proc server. -//***************************************************************************** -HRESULT REGUTIL::RegisterClassBase( // Return code. - REFCLSID rclsid, // Class ID we are registering. - LPCTSTR szDesc, // Class description. - LPCTSTR szProgID, // Class prog ID. - LPCTSTR szIndepProgID, // Class version independant prog ID. - __out_ecount(cchOutCLSID) LPTSTR szOutCLSID, // CLSID formatted in character form. - DWORD cchOutCLSID) // Out CLS ID buffer size -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - TCHAR szID[64]; // The class ID to register. - - // Create some base key strings. - GuidToLPWSTR(rclsid, szID, NumItems(szID)); - - size_t nLen = _tcslen(_T("CLSID\\")) + _tcslen( szID) + 1; - if( cchOutCLSID < nLen ) - return E_INVALIDARG; - - _tcscpy_s(szOutCLSID, cchOutCLSID, W("CLSID\\")); - _tcscat_s(szOutCLSID, cchOutCLSID, szID); - - // Create ProgID keys. - SetKeyAndValue(szProgID, NULL, szDesc); - SetKeyAndValue(szProgID, W("CLSID"), szID); - - // Create VersionIndependentProgID keys. - SetKeyAndValue(szIndepProgID, NULL, szDesc); - SetKeyAndValue(szIndepProgID, W("CurVer"), szProgID); - SetKeyAndValue(szIndepProgID, W("CLSID"), szID); - - // Create entries under CLSID. - SetKeyAndValue(szOutCLSID, NULL, szDesc); - SetKeyAndValue(szOutCLSID, W("ProgID"), szProgID); - SetKeyAndValue(szOutCLSID, W("VersionIndependentProgID"), szIndepProgID); - SetKeyAndValue(szOutCLSID, W("NotInsertable"), NULL); - return (S_OK); -} - - - -//***************************************************************************** -// Unregister the basic information in the system registry for a given object -// class. -//***************************************************************************** -HRESULT REGUTIL::UnregisterCOMClass( // Return code. - REFCLSID rclsid, // Class ID we are registering. - LPCTSTR szProgIDPrefix, // Prefix for progid. - int iVersion, // Version # for progid. - LPCTSTR szClassProgID, // Class progid. - BOOL fExternal) // flag - External to mscoree. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - WCHAR rcCLSID[64]; // CLSID\\szID. - WCHAR rcProgID[128]; // szProgIDPrefix.szClassProgID - WCHAR rcIndProgID[128]; // rcProgID.iVersion - - // Format the prog ID values. - VERIFY(_snwprintf_s(rcProgID, _countof(rcProgID), _TRUNCATE, W("%s.%s"), szProgIDPrefix, szClassProgID)); - - VERIFY(_snwprintf_s(rcIndProgID, _countof(rcIndProgID), _TRUNCATE, W("%s.%d"), rcProgID, iVersion)); - - UnregisterClassBase(rclsid, rcProgID, rcIndProgID, rcCLSID, NumItems(rcCLSID)); - DeleteKey(rcCLSID, W("InprocServer32")); - if (fExternal){ - DeleteKey(rcCLSID, W("Server")); - DeleteKey(rcCLSID, W("Version")); - } - GuidToLPWSTR(rclsid, rcCLSID, NumItems(rcCLSID)); - DeleteKey(W("CLSID"), rcCLSID); - return (S_OK); -} - - -//***************************************************************************** -// Unregister the basic information in the system registry for a given object -// class. -// NOTE: This is the non-side-by-side execution version. -//***************************************************************************** -HRESULT REGUTIL::UnregisterCOMClass( // Return code. - REFCLSID rclsid, // Class ID we are registering. - LPCTSTR szProgIDPrefix, // Prefix for progid. - int iVersion, // Version # for progid. - LPCTSTR szClassProgID) // Class progid. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - WCHAR rcCLSID[64]; // CLSID\\szID. - WCHAR rcProgID[128]; // szProgIDPrefix.szClassProgID - WCHAR rcIndProgID[128]; // rcProgID.iVersion - - // Format the prog ID values. - VERIFY(_snwprintf_s(rcProgID, _countof(rcProgID), _TRUNCATE, W("%s.%s"), szProgIDPrefix, szClassProgID)); - - VERIFY(_snwprintf_s(rcIndProgID, _countof(rcIndProgID), _TRUNCATE, W("%s.%d"), rcProgID, iVersion)); - - UnregisterClassBase(rclsid, rcProgID, rcIndProgID, rcCLSID, NumItems(rcCLSID)); - DeleteKey(rcCLSID, W("InprocServer32")); - DeleteKey(rcCLSID, W("LocalServer32")); - - GuidToLPWSTR(rclsid, rcCLSID, NumItems(rcCLSID)); - DeleteKey(W("CLSID"), rcCLSID); - return (S_OK); -} - - -//***************************************************************************** -// Delete the basic settings for an inproc server. -//***************************************************************************** -HRESULT REGUTIL::UnregisterClassBase( // Return code. - REFCLSID rclsid, // Class ID we are registering. - LPCTSTR szProgID, // Class prog ID. - LPCTSTR szIndepProgID, // Class version independant prog ID. - __out_ecount(cchOutCLSID) LPTSTR szOutCLSID, // Return formatted class ID here. - DWORD cchOutCLSID) // Out CLS ID buffer size -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - TCHAR szID[64]; // The class ID to register. - - // Create some base key strings. - GuidToLPWSTR(rclsid, szID, NumItems(szID)); - size_t nLen = _tcslen(_T("CLSID\\")) + _tcslen( szID) + 1; - if( cchOutCLSID < nLen ) - return E_INVALIDARG; - - _tcscpy_s(szOutCLSID, cchOutCLSID, W("CLSID\\")); - _tcscat_s(szOutCLSID, cchOutCLSID, szID); - - // Delete the version independant prog ID settings. - DeleteKey(szIndepProgID, W("CurVer")); - DeleteKey(szIndepProgID, W("CLSID")); - WszRegDeleteKey(HKEY_CLASSES_ROOT, szIndepProgID); - - // Delete the prog ID settings. - DeleteKey(szProgID, W("CLSID")); - WszRegDeleteKey(HKEY_CLASSES_ROOT, szProgID); - - // Delete the class ID settings. - DeleteKey(szOutCLSID, W("ProgID")); - DeleteKey(szOutCLSID, W("VersionIndependentProgID")); - DeleteKey(szOutCLSID, W("NotInsertable")); - WszRegDeleteKey(HKEY_CLASSES_ROOT, szOutCLSID); - return (S_OK); -} - - -//***************************************************************************** -// Register a type library. -//***************************************************************************** -HRESULT REGUTIL::RegisterTypeLib( // Return code. - REFGUID rtlbid, // TypeLib ID we are registering. - int iVersion, // Typelib version. - LPCTSTR szDesc, // TypeLib description. - LPCTSTR szModule) // Path to the typelib. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - WCHAR szID[64]; // The typelib ID to register. - WCHAR szTLBID[256]; // TypeLib\\szID. - WCHAR szHelpDir[_MAX_PATH]; - WCHAR szDrive[_MAX_DRIVE] = {0}; - WCHAR szDir[_MAX_DIR] = {0}; - WCHAR szVersion[64]; - LPWSTR szTmp; - - // Create some base key strings. - GuidToLPWSTR(rtlbid, szID, NumItems(szID)); - - _tcscpy_s(szTLBID, _countof(szTLBID), W("TypeLib\\")); - _tcscat_s(szTLBID, _countof(szTLBID), szID); - - VERIFY(_snwprintf_s(szVersion, _countof(szVersion), _TRUNCATE, W("%d.0"), iVersion)); - - // Create Typelib keys. - SetKeyAndValue(szTLBID, NULL, NULL); - SetKeyAndValue(szTLBID, szVersion, szDesc); - _tcscat_s(szTLBID, _countof(szTLBID), W("\\")); - _tcscat_s(szTLBID, _countof(szTLBID), szVersion); - SetKeyAndValue(szTLBID, W("0"), NULL); - SetKeyAndValue(szTLBID, W("0\\win32"), szModule); - SetKeyAndValue(szTLBID, W("FLAGS"), W("0")); - SplitPath(szModule, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, NULL, 0, NULL, 0); - _tcscpy_s(szHelpDir, _countof(szHelpDir), szDrive); - if ((szTmp = CharPrev(szDir, szDir + Wszlstrlen(szDir))) != NULL) - *szTmp = '\0'; - _tcscat_s(szHelpDir, _countof(szHelpDir), szDir); - SetKeyAndValue(szTLBID, W("HELPDIR"), szHelpDir); - return (S_OK); -} - - -//***************************************************************************** -// Remove the registry keys for a type library. -//***************************************************************************** -HRESULT REGUTIL::UnregisterTypeLib( // Return code. - REFGUID rtlbid, // TypeLib ID we are registering. - int iVersion) // Typelib version. -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - WCHAR szID[64]; // The typelib ID to register. - WCHAR szTLBID[256]; // TypeLib\\szID. - WCHAR szTLBVersion[256]; // TypeLib\\szID\\szVersion - WCHAR szVersion[64]; - - // Create some base key strings. - GuidToLPWSTR(rtlbid, szID, NumItems(szID)); - - VERIFY(_snwprintf_s(szVersion, _countof(szVersion), _TRUNCATE, W("%d.0"), iVersion)); - - _tcscpy_s(szTLBID, _countof(szTLBID), W("TypeLib\\")); - _tcscat_s(szTLBID, _countof(szTLBID), szID); - _tcscpy_s(szTLBVersion, _countof(szTLBVersion), szTLBID); - _tcscat_s(szTLBVersion, _countof(szTLBVersion), W("\\")); - _tcscat_s(szTLBVersion, _countof(szTLBVersion), szVersion); - - // Delete Typelib keys. - DeleteKey(szTLBVersion, W("HELPDIR")); - DeleteKey(szTLBVersion, W("FLAGS")); - DeleteKey(szTLBVersion, W("0\\win32")); - DeleteKey(szTLBVersion, W("0")); - DeleteKey(szTLBID, szVersion); - WszRegDeleteKey(HKEY_CLASSES_ROOT, szTLBID); - return (0); -} - -#endif // !FEATURE_CORECLR // diff --git a/src/utilcode/sortversioning.cpp b/src/utilcode/sortversioning.cpp index 5420947842..65781cdc1a 100644 --- a/src/utilcode/sortversioning.cpp +++ b/src/utilcode/sortversioning.cpp @@ -136,230 +136,6 @@ namespace SortVersioning return i; } -#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) - //////////////////////////////////////////////////////////////////////////// - // - // LoadSortModuleAndInvariant() - // - // Attempts to load the given dll. If that is successful, attempts to - // load the invariant data. If that is successful, returns the module handle - // and the addresses of the SortGetHandle function and SortCloseHandle function - // - // failure is indicated by returning NULL for the module handle and the - // function addresses - // - //////////////////////////////////////////////////////////////////////////// - - HMODULE LoadSortModuleAndInvariant( - __in LPCWSTR sDllName, - __in DWORD dwVersion, - __out SORTGETHANDLE* ppGetHandle, - __out SORTCLOSEHANDLE* ppCloseHandle - ) - { - *ppGetHandle = NULL; - *ppCloseHandle = NULL; - HMODULE hSort; - - if(FAILED(UtilCode::LoadLibraryShim(sDllName, NULL, NULL, &hSort))) - { - return NULL; - } - - SORTGETHANDLE pGetHandle = (SORTGETHANDLE)GetProcAddress(hSort, "SortGetHandle"); - SORTCLOSEHANDLE pCloseHandle = (SORTCLOSEHANDLE)GetProcAddress(hSort, "SortCloseHandle"); - - // If we didn't load the procs, then remember that - if (pCloseHandle == NULL || pGetHandle == NULL) - { - ::FreeLibrary(hSort); - return NULL; - } - - // Verify that the data file's available - NLSVERSIONINFO sortVersion; - sortVersion.dwNLSVersionInfoSize = sizeof(NLSVERSIONINFO); - sortVersion.dwNLSVersion = dwVersion; - sortVersion.dwDefinedVersion = dwVersion; - - // Invariant must be there and is kinda common, so we'll just get it - PSORTHANDLE pSort = pGetHandle(W(""), &sortVersion, NULL); - if (!pSort) - { - // Yikes, invariant failed, forget about it. - ::FreeLibrary(hSort); - return NULL; - } - - // Since we found it, may as well remember it. - const SORTHANDLE * const pSortInHash = InsertSortHashNode(pSort); - - // If we got a different one back then free the one we added - if (pSortInHash != pSort && pSortInHash) - { - // We got a different one from the hash (someone beat us to the cache) - // so use that and discard the new one. - pCloseHandle(pSort); - } - - *ppGetHandle = pGetHandle; - *ppCloseHandle = pCloseHandle; - return hSort; - } - - // Attempts to load a Sort DLL. If this fails, the values of the __out parameters are unchanged. - __success(return) - BOOL LoadSortDllAndPublish( - __in LPCWSTR sDllName, - __in DWORD dwVersion, - __out __encoded_pointer SORTGETHANDLE* ppGetHandle, - __out __encoded_pointer SORTCLOSEHANDLE* ppCloseHandle, - __out HMODULE* phSortDll) - { - HMODULE hSortDll; - SORTGETHANDLE pGetHandle; - SORTCLOSEHANDLE pCloseHandle; - - hSortDll = LoadSortModuleAndInvariant(sDllName, dwVersion, &pGetHandle, &pCloseHandle); - - if(hSortDll != NULL) { - *phSortDll = hSortDll; - *ppGetHandle = (SORTGETHANDLE)EncodePointer(pGetHandle); - *ppCloseHandle = (SORTCLOSEHANDLE)EncodePointer(pCloseHandle); - return TRUE; - } - - return FALSE; - } - - //////////////////////////////////////////////////////////////////////////// - // - // GetSortGetHandle() - // - // Get the SortGetHandle() function for the proper dll version. - // - //////////////////////////////////////////////////////////////////////////// - SORTGETHANDLE GetSortGetHandle(__in DWORD dwVersion) - { - if(dwVersion == SORT_VERSION_DEFAULT) - { - // If we haven't tried to load the module/proc before do so now - if (g_hSortDefault == (HMODULE)-1) - { - LoadSortDllAndPublish(SORT_DEFAULT_DLL_NAME, SORT_VERSION_DEFAULT, &g_pDefaultGetHandle, &g_pDefaultCloseHandle, &g_hSortDefault); - } - - // This check is necessary because the LoadSortDllAndPublish call may have failed since some platforms - // won't have nlssorting.dll (e.g. Windows 8 and above). - if (g_hSortDefault != (HMODULE)-1) - { - return (SORTGETHANDLE)DecodePointer(g_pDefaultGetHandle); - } - } - - HMODULE* pHSortModule; - SORTGETHANDLE* ppGetHandle; - SORTCLOSEHANDLE* ppCloseHandle; - - if(dwVersion == SORT_VERSION_V4) - { - ppGetHandle = &g_pV4GetHandle; - ppCloseHandle = &g_pV4CloseHandle; - pHSortModule = &g_hSortCompatV4; - } - else if(dwVersion == SORT_VERSION_WHIDBEY) - { - ppGetHandle = &g_pV2GetHandle; - ppCloseHandle = &g_pV2CloseHandle; - pHSortModule = &g_hSortCompatV2; - } - else - { - // Unsupported sorting version. - return NULL; - } - - if(*pHSortModule == (HMODULE) -1) - { - // get module name - the module name should be "Sort"+dwVersion.ToString("x8")+".dll" - WCHAR moduleName[] = W("Sort00000000.dll"); - // replace the "00000000" with the hexadecimal of dwVersion - LPCWSTR hex = W("0123456789abcdef"); - WCHAR* p = &moduleName[4+8]; // position at end of number part of dll name - - unsigned int value = dwVersion; - - while (value != 0 && p != moduleName) { - int digit = value & 0xF; - *--p = hex[digit]; - value >>= 4; - } - - if(!LoadSortDllAndPublish(&moduleName[0], dwVersion, ppGetHandle, ppCloseHandle, pHSortModule)) - { - // We failed to load a versioned sort dll, try to fall back to the current version. - // If we haven't tried to load the module/proc before do so now - if (g_hSortDefault == (HMODULE)-1) - { - LoadSortDllAndPublish(SORT_DEFAULT_DLL_NAME, SORT_VERSION_DEFAULT, &g_pDefaultGetHandle, &g_pDefaultCloseHandle, &g_hSortDefault); - } - - *pHSortModule = g_hSortDefault; - *ppCloseHandle = g_pDefaultCloseHandle; - *ppGetHandle = g_pDefaultGetHandle; - } - } - - // At this point, we've either loaded a sorting dll or we've exausted all options. - if(*pHSortModule == (HMODULE) -1) - { - // Couldn't find anything, give up. - return NULL; - } - else - { - return (SORTGETHANDLE)DecodePointer(*ppGetHandle); - } - - // Unknown version requested - return NULL; - } - - void DoSortCloseHandle(__in DWORD dwVersion, __in PSORTHANDLE pSort) - { - if (dwVersion == SORT_VERSION_DEFAULT) - { - SORTCLOSEHANDLE pDefaultCloseHandle = (SORTCLOSEHANDLE)DecodePointer(g_pDefaultCloseHandle); - if(pDefaultCloseHandle != NULL) - { - (pDefaultCloseHandle)(pSort); - return; - } - } - - if (dwVersion == SORT_VERSION_V4) - { - SORTCLOSEHANDLE pV4CloseHandle = (SORTCLOSEHANDLE)DecodePointer(g_pV4CloseHandle); - if(pV4CloseHandle != NULL) - { - (pV4CloseHandle)(pSort); - return; - } - } - - - if (dwVersion == SORT_VERSION_WHIDBEY) - { - SORTCLOSEHANDLE pV2CloseHandle = (SORTCLOSEHANDLE)DecodePointer(g_pV2CloseHandle); - if(pV2CloseHandle != NULL) - { - (pV2CloseHandle)(pSort); - return; - } - } - } - -#else // !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) SORTGETHANDLE GetSortGetHandle(__in DWORD dwVersion) { @@ -370,7 +146,6 @@ namespace SortVersioning { } -#endif // !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) //////////////////////////////////////////////////////////////////////////// // @@ -663,26 +438,7 @@ namespace SortVersioning //////////////////////////////////////////////////////////////////////////// DWORD SortNLSVersion() { -#ifdef FEATURE_CORECLR return SORT_VERSION_DEFAULT; -#else - static bool sortNLSVersionConfigChecked = false; - static DWORD sortNLSVersion = SORT_VERSION_DEFAULT; - - if(!sortNLSVersionConfigChecked) - { - BEGIN_SO_INTOLERANT_CODE_NO_THROW_CHECK_THREAD(return false); - sortNLSVersion = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_CompatSortNLSVersion); - if(sortNLSVersion == 0) - { - sortNLSVersion = SORT_VERSION_DEFAULT; - } - END_SO_INTOLERANT_CODE; - - sortNLSVersionConfigChecked = true; - } - return sortNLSVersion; -#endif // !FEATURE_CORECLR } //////////////////////////////////////////////////////////////////////////// diff --git a/src/utilcode/stacktrace.cpp b/src/utilcode/stacktrace.cpp index 858fac723e..8fbc457019 100644 --- a/src/utilcode/stacktrace.cpp +++ b/src/utilcode/stacktrace.cpp @@ -949,7 +949,7 @@ void MagicDeinit(void) } } -#if defined(_TARGET_X86_) && defined(FEATURE_CORECLR) +#if defined(_TARGET_X86_) /**************************************************************************** * ClrCaptureContext * *-------------------* diff --git a/src/utilcode/stresslog.cpp b/src/utilcode/stresslog.cpp index d364b06dd6..91c5c0e8ef 100644 --- a/src/utilcode/stresslog.cpp +++ b/src/utilcode/stresslog.cpp @@ -608,12 +608,7 @@ FORCEINLINE BOOL StressLog::InlinedETWLogOn(unsigned facility, unsigned level) STATIC_CONTRACT_LEAF; STATIC_CONTRACT_SUPPORTS_DAC; -#if defined(FEATURE_EVENT_TRACE) && !defined(FEATURE_CORECLR) && !defined(DACCESS_COMPILE) - return ((Microsoft_Windows_DotNETRuntimeStressHandle != 0) && - (ETW_CATEGORY_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_STRESS_PROVIDER_Context, (UCHAR)level, facility) != 0)); -#else return FALSE; -#endif } BOOL StressLog::ETWLogOn(unsigned facility, unsigned level) @@ -671,28 +666,6 @@ void StressLog::LogMsg (unsigned level, unsigned facility, int cArgs, const char } // Stress Log ETW feature available only on the desktop versions of the runtime -#if !defined(FEATURE_CORECLR) - // The previous LogMsg call could have modified the Args, so we need to reset it - if(InlinedETWLogOn(facility, level)) - { -#define MAX_STRESSLOG_DATA_ETW_LENGTH 256 - CHAR logMessage[MAX_STRESSLOG_DATA_ETW_LENGTH]; - - va_start(Args, format); - ULONG messageLength = (USHORT)_vsnprintf_s(logMessage, COUNTOF(logMessage), MAX_STRESSLOG_DATA_ETW_LENGTH-1, format, Args); - va_end(Args); - - if(messageLength >= 0 && - messageLength < MAX_STRESSLOG_DATA_ETW_LENGTH) // this condition has been added to make prefast happy - { - logMessage[messageLength] = 0; - } - messageLength++; - logMessage[MAX_STRESSLOG_DATA_ETW_LENGTH-1] = 0; - FireEtwStressLogEvent_V1((UINT32)facility, (UCHAR)level, logMessage, GetClrInstanceId()); -#undef MAX_STRESSLOG_DATA_ETW_LENGTH - } -#endif // !FEATURE_CORECLR #endif //!DACCESS_COMPILE } diff --git a/src/utilcode/util.cpp b/src/utilcode/util.cpp index 45b5125206..67e353b359 100644 --- a/src/utilcode/util.cpp +++ b/src/utilcode/util.cpp @@ -19,9 +19,6 @@ #include "cor.h" #include "corinfo.h" -#ifndef FEATURE_CORECLR -#include "metahost.h" -#endif // !FEATURE_CORECLR const char g_RTMVersion[]= "v1.0.3705"; @@ -3269,114 +3266,6 @@ BOOL FileExists(LPCWSTR filename) return TRUE; } -#ifndef FEATURE_CORECLR -// Current users for FileLock are ngen and ngen service - -FileLockHolder::FileLockHolder() -{ - _hLock = INVALID_HANDLE_VALUE; -} - -FileLockHolder::~FileLockHolder() -{ - Release(); -} - -// the amount of time we want to wait -#define FILE_LOCK_RETRY_TIME 100 - -void FileLockHolder::Acquire(LPCWSTR lockName, HANDLE hInterrupt, BOOL* pInterrupted) -{ - WRAPPER_NO_CONTRACT; - - DWORD dwErr = 0; - DWORD dwAccessDeniedRetry = 0; - const DWORD MAX_ACCESS_DENIED_RETRIES = 10; - - if (pInterrupted) - { - *pInterrupted = FALSE; - } - - _ASSERTE(_hLock == INVALID_HANDLE_VALUE); - - for (;;) { - _hLock = WszCreateFile(lockName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); - if (_hLock != INVALID_HANDLE_VALUE) { - return; - } - - dwErr = GetLastError(); - // Logically we should only expect ERROR_SHARING_VIOLATION, but Windows can also return - // ERROR_ACCESS_DENIED for underlying NtStatus DELETE_PENDING. That happens when another process - // (gacutil.exe or indexer) have the file opened. Unfortunately there is no public API that would - // allow us to detect this NtStatus and distinguish it from 'real' access denied (candidates are - // RtlGetLastNtStatus that is not documented on MSDN and NtCreateFile that is internal and can change - // at any time), so we retry on access denied, but only for a limited number of times. - if (dwErr == ERROR_SHARING_VIOLATION || - (dwErr == ERROR_ACCESS_DENIED && ++dwAccessDeniedRetry <= MAX_ACCESS_DENIED_RETRIES)) - { - // Somebody is holding the lock. Let's sleep, and come back again. - if (hInterrupt) - { - _ASSERTE(pInterrupted && - "If you can be interrupted, you better want to know if you actually were interrupted"); - if (WaitForSingleObject(hInterrupt, FILE_LOCK_RETRY_TIME) == WAIT_OBJECT_0) - { - if (pInterrupted) - { - *pInterrupted = TRUE; - } - - // We've been interrupted, so return without acquiring - return; - } - } - else - { - ClrSleepEx(FILE_LOCK_RETRY_TIME, FALSE); - } - } - else { - ThrowHR(HRESULT_FROM_WIN32(dwErr)); - } - } -} - - -HRESULT FileLockHolder::AcquireNoThrow(LPCWSTR lockName, HANDLE hInterrupt, BOOL* pInterrupted) -{ - HRESULT hr = S_OK; - - EX_TRY - { - Acquire(lockName, hInterrupt, pInterrupted); - } - EX_CATCH_HRESULT(hr); - - return hr; -} - -BOOL FileLockHolder::IsTaken(LPCWSTR lockName) -{ - - // We don't want to do an acquire the lock to know if its taken, so we want to see if the file - // exists. However, in situations like unplugging a machine, a DELETE_ON_CLOSE still leaves the file - // around. We try to delete it here. If the lock is acquired, DeleteFile will fail, as the file is - // not opened with SHARE_DELETE. - WszDeleteFile(lockName); - - return FileExists(lockName); -} - -void FileLockHolder::Release() -{ - if (_hLock != INVALID_HANDLE_VALUE) { - CloseHandle(_hLock); - _hLock = INVALID_HANDLE_VALUE; - } -} -#endif // FEATURE_CORECLR //====================================================================== // This function returns true, if it can determine that the instruction pointer @@ -3534,59 +3423,6 @@ RUNTIMEVERSIONINFO RUNTIMEVERSIONINFO::notDefined; BOOL IsV2RuntimeLoaded(void) { -#ifndef FEATURE_CORECLR - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - CANNOT_TAKE_LOCK; - } - CONTRACTL_END; - - ReleaseHolder<ICLRMetaHost> pMetaHost(NULL); - ReleaseHolder<IEnumUnknown> pEnum(NULL); - ReleaseHolder<IUnknown> pUnk(NULL); - ReleaseHolder<ICLRRuntimeInfo> pRuntime(NULL); - HRESULT hr; - - HModuleHolder hModule = WszLoadLibrary(MSCOREE_SHIM_W); - if (hModule == NULL) - return FALSE; - - CLRCreateInstanceFnPtr pfnCLRCreateInstance = (CLRCreateInstanceFnPtr)::GetProcAddress(hModule, "CLRCreateInstance"); - if (pfnCLRCreateInstance == NULL) - return FALSE; - - hr = (*pfnCLRCreateInstance)(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID *)&pMetaHost); - if (FAILED(hr)) - return FALSE; - - hr = pMetaHost->EnumerateLoadedRuntimes(GetCurrentProcess(), &pEnum); - if (FAILED(hr)) - return FALSE; - - while (pEnum->Next(1, &pUnk, NULL) == S_OK) - { - hr = pUnk->QueryInterface(IID_ICLRRuntimeInfo, (void **)&pRuntime); - if (FAILED(hr)) - continue; - - WCHAR wszVersion[30]; - DWORD cchVersion = _countof(wszVersion); - hr = pRuntime->GetVersionString(wszVersion, &cchVersion); - if (FAILED(hr)) - continue; - - // Is it a V2 runtime? - if ((cchVersion < 3) || - ((wszVersion[0] != W('v')) && (wszVersion[0] != W('V'))) || - (wszVersion[1] != W('2')) || - (wszVersion[2] != W('.'))) - continue; - - return TRUE; - } -#endif // FEATURE_CORECLR return FALSE; } @@ -3610,54 +3446,6 @@ BOOL IsClrHostedLegacyComObject(REFCLSID rclsid) -#if !defined(FEATURE_CORECLR) && !defined(SELF_NO_HOST) && !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) - -namespace UtilCode -{ - -#pragma warning(push) -#pragma warning(disable:4996) // For use of deprecated LoadLibraryShim - - // When a NULL version is passed to LoadLibraryShim, this told the shim to bind the already-loaded - // runtime or to the latest runtime. In hosted environments, we already know a runtime (or two) is - // loaded, and since we are no longer guaranteed that a call to mscoree!LoadLibraryShim with a NULL - // version will return the correct runtime, this code uses the ClrCallbacks infrastructure - // available to get the ICLRRuntimeInfo for the runtime in which this code is hosted, and then - // calls ICLRRuntimeInfo::LoadLibrary to make sure that the load occurs within the context of the - // correct runtime. - HRESULT LoadLibraryShim(LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE *phModDll) - { - HRESULT hr = S_OK; - - if (szVersion != NULL) - { // If a version is provided, then we just fall back to the legacy function to allow - // it to construct the explicit path and load from that location. - //@TODO: Can we verify that all callers of LoadLibraryShim in hosted environments always pass null and eliminate this code? - return ::LoadLibraryShim(szDllName, szVersion, pvReserved, phModDll); - } - - // - // szVersion is NULL, which means we should load the DLL from the hosted environment's directory. - // - - typedef ICLRRuntimeInfo *GetCLRRuntime_t(); - GetCLRRuntime_t *pfnGetCLRRuntime = - reinterpret_cast<GetCLRRuntime_t *>((*GetClrCallbacks().m_pfnGetCLRFunction)("GetCLRRuntime")); - if (pfnGetCLRRuntime == NULL) - return E_UNEXPECTED; - - ICLRRuntimeInfo* pRI = (*pfnGetCLRRuntime)(); - if (pRI == NULL) - return E_UNEXPECTED; - - return pRI->LoadLibrary(szDllName, phModDll); - } - -#pragma warning(pop) - -} - -#endif //!FEATURE_CORECLR && !SELF_NO_HOST && !FEATURE_UTILCODE_NO_DEPENDENCIES namespace Clr { diff --git a/src/utilcode/utilmessagebox.cpp b/src/utilcode/utilmessagebox.cpp index 3d13489b84..899b12088a 100644 --- a/src/utilcode/utilmessagebox.cpp +++ b/src/utilcode/utilmessagebox.cpp @@ -19,29 +19,6 @@ #include "../dlls/mscorrc/resource.h" #include "ex.h" -#if !defined(SELF_NO_HOST) && !defined(FEATURE_CORECLR) - -// -// This should be used for runtime dialog box, because we assume the resource is from mscorrc.dll -// For tools like ildasm or Shim which uses their own resource file, you need to define IDS_RTL in -// their resource file and define a function like this and append the style returned from the function -// to every calls to WszMessageBox. -// -UINT GetCLRMBRTLStyle() -{ - WRAPPER_NO_CONTRACT; - - UINT mbStyle = 0; - WCHAR buff[MAX_LONGPATH]; - if(SUCCEEDED(UtilLoadStringRC(IDS_RTL, buff, MAX_LONGPATH, true))) { - if(wcscmp(buff, W("RTL_True")) == 0) { - mbStyle = 0x00080000 |0x00100000; // MB_RIGHT || MB_RTLREADING - } - } - return mbStyle; -} - -#endif //!defined(SELF_NO_HOST) && !defined(FEATURE_CORECLR) BOOL ShouldDisplayMsgBoxOnCriticalFailure() { @@ -263,9 +240,6 @@ int UtilMessageBoxNonLocalizedVA( // in use. However, outside the CLR (SELF_NO_HOST) we can't assume we have resources and // in CORECLR we can't even necessarily expect that our CLR callbacks have been initialized. // This code path is used for ASSERT dialogs. -#if !defined(SELF_NO_HOST) && !defined(FEATURE_CORECLR) - uType |= GetCLRMBRTLStyle(); -#endif result = MessageBoxImpl(hWnd, formattedMessage, formattedTitle, details, uType); |