Fix contract violations in Ready to Run code
authorJohn Chen (CLR) <jochen@microsoft.com>
Thu, 12 May 2016 17:02:33 +0000 (10:02 -0700)
committerJohn Chen (CLR) <jochen@microsoft.com>
Thu, 12 May 2016 20:03:49 +0000 (13:03 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/e732c0a3fe1649995e62d577a067d4f066c79b22

src/coreclr/src/vm/readytoruninfo.cpp
src/coreclr/src/vm/typehashingalgorithms.h
src/coreclr/src/vm/versionresilienthashcode.cpp

index ea49282..3636a8e 100644 (file)
@@ -85,7 +85,7 @@ BOOL ReadyToRunInfo::TryLookupTypeTokenFromName(NameHandle *pName, mdToken * pFo
     CONTRACTL
     {
         GC_NOTRIGGER;
-        NOTHROW;
+        THROWS;
         SO_INTOLERANT;
         SUPPORTS_DAC;
         PRECONDITION(!m_availableTypesHashtable.IsNull());
index 9f3f3cd..c661451 100644 (file)
@@ -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 <typename TA, typename TB>
 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++)
     {
index 277bb93..b48991f 100644 (file)
@@ -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.