summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Chen (CLR) <jochen@microsoft.com>2016-05-12 10:02:33 -0700
committerJohn Chen (CLR) <jochen@microsoft.com>2016-05-12 13:03:49 -0700
commite732c0a3fe1649995e62d577a067d4f066c79b22 (patch)
treee32e1927ca57199f4ff58b33d5da3037e494db28
parent4678ac883a8eafa45246fff978a4756483e0f067 (diff)
downloadcoreclr-e732c0a3fe1649995e62d577a067d4f066c79b22.tar.gz
coreclr-e732c0a3fe1649995e62d577a067d4f066c79b22.tar.bz2
coreclr-e732c0a3fe1649995e62d577a067d4f066c79b22.zip
Fix contract violations in Ready to Run code
-rw-r--r--src/vm/readytoruninfo.cpp2
-rw-r--r--src/vm/typehashingalgorithms.h14
-rw-r--r--src/vm/versionresilienthashcode.cpp13
3 files changed, 28 insertions, 1 deletions
diff --git a/src/vm/readytoruninfo.cpp b/src/vm/readytoruninfo.cpp
index ea49282922..3636a8ed7a 100644
--- a/src/vm/readytoruninfo.cpp
+++ b/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/vm/typehashingalgorithms.h b/src/vm/typehashingalgorithms.h
index 9f3f3cd37a..c661451eff 100644
--- a/src/vm/typehashingalgorithms.h
+++ b/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 <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++)
{
diff --git a/src/vm/versionresilienthashcode.cpp b/src/vm/versionresilienthashcode.cpp
index 277bb93655..b48991fccc 100644
--- a/src/vm/versionresilienthashcode.cpp
+++ b/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.