* Remove cases where PEImage::m_path was mutated. Create m_pathHash field and remove function. Remove FEATURE_CASE_SENSITIVE_FILESYSTEM.
* Address contract violations
* Remove try/catch and replace with assert
---------
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
// Turn from bytes to wide characters
if (!pAssembly->GetPEAssembly()->GetPath().IsEmpty())
{
- if (!pAssembly->GetPEAssembly()->GetPath().
- DacGetUnicode(count, location, pNeeded))
+ if (!pAssembly->GetPEAssembly()->GetPath().DacGetUnicode(count, location, pNeeded))
{
hr = E_FAIL;
}
BOOL IsASCIIScanned() const;
void SetASCIIScanned() const;
void SetNormalized() const;
+public:
BOOL IsNormalized() const;
+private:
void ClearNormalized() const;
void EnsureWritable() const;
{
// If the name matches...
LPCWSTR pszName = pRegMeta->GetNameOfDBFile();
- #ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
- if (u16_strcmp(szName, pszName) == 0)
- #else
if (SString::_wcsicmp(szName, pszName) == 0)
- #endif
{
ULONG cRefs;
{
// If the name matches...
LPCWSTR pszName = pRegMeta->GetNameOfDBFile();
- #ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
- if (u16_strcmp(szName, pszName) == 0)
- #else
if (SString::_wcsicmp(szName, pszName) == 0)
- #endif
{
ULONG cRefs;
// if we failed to get the version info from the native image then fall back to the IL image.
if (!succeeded)
{
- LPCWSTR modulePath = pPEAssembly->GetPath().GetUnicode();
- if (modulePath != NULL && modulePath != SString::Empty() && SUCCEEDED(DwGetFileVersionInfo(modulePath, major, minor, build, revision)))
- {
- succeeded = true;
- }
+ const SString& modulePath = pPEAssembly->GetPath();
+ _ASSERTE(modulePath.IsNormalized());
+ succeeded = !modulePath.IsEmpty() && SUCCEEDED(DwGetFileVersionInfo(modulePath.GetUnicode(), major, minor, build, revision));
}
}
SString sAlcName;
pPEAssembly->GetAssemblyBinder()->GetNameForDiagnostics(sAlcName);
- if (pPEAssembly->GetPath().IsEmpty())
+ SString assemblyPath{ pPEAssembly->GetPath() };
+ if (assemblyPath.IsEmpty())
{
detailsUtf8.Printf("Type %s originates from '%s' in the context '%s' in a byte array",
sType.GetUTF8(),
sType.GetUTF8(),
sAssemblyDisplayName.GetUTF8(),
sAlcName.GetUTF8(),
- pPEAssembly->GetPath().GetUTF8());
+ assemblyPath.GetUTF8());
}
sAssemblyDetailInfo.Append(detailsUtf8.GetUnicode());
result=InterlockedDecrement(&m_refCount);
if (result == 0 )
{
- LOG((LF_LOADER, LL_INFO100, "PEImage: Closing Image %s\n", m_path.GetUTF8()));
+ LOG((LF_LOADER, LL_INFO100, "PEImage: Closing %p\n", this));
if(m_bInHashMap)
{
PEImageLocator locator(this);
- PEImage* deleted = (PEImage *)s_Images->DeleteValue(GetPathHash(), &locator);
+ PEImage* deleted = (PEImage *)s_Images->DeleteValue(m_pathHash, &locator);
_ASSERTE(deleted == this);
}
}
EX_TRY
{
SString path(SString::Literal, pLocator->m_pPath);
-
-#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
- if (pImage->GetPath().Equals(path))
-#else
if (pImage->GetPath().EqualsCaseInsensitive(path))
-#endif
{
ret = TRUE;
}
PEImage::PEImage():
m_path(),
+ m_pathHash(0),
m_refCount(1),
m_bInHashMap(FALSE),
m_bundleFileLocation(),
PTR_PEImageLayout GetLoadedLayout();
PTR_PEImageLayout GetFlatLayout();
- BOOL HasPath();
- ULONG GetPathHash();
const SString& GetPath();
const SString& GetPathToLoad();
LPCWSTR GetPathForErrorMessages() { return GetPath(); }
// ------------------------------------------------------------
SString m_path;
+ ULONG m_pathHash;
LONG m_refCount;
// means this is a unique (deduped) instance.
m_path = pPath;
m_path.Normalize();
+ m_pathHash = m_path.HashCaseInsensitive();
m_bundleFileLocation = bundleFileLocation;
SetModuleFileNameHintForDAC();
}
int CaseHashHelper(const WCHAR *buffer, COUNT_T count);
PEImageLocator locator(pPath, isInBundle);
-#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
- DWORD dwHash=path.Hash();
-#else
DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) u16_strlen(pPath));
-#endif
return (PEImage *) s_Images->LookupValue(dwHash, &locator);
}
CONTRACTL_END;
_ASSERTE(s_hashLock.OwnedByCurrentThread());
- s_Images->InsertValue(GetPathHash(),this);
+ s_Images->InsertValue(m_pathHash,this);
m_bInHashMap=TRUE;
}
return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->Has32BitNTHeaders();
}
-inline BOOL PEImage::HasPath()
-{
- LIMITED_METHOD_CONTRACT;
-
- return !GetPath().IsEmpty();
-}
-
-inline ULONG PEImage::GetPathHash()
-{
- CONTRACT(ULONG)
- {
- PRECONDITION(HasPath());
- MODE_ANY;
- GC_NOTRIGGER;
- THROWS;
- }
- CONTRACT_END;
-
-#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM
- RETURN m_path.Hash();
-#else
- RETURN m_path.HashCaseInsensitive();
-#endif
-}
-
inline void PEImage::GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine)
{
CONTRACTL
IfFailThrow(Init(m_Module, true));
- LOG((LF_LOADER, LL_INFO1000, "PEImage: Opened HMODULE %s\n", pOwner->GetPath().GetUTF8()));
+#ifdef LOGGING
+ SString ownerPath{ pOwner->GetPath() };
+ LOG((LF_LOADER, LL_INFO1000, "PEImage: Opened HMODULE %s\n", ownerPath.GetUTF8()));
+#endif // LOGGING
#else
HANDLE hFile = pOwner->GetFileHandle();
return;
}
+#ifdef LOGGING
+ SString ownerPath{ pOwner->GetPath() };
LOG((LF_LOADER, LL_INFO1000, "PEImage: image %s (hFile %p) mapped @ %p\n",
- pOwner->GetPath().GetUTF8(), hFile, (void*)m_LoadedFile));
+ ownerPath.GetUTF8(), hFile, (void*)m_LoadedFile));
+#endif // LOGGING
IfFailThrow(Init((void*)m_LoadedFile));
INT64 offset = pOwner->GetOffset();
INT64 size = pOwner->GetSize();
- LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %s\n", pOwner->GetPath().GetUTF8()));
+#ifdef LOGGING
+ SString ownerPath{ pOwner->GetPath() };
+ LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %s\n", ownerPath.GetUTF8()));
+#endif // LOGGING
// If a size is not specified, load the whole file
if (size == 0)
if (r2rLogFile == NULL)
return;
- fprintf(r2rLogFile, "%s: \"%s\".\n", msg, pPEAssembly->GetPath().GetUTF8());
+ SString assemblyPath{ pPEAssembly->GetPath() };
+ fprintf(r2rLogFile, "%s: \"%s\".\n", msg, assemblyPath.GetUTF8());
fflush(r2rLogFile);
}
uint32_t count = ((uint8_t)typeGenericInfo & (uint8_t)ReadyToRunTypeGenericInfo::GenericCountMask);
if (count > 2)
foundResult = false;
-
+
if (!foundResult)
{
HENUMInternalHolder hEnumTyPars(pImport);
uint32_t count = ((uint8_t)typeGenericInfo & (uint8_t)ReadyToRunTypeGenericInfo::GenericCountMask);
if (count > 2)
foundResult = false;
-
+
if (!foundResult)
{
HENUMInternalHolder hEnumTyPars(pImport);