From b137d85468f55fe50168ef266fa8c82aea1dc08d Mon Sep 17 00:00:00 2001 From: "John Chen (CLR)" Date: Thu, 12 May 2016 10:02:33 -0700 Subject: [PATCH] Fix contract violations in Ready to Run code Commit migrated from https://github.com/dotnet/coreclr/commit/e732c0a3fe1649995e62d577a067d4f066c79b22 --- src/coreclr/src/vm/readytoruninfo.cpp | 2 +- src/coreclr/src/vm/typehashingalgorithms.h | 14 ++++++++++++++ src/coreclr/src/vm/versionresilienthashcode.cpp | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/vm/readytoruninfo.cpp b/src/coreclr/src/vm/readytoruninfo.cpp index ea49282..3636a8e 100644 --- a/src/coreclr/src/vm/readytoruninfo.cpp +++ b/src/coreclr/src/vm/readytoruninfo.cpp @@ -85,7 +85,7 @@ BOOL ReadyToRunInfo::TryLookupTypeTokenFromName(NameHandle *pName, mdToken * pFo CONTRACTL { GC_NOTRIGGER; - NOTHROW; + THROWS; SO_INTOLERANT; SUPPORTS_DAC; PRECONDITION(!m_availableTypesHashtable.IsNull()); diff --git a/src/coreclr/src/vm/typehashingalgorithms.h b/src/coreclr/src/vm/typehashingalgorithms.h index 9f3f3cd..c661451 100644 --- a/src/coreclr/src/vm/typehashingalgorithms.h +++ b/src/coreclr/src/vm/typehashingalgorithms.h @@ -14,6 +14,8 @@ // inline static int ComputeNameHashCode(LPCUTF8 src) { + LIMITED_METHOD_CONTRACT; + if (src == NULL || *src == '\0') return 0; @@ -39,6 +41,8 @@ inline static int ComputeNameHashCode(LPCUTF8 src) inline static int ComputeNameHashCode(LPCUTF8 pszNamespace, LPCUTF8 pszName) { + LIMITED_METHOD_CONTRACT; + // DIFFERENT FROM CORERT: CoreRT hashes the full name as one string ("namespace.name"), // as the full name is already available. In CoreCLR we normally only have separate // strings for namespace and name, thus we hash them separately. @@ -47,6 +51,8 @@ inline static int ComputeNameHashCode(LPCUTF8 pszNamespace, LPCUTF8 pszName) inline static int ComputeArrayTypeHashCode(int elementTypeHashcode, int rank) { + LIMITED_METHOD_CONTRACT; + // DIFFERENT FROM CORERT: This is much simplified compared to CoreRT, to avoid converting.rank to string. // For single-dimensinal array, the result is identical to CoreRT. int hashCode = 0xd5313556 + rank; @@ -59,22 +65,30 @@ inline static int ComputeArrayTypeHashCode(int elementTypeHashcode, int rank) inline static int ComputePointerTypeHashCode(int pointeeTypeHashcode) { + LIMITED_METHOD_CONTRACT; + return (pointeeTypeHashcode + _rotl(pointeeTypeHashcode, 5)) ^ 0x12D0; } inline static int ComputeByrefTypeHashCode(int parameterTypeHashcode) { + LIMITED_METHOD_CONTRACT; + return (parameterTypeHashcode + _rotl(parameterTypeHashcode, 7)) ^ 0x4C85; } inline static int ComputeNestedTypeHashCode(int enclosingTypeHashcode, int nestedTypeNameHash) { + LIMITED_METHOD_CONTRACT; + return (enclosingTypeHashcode + _rotl(enclosingTypeHashcode, 11)) ^ nestedTypeNameHash; } template inline static int ComputeGenericInstanceHashCode(int definitionHashcode, int arity, const TA& genericTypeArguments, int (*getHashCode)(TB)) { + LIMITED_METHOD_CONTRACT; + int hashcode = definitionHashcode; for (int i = 0; i < arity; i++) { diff --git a/src/coreclr/src/vm/versionresilienthashcode.cpp b/src/coreclr/src/vm/versionresilienthashcode.cpp index 277bb93..b48991f 100644 --- a/src/coreclr/src/vm/versionresilienthashcode.cpp +++ b/src/coreclr/src/vm/versionresilienthashcode.cpp @@ -8,6 +8,15 @@ int GetVersionResilientTypeHashCode(IMDInternalImport *pMDImport, mdExportedType token) { + CONTRACTL + { + THROWS; + GC_NOTRIGGER; + SO_TOLERANT; + MODE_ANY; + } + CONTRACTL_END + _ASSERTE(TypeFromToken(token) == mdtTypeDef || TypeFromToken(token) == mdtTypeRef || TypeFromToken(token) == mdtExportedType); @@ -63,6 +72,8 @@ int GetVersionResilientTypeHashCode(IMDInternalImport *pMDImport, mdExportedType #ifndef DACCESS_COMPILE int GetVersionResilientTypeHashCode(TypeHandle type) { + STANDARD_VM_CONTRACT; + if (!type.IsTypeDesc()) { MethodTable *pMT = type.AsMethodTable(); @@ -114,6 +125,8 @@ int GetVersionResilientTypeHashCode(TypeHandle type) int GetVersionResilientMethodHashCode(MethodDesc *pMD) { + STANDARD_VM_CONTRACT; + int hashCode = GetVersionResilientTypeHashCode(TypeHandle(pMD->GetMethodTable())); // Todo: Add signature to hash. -- 2.7.4