From a62cb372fb7edf1cf7d7b783bfa653f58dc68a7a Mon Sep 17 00:00:00 2001 From: Fadi Hanna Date: Wed, 30 Mar 2016 09:27:04 -0700 Subject: Fixing contracts violations, and adding missing contracts to some APIs. Changing native format reader failure mode to fail fast instead of throwing and exception. [tfs-changeset: 1591477] --- src/vm/clsload.hpp | 8 ++++++++ src/vm/nativeformatreader.h | 6 +++++- src/vm/readytoruninfo.cpp | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vm/clsload.hpp b/src/vm/clsload.hpp index ca561a8049..e2705ae2e4 100644 --- a/src/vm/clsload.hpp +++ b/src/vm/clsload.hpp @@ -87,18 +87,24 @@ public: const HashedTypeEntry& SetClassHashBasedEntryValue(EEClassHashEntry_t * pClassHashEntry) { + LIMITED_METHOD_CONTRACT; + m_EntryType = EntryType::IsHashedClassEntry; m_pClassHashEntry = dac_cast(pClassHashEntry); return *this; } EEClassHashEntry_t * GetClassHashBasedEntryValue() { + LIMITED_METHOD_CONTRACT; + _ASSERT(m_EntryType == EntryType::IsHashedClassEntry); return m_pClassHashEntry; } const HashedTypeEntry& SetTokenBasedEntryValue(mdTypeDef typeToken, Module * pModule) { + LIMITED_METHOD_CONTRACT; + m_EntryType = EntryType::IsHashedTokenEntry; m_TokenAndModulePair.m_TypeToken = typeToken; m_TokenAndModulePair.m_pModule = pModule; @@ -106,6 +112,8 @@ public: } const TokenTypeEntry& GetTokenBasedEntryValue() { + LIMITED_METHOD_CONTRACT; + _ASSERT(m_EntryType == EntryType::IsHashedTokenEntry); return m_TokenAndModulePair; } diff --git a/src/vm/nativeformatreader.h b/src/vm/nativeformatreader.h index cfebb498ca..a410884626 100644 --- a/src/vm/nativeformatreader.h +++ b/src/vm/nativeformatreader.h @@ -44,7 +44,11 @@ namespace NativeFormat void ThrowBadImageFormatException() { _ASSERTE(false); - ThrowHR(COR_E_BADIMAGEFORMAT); + +#ifndef DACCESS_COMPILE + // Failfast instead of throwing, to avoid violating NOTHROW contracts of callers + EEPOLICY_HANDLE_FATAL_ERROR(COR_E_BADIMAGEFORMAT); +#endif } uint EnsureOffsetInRange(uint offset, uint lookAhead) diff --git a/src/vm/readytoruninfo.cpp b/src/vm/readytoruninfo.cpp index d00db7150f..1faf820a1c 100644 --- a/src/vm/readytoruninfo.cpp +++ b/src/vm/readytoruninfo.cpp @@ -84,7 +84,7 @@ BOOL ReadyToRunInfo::TryLookupTypeTokenFromName(NameHandle *pName, mdToken * pFo { GC_NOTRIGGER; NOTHROW; - SO_TOLERANT; + SO_INTOLERANT; SUPPORTS_DAC; PRECONDITION(!m_availableTypesHashtable.IsNull()); } -- cgit v1.2.3