diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs index 74849de7d1ed8..fda6459b2551d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs @@ -30,9 +30,6 @@ internal RuntimeType[] GetDefinedTypes() { return GetTypes(this); } - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern bool IsResource(RuntimeModule module); #endregion #region Module overrides @@ -472,7 +469,8 @@ public override Guid ModuleVersionId public override bool IsResource() { - return IsResource(this); + // CoreClr does not support resource-only modules. + return false; } [RequiresUnreferencedCode("Fields might be removed")] diff --git a/src/coreclr/binder/bindertracing.cpp b/src/coreclr/binder/bindertracing.cpp index b03eb2f66db5f..499e20d928887 100644 --- a/src/coreclr/binder/bindertracing.cpp +++ b/src/coreclr/binder/bindertracing.cpp @@ -147,12 +147,12 @@ namespace DomainAssembly *parentAssembly = spec->GetParentAssembly(); if (parentAssembly != nullptr) { - PEAssembly *peAssembly = parentAssembly->GetFile(); - _ASSERTE(peAssembly != nullptr); - peAssembly->GetDisplayName(request.RequestingAssembly); + PEAssembly *pPEAssembly = parentAssembly->GetPEAssembly(); + _ASSERTE(pPEAssembly != nullptr); + pPEAssembly->GetDisplayName(request.RequestingAssembly); AppDomain *domain = parentAssembly->GetAppDomain(); - AssemblyBinder *binder = peAssembly->GetAssemblyBinder(); + AssemblyBinder *binder = pPEAssembly->GetAssemblyBinder(); GetAssemblyLoadContextNameFromBinder(binder, domain, request.RequestingAssemblyLoadContext); } diff --git a/src/coreclr/debug/createdump/crashinfo.cpp b/src/coreclr/debug/createdump/crashinfo.cpp index 8ab327eb15578..72ad06c51b521 100644 --- a/src/coreclr/debug/createdump/crashinfo.cpp +++ b/src/coreclr/debug/createdump/crashinfo.cpp @@ -320,7 +320,7 @@ CrashInfo::EnumerateManagedModules(IXCLRDataProcess* pClrDataProcess) if (SUCCEEDED(hr = moduleData.Request(pClrDataModule.GetPtr()))) { TRACE("MODULE: %" PRIA PRIx64 " dyn %d inmem %d file %d pe %" PRIA PRIx64 " pdb %" PRIA PRIx64, (uint64_t)moduleData.LoadedPEAddress, moduleData.IsDynamic, - moduleData.IsInMemory, moduleData.IsFileLayout, (uint64_t)moduleData.PEFile, (uint64_t)moduleData.InMemoryPdbAddress); + moduleData.IsInMemory, moduleData.IsFileLayout, (uint64_t)moduleData.PEAssembly, (uint64_t)moduleData.InMemoryPdbAddress); if (!moduleData.IsDynamic && moduleData.LoadedPEAddress != 0) { diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 0630cfa710a37..35b834542c91c 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -679,11 +679,6 @@ MetaEnum::New(Module* mod, *handle = TO_CDENUM(NULL); } - if (!mod->GetFile()->HasMetadata()) - { - return S_FALSE; - } - metaEnum = new (nothrow) MetaEnum; if (!metaEnum) { @@ -4079,9 +4074,9 @@ ClrDataAccess::GetModuleByAddress( { TADDR base; ULONG32 length; - PEFile* file = modDef->GetFile(); + PEAssembly* pPEAssembly = modDef->GetPEAssembly(); - if ((base = PTR_TO_TADDR(file->GetLoadedImageContents(&length)))) + if ((base = PTR_TO_TADDR(pPEAssembly->GetLoadedImageContents(&length)))) { if (TO_CDADDR(base) <= address && TO_CDADDR(base + length) > address) @@ -4133,9 +4128,9 @@ ClrDataAccess::StartEnumMethodDefinitionsByAddress( { TADDR base; ULONG32 length; - PEFile* file = modDef->GetFile(); + PEAssembly* assembly = modDef->GetPEAssembly(); - if ((base = PTR_TO_TADDR(file->GetLoadedImageContents(&length)))) + if ((base = PTR_TO_TADDR(assembly->GetLoadedImageContents(&length)))) { if (TO_CDADDR(base) <= address && TO_CDADDR(base + length) > address) @@ -6459,7 +6454,7 @@ ClrDataAccess::GetHostGcNotificationTable() } /* static */ bool -ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEFile *pPEFile, +ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEAssembly *pPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, DWORD &dwDataSize, @@ -6477,7 +6472,7 @@ ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEFile *pPEFile, isNGEN = false; if (pDir == NULL || pDir->Size == 0) { - mdImage = pPEFile->GetILimage(); + mdImage = pPEAssembly->GetPEImage(); if (mdImage != NULL) { layout = mdImage->GetLoadedLayout(); @@ -6526,7 +6521,7 @@ ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEFile *pPEFile, } /* static */ -bool ClrDataAccess::GetILImageInfoFromNgenPEFile(PEFile *peFile, +bool ClrDataAccess::GetILImageInfoFromNgenPEFile(PEAssembly *pPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, __out_ecount(cchFilePath) LPWSTR wszFilePath, @@ -6536,10 +6531,10 @@ bool ClrDataAccess::GetILImageInfoFromNgenPEFile(PEFile *peFile, DWORD dwWritten = 0; // use the IL File name - if (!peFile->GetPath().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten))) + if (!pPEAssembly->GetPath().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten))) { // Use DAC hint to retrieve the IL name. - peFile->GetModuleFileNameHint().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten)); + pPEAssembly->GetModuleFileNameHint().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten)); } dwTimeStamp = 0; dwSize = 0; @@ -6603,7 +6598,7 @@ bool ClrDataAccess::GetILImageNameFromNgenImage( LPCWSTR ilExtension, #endif // FEATURE_CORESYSTEM void * -ClrDataAccess::GetMetaDataFromHost(PEFile* peFile, +ClrDataAccess::GetMetaDataFromHost(PEAssembly* pPEAssembly, bool* isAlternate) { DWORD imageTimestamp, imageSize, dataSize; @@ -6634,7 +6629,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile, // so the field remains for now. if (!ClrDataAccess::GetMetaDataFileInfoFromPEFile( - peFile, + pPEAssembly, imageTimestamp, imageSize, dataSize, @@ -6647,7 +6642,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile, } // try direct match for the image that is loaded into the managed process - peFile->GetLoadedMetadata((COUNT_T *)(&dataSize)); + pPEAssembly->GetLoadedMetadata((COUNT_T *)(&dataSize)); DWORD allocSize = 0; if (!ClrSafeInt::addition(dataSize, sizeof(DAC_INSTANCE), allocSize)) @@ -6665,7 +6660,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile, buffer = (void*)(inst + 1); // APIs implemented by hosting debugger. It can use the path/filename, timestamp, and - // file size to find an exact match for the image. If that fails for an ngen'ed image, + // pPEAssembly size to find an exact match for the image. If that fails for an ngen'ed image, // we can request the IL image which it came from. if (m_legacyMetaDataLocator) { @@ -6701,7 +6696,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile, // isAlt = true; if (!ClrDataAccess::GetILImageInfoFromNgenPEFile( - peFile, + pPEAssembly, imageTimestamp, imageSize, uniPath, @@ -6781,13 +6776,13 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile, //++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // -// Given a PEFile or a ReflectionModule try to find the corresponding metadata +// Given a PEAssembly or a ReflectionModule try to find the corresponding metadata // We will first ask debugger to locate it. If fail, we will try // to get it from the target process // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++ IMDInternalImport* -ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflectionModule, bool throwEx) +ClrDataAccess::GetMDImport(const PEAssembly* pPEAssembly, const ReflectionModule* reflectionModule, bool throwEx) { HRESULT status; PTR_CVOID mdBaseTarget = NULL; @@ -6796,22 +6791,22 @@ ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflect PVOID mdBaseHost = NULL; bool isAlternate = false; - _ASSERTE((peFile == NULL && reflectionModule != NULL) || (peFile != NULL && reflectionModule == NULL)); - TADDR peFileAddr = (peFile != NULL) ? dac_cast(peFile) : dac_cast(reflectionModule); + _ASSERTE((pPEAssembly == NULL && reflectionModule != NULL) || (pPEAssembly != NULL && reflectionModule == NULL)); + TADDR peAssemblyAddr = (pPEAssembly != NULL) ? dac_cast(pPEAssembly) : dac_cast(reflectionModule); // // Look for one we've already created. // - mdImport = m_mdImports.Get(peFileAddr); + mdImport = m_mdImports.Get(peAssemblyAddr); if (mdImport != NULL) { return mdImport; } - if (peFile != NULL) + if (pPEAssembly != NULL) { // Get the metadata size - mdBaseTarget = ((PEFile*)peFile)->GetLoadedMetadata(&mdSize); + mdBaseTarget = const_cast(pPEAssembly)->GetLoadedMetadata(&mdSize); } else if (reflectionModule != NULL) { @@ -6862,12 +6857,12 @@ ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflect } // Try to see if debugger can locate it - if (peFile != NULL && mdBaseHost == NULL && (m_target3 || m_legacyMetaDataLocator)) + if (pPEAssembly != NULL && mdBaseHost == NULL && (m_target3 || m_legacyMetaDataLocator)) { // We couldn't read the metadata from memory. Ask // the target for metadata as it may be able to // provide it from some alternate means. - mdBaseHost = GetMetaDataFromHost(const_cast(peFile), &isAlternate); + mdBaseHost = GetMetaDataFromHost(const_cast(pPEAssembly), &isAlternate); } if (mdBaseHost == NULL) @@ -6902,7 +6897,7 @@ ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflect // The m_mdImports list does get cleaned up by calls to ClrDataAccess::Flush, // i.e. every time the process changes state. - if (m_mdImports.Add(peFileAddr, mdImport, isAlternate) == NULL) + if (m_mdImports.Add(peAssemblyAddr, mdImport, isAlternate) == NULL) { mdImport->Release(); DacError(E_OUTOFMEMORY); @@ -6970,9 +6965,9 @@ HRESULT ClrDataAccess::VerifyDlls() } // Read the debug directory timestamp from the target mscorwks image using DAC - // Note that we don't use the PE timestamp because the PE file might be changed in ways + // Note that we don't use the PE timestamp because the PE pPEAssembly might be changed in ways // that don't effect the PDB (and therefore don't effect DAC). Specifically, we rebase - // our DLLs at the end of a build, that changes the PE file, but not the PDB. + // our DLLs at the end of a build, that changes the PE pPEAssembly, but not the PDB. // Note that if we wanted to be extra careful, we could read the CV contents (which includes // the GUID signature) and verify it matches. Using the timestamp is useful for helpful error // messages, and should be sufficient in any real scenario. diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index 855ec4ad22058..ee390fa5bd92b 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -272,7 +272,7 @@ DacDbiInterfaceImpl::DacDbiInterfaceImpl( ) : ClrDataAccess(pTarget), m_pAllocator(pAllocator), m_pMetaDataLookup(pMetaDataLookup), - m_pCachedPEFile(VMPTR_PEFile::NullPtr()), + m_pCachedPEAssembly(VMPTR_PEAssembly::NullPtr()), m_pCachedImporter(NULL), m_isCachedHijackFunctionValid(FALSE) { @@ -307,7 +307,7 @@ DacDbiInterfaceImpl::~DacDbiInterfaceImpl() // Called from DAC-ized code to get a IMDInternalImport // // Arguments: -// pPEFile - PE file for which to get importer for +// pPEAssembly - PE file for which to get importer for // fThrowEx - if true, throw instead of returning NULL. // // Returns: @@ -324,7 +324,7 @@ DacDbiInterfaceImpl::~DacDbiInterfaceImpl() // This is an Internal importer, not a public Metadata importer. // interface IMDInternalImport* DacDbiInterfaceImpl::GetMDImport( - const PEFile* pPEFile, + const PEAssembly* pPEAssembly, const ReflectionModule * pReflectionModule, bool fThrowEx) { @@ -335,23 +335,23 @@ interface IMDInternalImport* DacDbiInterfaceImpl::GetMDImport( IDacDbiInterface::IMetaDataLookup * pLookup = m_pMetaDataLookup; _ASSERTE(pLookup != NULL); - VMPTR_PEFile vmPEFile = VMPTR_PEFile::NullPtr(); + VMPTR_PEAssembly vmPEAssembly = VMPTR_PEAssembly::NullPtr(); - if (pPEFile != NULL) + if (pPEAssembly != NULL) { - vmPEFile.SetHostPtr(pPEFile); + vmPEAssembly.SetHostPtr(pPEAssembly); } else if (pReflectionModule != NULL) { // SOS and ClrDataAccess rely on special logic to find the metadata for methods in dynamic modules. // We don't need to. The RS has already taken care of the special logic for us. - // So here we just grab the PEFile off of the ReflectionModule and continue down the normal + // So here we just grab the PEAssembly off of the ReflectionModule and continue down the normal // code path. See code:ClrDataAccess::GetMDImport for comparison. - vmPEFile.SetHostPtr(pReflectionModule->GetFile()); + vmPEAssembly.SetHostPtr(pReflectionModule->GetPEAssembly()); } // Optimize for the case where the VM queries the same Importer many times in a row. - if (m_pCachedPEFile == vmPEFile) + if (m_pCachedPEAssembly == vmPEAssembly) { return m_pCachedImporter; } @@ -370,7 +370,7 @@ interface IMDInternalImport* DacDbiInterfaceImpl::GetMDImport( // To get the old codepath that uses the v2 metadata lookup methods, // you'd have to load DAC only and then you'll get ClrDataAccess's implementation // of this function. - pInternal = pLookup->LookupMetaData(vmPEFile, isILMetaDataForNI); + pInternal = pLookup->LookupMetaData(vmPEAssembly, isILMetaDataForNI); } EX_CATCH { @@ -397,7 +397,7 @@ interface IMDInternalImport* DacDbiInterfaceImpl::GetMDImport( else { // Cache it such that it we look for the exact same Importer again, we'll return it. - m_pCachedPEFile = vmPEFile; + m_pCachedPEAssembly = vmPEAssembly; m_pCachedImporter = pInternal; } @@ -445,7 +445,7 @@ HRESULT DacDbiInterfaceImpl::FlushCache() // That would remove host DAC instances while they're being used. DD_NON_REENTRANT_MAY_THROW; - m_pCachedPEFile = VMPTR_PEFile::NullPtr(); + m_pCachedPEAssembly = VMPTR_PEAssembly::NullPtr(); m_pCachedImporter = NULL; m_isCachedHijackFunctionValid = FALSE; @@ -1227,7 +1227,7 @@ mdSignature DacDbiInterfaceImpl::GetILCodeAndSigHelper(Module * pModule, } -bool DacDbiInterfaceImpl::GetMetaDataFileInfoFromPEFile(VMPTR_PEFile vmPEFile, +bool DacDbiInterfaceImpl::GetMetaDataFileInfoFromPEFile(VMPTR_PEAssembly vmPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, bool &isNGEN, @@ -1237,14 +1237,14 @@ bool DacDbiInterfaceImpl::GetMetaDataFileInfoFromPEFile(VMPTR_PEFile vmPEFile, DWORD dwDataSize; DWORD dwRvaHint; - PEFile * pPEFile = vmPEFile.GetDacPtr(); - _ASSERTE(pPEFile != NULL); - if (pPEFile == NULL) + PEAssembly * pPEAssembly = vmPEAssembly.GetDacPtr(); + _ASSERTE(pPEAssembly != NULL); + if (pPEAssembly == NULL) return false; WCHAR wszFilePath[MAX_LONGPATH] = {0}; DWORD cchFilePath = MAX_LONGPATH; - bool ret = ClrDataAccess::GetMetaDataFileInfoFromPEFile(pPEFile, + bool ret = ClrDataAccess::GetMetaDataFileInfoFromPEFile(pPEAssembly, dwTimeStamp, dwSize, dwDataSize, @@ -1258,7 +1258,7 @@ bool DacDbiInterfaceImpl::GetMetaDataFileInfoFromPEFile(VMPTR_PEFile vmPEFile, } -bool DacDbiInterfaceImpl::GetILImageInfoFromNgenPEFile(VMPTR_PEFile vmPEFile, +bool DacDbiInterfaceImpl::GetILImageInfoFromNgenPEFile(VMPTR_PEAssembly vmPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, IStringHolder* pStrFilename) @@ -4137,16 +4137,16 @@ BOOL DacDbiInterfaceImpl::GetModulePath(VMPTR_Module vmModule, DD_ENTER_MAY_THROW; Module * pModule = vmModule.GetDacPtr(); - PEFile * pFile = pModule->GetFile(); - if (pFile != NULL) + PEAssembly * pPEAssembly = pModule->GetPEAssembly(); + if (pPEAssembly != NULL) { - if( !pFile->GetPath().IsEmpty() ) + if( !pPEAssembly->GetPath().IsEmpty() ) { // Module has an on-disk path - const WCHAR * szPath = pFile->GetPath().DacGetRawUnicode(); + const WCHAR * szPath = pPEAssembly->GetPath().DacGetRawUnicode(); if (szPath == NULL) { - szPath = pFile->GetModuleFileNameHint().DacGetRawUnicode(); + szPath = pPEAssembly->GetModuleFileNameHint().DacGetRawUnicode(); if (szPath == NULL) { goto NoFileName; @@ -4198,12 +4198,12 @@ HRESULT DacDbiInterfaceImpl::IsModuleMapped(VMPTR_Module pModule, OUT BOOL *isMo EX_TRY { - PTR_PEFile pPEFile = pTargetModule->GetFile(); - _ASSERTE(pPEFile != NULL); + PTR_PEAssembly pPEAssembly = pTargetModule->GetPEAssembly(); + _ASSERTE(pPEAssembly != NULL); - if (pPEFile->HasLoadedIL()) + if (pPEAssembly->HasLoadedPEImage()) { - *isModuleMapped = pPEFile->GetLoadedIL()->IsMapped(); + *isModuleMapped = pPEAssembly->GetLoadedLayout()->IsMapped(); hr = S_OK; } } @@ -4296,11 +4296,11 @@ void DacDbiInterfaceImpl::GetMetadata(VMPTR_Module vmModule, TargetBuffer * pTar } else { - PEFile * pFile = pModule->GetFile(); + PEAssembly * pPEAssembly = pModule->GetPEAssembly(); // For non-dynamic modules, metadata is in the pe-image. COUNT_T size; - CORDB_ADDRESS address = PTR_TO_CORDB_ADDRESS(dac_cast(pFile->GetLoadedMetadata(&size))); + CORDB_ADDRESS address = PTR_TO_CORDB_ADDRESS(dac_cast(pPEAssembly->GetLoadedMetadata(&size))); pTargetBuffer->Init(address, (ULONG) size); } @@ -4386,9 +4386,9 @@ void DacDbiInterfaceImpl::GetModuleData(VMPTR_Module vmModule, ModuleInfo * pDat ZeroMemory(pData, sizeof(*pData)); Module * pModule = vmModule.GetDacPtr(); - PEFile * pFile = pModule->GetFile(); + PEAssembly * pPEAssembly = pModule->GetPEAssembly(); - pData->vmPEFile.SetHostPtr(pFile); + pData->vmPEAssembly.SetHostPtr(pPEAssembly); pData->vmAssembly.SetHostPtr(pModule->GetAssembly()); // Is it dynamic? @@ -4403,15 +4403,15 @@ void DacDbiInterfaceImpl::GetModuleData(VMPTR_Module vmModule, ModuleInfo * pDat if (!fIsDynamic) { COUNT_T size = 0; - pData->pPEBaseAddress = PTR_TO_TADDR(pFile->GetDebuggerContents(&size)); + pData->pPEBaseAddress = PTR_TO_TADDR(pPEAssembly->GetDebuggerContents(&size)); pData->nPESize = (ULONG) size; } // In-memory is determined by whether the module has a filename. pData->fInMemory = FALSE; - if (pFile != NULL) + if (pPEAssembly != NULL) { - pData->fInMemory = pFile->GetPath().IsEmpty(); + pData->fInMemory = pPEAssembly->GetPath().IsEmpty(); } } @@ -7316,13 +7316,13 @@ void DacDbiInterfaceImpl::GetGCHeapInformation(COR_HEAPINFO * pHeapInfo) } -HRESULT DacDbiInterfaceImpl::GetPEFileMDInternalRW(VMPTR_PEFile vmPEFile, OUT TADDR* pAddrMDInternalRW) +HRESULT DacDbiInterfaceImpl::GetPEFileMDInternalRW(VMPTR_PEAssembly vmPEAssembly, OUT TADDR* pAddrMDInternalRW) { DD_ENTER_MAY_THROW; if (pAddrMDInternalRW == NULL) return E_INVALIDARG; - PEFile * pPEFile = vmPEFile.GetDacPtr(); - *pAddrMDInternalRW = pPEFile->GetMDInternalRWAddress(); + PEAssembly * pPEAssembly = vmPEAssembly.GetDacPtr(); + *pAddrMDInternalRW = pPEAssembly->GetMDInternalRWAddress(); return S_OK; } diff --git a/src/coreclr/debug/daccess/dacdbiimpl.h b/src/coreclr/debug/daccess/dacdbiimpl.h index 3088ed007a717..e484a28008b0c 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.h +++ b/src/coreclr/debug/daccess/dacdbiimpl.h @@ -53,7 +53,7 @@ class DacDbiInterfaceImpl : // Overridden from ClrDataAccess. Gets an internal metadata importer for the file. virtual IMDInternalImport* GetMDImport( - const PEFile* pPEFile, + const PEAssembly* pPEAssembly, const ReflectionModule * pReflectionModule, bool fThrowEx); @@ -149,7 +149,7 @@ class DacDbiInterfaceImpl : HRESULT GetTypeLayout(COR_TYPEID id, COR_TYPE_LAYOUT *pLayout); HRESULT GetArrayLayout(COR_TYPEID id, COR_ARRAY_LAYOUT *pLayout); void GetGCHeapInformation(COR_HEAPINFO * pHeapInfo); - HRESULT GetPEFileMDInternalRW(VMPTR_PEFile vmPEFile, OUT TADDR* pAddrMDInternalRW); + HRESULT GetPEFileMDInternalRW(VMPTR_PEAssembly vmPEAssembly, OUT TADDR* pAddrMDInternalRW); HRESULT GetReJitInfo(VMPTR_Module vmModule, mdMethodDef methodTk, OUT VMPTR_ReJitInfo* pReJitInfo); HRESULT GetActiveRejitILCodeVersionNode(VMPTR_Module vmModule, mdMethodDef methodTk, OUT VMPTR_ILCodeVersionNode* pVmILCodeVersionNode); HRESULT GetReJitInfo(VMPTR_MethodDesc vmMethod, CORDB_ADDRESS codeStartAddress, OUT VMPTR_ReJitInfo* pReJitInfo); @@ -952,15 +952,15 @@ class DacDbiInterfaceImpl : IMetaDataLookup * m_pMetaDataLookup; - // Metadata lookups is just a property on the PEFile in the normal builds, + // Metadata lookups is just a property on the PEAssembly in the normal builds, // and so VM code tends to access the same metadata importer many times in a row. // Cache the most-recently used to avoid excessive redundant lookups. - // PEFile of Cached Importer. Invalidated between Flush calls. If this is Non-null, + // PEAssembly of Cached Importer. Invalidated between Flush calls. If this is Non-null, // then the importer is m_pCachedImporter, and we can avoid using IMetaDataLookup - VMPTR_PEFile m_pCachedPEFile; + VMPTR_PEAssembly m_pCachedPEAssembly; - // Value of cached importer, corresponds with m_pCachedPEFile. + // Value of cached importer, corresponds with m_pCachedPEAssembly. IMDInternalImport * m_pCachedImporter; // Value of cached hijack function list, corresponds to g_pDebugger->m_rgHijackFunction @@ -1104,13 +1104,13 @@ class DacDbiInterfaceImpl : public: // APIs for picking up the info needed for a debugger to look up an ngen image or IL image // from it's search path. - bool GetMetaDataFileInfoFromPEFile(VMPTR_PEFile vmPEFile, + bool GetMetaDataFileInfoFromPEFile(VMPTR_PEAssembly vmPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, bool &isNGEN, IStringHolder* pStrFilename); - bool GetILImageInfoFromNgenPEFile(VMPTR_PEFile vmPEFile, + bool GetILImageInfoFromNgenPEFile(VMPTR_PEAssembly vmPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, IStringHolder* pStrFilename); diff --git a/src/coreclr/debug/daccess/dacfn.cpp b/src/coreclr/debug/daccess/dacfn.cpp index c8ac208d6352c..e1b83aba17e20 100644 --- a/src/coreclr/debug/daccess/dacfn.cpp +++ b/src/coreclr/debug/daccess/dacfn.cpp @@ -1304,7 +1304,7 @@ DacSetMethodDescEnumerated(LPCVOID pMD) // This gets called from DAC-ized code in the VM. IMDInternalImport* -DacGetMDImport(const PEFile* peFile, bool throwEx) +DacGetMDImport(const PEAssembly* pPEAssembly, bool throwEx) { if (!g_dacImpl) { @@ -1312,7 +1312,7 @@ DacGetMDImport(const PEFile* peFile, bool throwEx) UNREACHABLE(); } - return g_dacImpl->GetMDImport(peFile, throwEx); + return g_dacImpl->GetMDImport(pPEAssembly, throwEx); } IMDInternalImport* diff --git a/src/coreclr/debug/daccess/dacimpl.h b/src/coreclr/debug/daccess/dacimpl.h index 62d99ec574929..84d560e73ec03 100644 --- a/src/coreclr/debug/daccess/dacimpl.h +++ b/src/coreclr/debug/daccess/dacimpl.h @@ -132,7 +132,7 @@ class ReflectionModule; struct DAC_MD_IMPORT { DAC_MD_IMPORT* next; // list link field - TADDR peFile; // a TADDR for a PEFile* or a ReflectionModule* + TADDR peFile; // a TADDR for a PEAssembly* or a ReflectionModule* IMDInternalImport* impl; // Associated metadata interface bool isAlternate; // for NGEN images set to true if the metadata corresponds to the IL image @@ -151,7 +151,7 @@ struct DAC_MD_IMPORT // This class maintains a cache of IMDInternalImport* and their corresponding -// source (a PEFile* or a ReflectionModule*), as a singly-linked list of +// source (a PEAssembly* or a ReflectionModule*), as a singly-linked list of // DAC_MD_IMPORT nodes. The cache is flushed whenever the process state changes // by calling its Flush() member function. class MDImportsCache @@ -1352,18 +1352,18 @@ class ClrDataAccess JITNotification* GetHostJitNotificationTable(); GcNotification* GetHostGcNotificationTable(); - void* GetMetaDataFromHost(PEFile* peFile, + void* GetMetaDataFromHost(PEAssembly* pPEAssembly, bool* isAlternate); virtual - interface IMDInternalImport* GetMDImport(const PEFile* peFile, + interface IMDInternalImport* GetMDImport(const PEAssembly* pPEAssembly, const ReflectionModule* reflectionModule, bool throwEx); - interface IMDInternalImport* GetMDImport(const PEFile* peFile, + interface IMDInternalImport* GetMDImport(const PEAssembly* pPEAssembly, bool throwEx) { - return GetMDImport(peFile, NULL, throwEx); + return GetMDImport(pPEAssembly, NULL, throwEx); } interface IMDInternalImport* GetMDImport(const ReflectionModule* reflectionModule, @@ -1501,7 +1501,7 @@ class ClrDataAccess public: // APIs for picking up the info needed for a debugger to look up an ngen image or IL image // from it's search path. - static bool GetMetaDataFileInfoFromPEFile(PEFile *pPEFile, + static bool GetMetaDataFileInfoFromPEFile(PEAssembly *pPEAssembly, DWORD &dwImageTimestamp, DWORD &dwImageSize, DWORD &dwDataSize, @@ -1510,7 +1510,7 @@ class ClrDataAccess __out_ecount(cchFilePath) LPWSTR wszFilePath, DWORD cchFilePath); - static bool GetILImageInfoFromNgenPEFile(PEFile *peFile, + static bool GetILImageInfoFromNgenPEFile(PEAssembly *pPEAssembly, DWORD &dwTimeStamp, DWORD &dwSize, __out_ecount(cchPath) LPWSTR wszPath, diff --git a/src/coreclr/debug/daccess/enummem.cpp b/src/coreclr/debug/daccess/enummem.cpp index f956151f7ce8e..1914d13a1c5fb 100644 --- a/src/coreclr/debug/daccess/enummem.cpp +++ b/src/coreclr/debug/daccess/enummem.cpp @@ -67,7 +67,7 @@ HRESULT ClrDataAccess::EnumMemCollectImages() ProcessModIter modIter; Module* modDef = NULL; HRESULT status = S_OK; - PEFile *file; + PEAssembly *assembly; TADDR pStartAddr = 0; ULONG32 ulSize = 0; ULONG32 ulSizeBlock; @@ -84,7 +84,7 @@ HRESULT ClrDataAccess::EnumMemCollectImages() EX_TRY { ulSize = 0; - file = modDef->GetFile(); + assembly = modDef->GetPEAssembly(); // We want to save any in-memory images. These show up like mapped files // and so would not be in a heap dump by default. Technically it's not clear we @@ -92,13 +92,11 @@ HRESULT ClrDataAccess::EnumMemCollectImages() // after-the-fact. But in-memory modules may be harder to track down at debug time // and people may have come to rely on this - so we'll include them for now. if ( - file->GetPath().IsEmpty() && // is in-memory - file->HasMetadata() && // skip resource assemblies - file->IsLoaded(FALSE) && // skip files not yet loaded - !file->IsDynamic()) // skip dynamic (GetLoadedIL asserts anyway) + assembly->GetPath().IsEmpty() && // is in-memory + assembly->HasLoadedPEImage()) // skip files not yet loaded or Dynamic { - pStartAddr = PTR_TO_TADDR(file->GetLoadedIL()->GetBase()); - ulSize = file->GetLoadedIL()->GetSize(); + pStartAddr = PTR_TO_TADDR(assembly->GetLoadedLayout()->GetBase()); + ulSize = assembly->GetLoadedLayout()->GetSize(); } // memory are mapped in in GetOsPageSize() size. @@ -609,7 +607,7 @@ HRESULT ClrDataAccess::EnumMemDumpModuleList(CLRDataEnumMemoryFlags flags) Module* modDef; TADDR base; ULONG32 length; - PEFile *file; + PEAssembly* assembly; TSIZE_T cbMemoryReported = m_cbMemoryReported; // @@ -635,8 +633,8 @@ HRESULT ClrDataAccess::EnumMemDumpModuleList(CLRDataEnumMemoryFlags flags) // To enable a debugger to check on whether a module is an NI or IL image, they need // the DOS header, PE headers, and IMAGE_COR20_HEADER for the Flags member. // We expose no API today to find this out. - PTR_PEFile pPEFile = modDef->GetFile(); - PEImage * pILImage = pPEFile->GetILimage(); + PTR_PEAssembly pPEAssembly = modDef->GetPEAssembly(); + PEImage * pILImage = pPEAssembly->GetPEImage(); // Implicitly gets the COR header. if ((pILImage) && (pILImage->HasLoadedLayout())) @@ -649,9 +647,9 @@ HRESULT ClrDataAccess::EnumMemDumpModuleList(CLRDataEnumMemoryFlags flags) EX_TRY { - file = modDef->GetFile(); - base = PTR_TO_TADDR(file->GetLoadedImageContents(&length)); - file->EnumMemoryRegions(flags); + assembly = modDef->GetPEAssembly(); + base = PTR_TO_TADDR(assembly->GetLoadedImageContents(&length)); + assembly->EnumMemoryRegions(flags); } EX_CATCH { diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 3deed09f70720..cfe0d16035bf4 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -1506,8 +1506,8 @@ ClrDataAccess::GetObjectClassName(CLRDATA_ADDRESS obj, unsigned int count, __out { // There is a case where metadata was unloaded and the AppendType call will fail. // This is when an AppDomain has been unloaded but not yet collected. - PEFile *pPEFile = mt->GetModule()->GetFile(); - if (pPEFile->GetILimage() == NULL) + PEAssembly *pPEAssembly = mt->GetModule()->GetPEAssembly(); + if (pPEAssembly->GetPEImage() == NULL) { if (pNeeded) *pNeeded = 16; @@ -1645,14 +1645,14 @@ ClrDataAccess::GetModuleData(CLRDATA_ADDRESS addr, struct DacpModuleData *Module ZeroMemory(ModuleData,sizeof(DacpModuleData)); ModuleData->Address = addr; - ModuleData->File = HOST_CDADDR(pModule->GetFile()); + ModuleData->PEAssembly = HOST_CDADDR(pModule->GetPEAssembly()); COUNT_T metadataSize = 0; - if (!pModule->GetFile()->IsDynamic()) + if (!pModule->GetPEAssembly()->IsDynamic()) { - ModuleData->ilBase = (CLRDATA_ADDRESS)(ULONG_PTR) pModule->GetFile()->GetIJWBase(); + ModuleData->ilBase = (CLRDATA_ADDRESS)(ULONG_PTR) pModule->GetPEAssembly()->GetIJWBase(); } - ModuleData->metadataStart = (CLRDATA_ADDRESS)dac_cast(pModule->GetFile()->GetLoadedMetadata(&metadataSize)); + ModuleData->metadataStart = (CLRDATA_ADDRESS)dac_cast(pModule->GetPEAssembly()->GetLoadedMetadata(&metadataSize)); ModuleData->metadataSize = (SIZE_T) metadataSize; ModuleData->bIsReflection = pModule->IsReflection(); @@ -1770,8 +1770,8 @@ ClrDataAccess::GetMethodTableName(CLRDATA_ADDRESS mt, unsigned int count, __out_ { // There is a case where metadata was unloaded and the AppendType call will fail. // This is when an AppDomain has been unloaded but not yet collected. - PEFile *pPEFile = pMT->GetModule()->GetFile(); - if (pPEFile->GetILimage() == NULL) + PEAssembly *pPEAssembly = pMT->GetModule()->GetPEAssembly(); + if (pPEAssembly->GetPEImage() == NULL) { if (pNeeded) *pNeeded = 16; @@ -2053,19 +2053,18 @@ ClrDataAccess::GetPEFileName(CLRDATA_ADDRESS addr, unsigned int count, __out_z _ return E_INVALIDARG; SOSDacEnter(); - PEFile* pPEFile = PTR_PEFile(TO_TADDR(addr)); + PEAssembly* pPEAssembly = PTR_PEAssembly(TO_TADDR(addr)); // Turn from bytes to wide characters - if (!pPEFile->GetPath().IsEmpty()) + if (!pPEAssembly->GetPath().IsEmpty()) { - if (!pPEFile->GetPath().DacGetUnicode(count, fileName, pNeeded)) + if (!pPEAssembly->GetPath().DacGetUnicode(count, fileName, pNeeded)) hr = E_FAIL; } - else if (!pPEFile->IsDynamic()) + else if (!pPEAssembly->IsDynamic()) { - PEAssembly *pAssembly = pPEFile->GetAssembly(); StackSString displayName; - pAssembly->GetDisplayName(displayName, 0); + pPEAssembly->GetDisplayName(displayName, 0); if (displayName.IsEmpty()) { @@ -2112,11 +2111,11 @@ ClrDataAccess::GetPEFileBase(CLRDATA_ADDRESS addr, CLRDATA_ADDRESS *base) SOSDacEnter(); - PEFile* pPEFile = PTR_PEFile(TO_TADDR(addr)); + PEAssembly* pPEAssembly = PTR_PEAssembly(TO_TADDR(addr)); // More fields later? - if (!pPEFile->IsDynamic()) - *base = TO_CDADDR(pPEFile->GetIJWBase()); + if (!pPEAssembly->IsDynamic()) + *base = TO_CDADDR(pPEAssembly->GetIJWBase()); else *base = NULL; @@ -4768,8 +4767,8 @@ HRESULT ClrDataAccess::GetAssemblyLoadContext(CLRDATA_ADDRESS methodTable, CLRDA PTR_MethodTable pMT = PTR_MethodTable(CLRDATA_ADDRESS_TO_TADDR(methodTable)); PTR_Module pModule = pMT->GetModule(); - PTR_PEFile pPEFile = pModule->GetFile(); - PTR_AssemblyBinder pBinder = pPEFile->GetAssemblyBinder(); + PTR_PEAssembly pPEAssembly = pModule->GetPEAssembly(); + PTR_AssemblyBinder pBinder = pPEAssembly->GetAssemblyBinder(); INT_PTR managedAssemblyLoadContextHandle = pBinder->GetManagedAssemblyLoadContext(); diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index 8989977880e2e..5c8c3d0152dcf 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -2414,12 +2414,12 @@ ClrDataModule::GetFileName( { COUNT_T _nameLen; - // Try to get the file name through GetPath. - // If the returned name is empty, then try to get the guessed module file name. - // The guessed file name is propogated from metadata's module name. + // Try to get the assembly name through GetPath. + // If the returned name is empty, then try to get the guessed module assembly name. + // The guessed assembly name is propogated from metadata's module name. // - if ((m_module->GetFile()->GetPath().DacGetUnicode(bufLen, name, &_nameLen) && name[0])|| - (m_module->GetFile()->GetModuleFileNameHint().DacGetUnicode(bufLen, name, &_nameLen) && name[0])) + if ((m_module->GetPEAssembly()->GetPath().DacGetUnicode(bufLen, name, &_nameLen) && name[0])|| + (m_module->GetPEAssembly()->GetModuleFileNameHint().DacGetUnicode(bufLen, name, &_nameLen) && name[0])) { if (nameLen) { @@ -2455,19 +2455,11 @@ ClrDataModule::GetVersionId( EX_TRY { - if (!m_module->GetFile()->HasMetadata()) + GUID mdVid; + status = m_module->GetMDImport()->GetScopeProps(NULL, &mdVid); + if (SUCCEEDED(status)) { - status = E_NOINTERFACE; - } - else - { - GUID mdVid; - - status = m_module->GetMDImport()->GetScopeProps(NULL, &mdVid); - if (SUCCEEDED(status)) - { - *vid = mdVid; - } + *vid = mdVid; } } EX_CATCH @@ -2499,10 +2491,7 @@ ClrDataModule::GetFlags( { (*flags) |= CLRDATA_MODULE_IS_DYNAMIC; } - if (m_module->IsIStream()) - { - (*flags) |= CLRDATA_MODULE_IS_MEMORY_STREAM; - } + PTR_Assembly pAssembly = m_module->GetAssembly(); PTR_BaseDomain pBaseDomain = pAssembly->GetDomain(); if (pBaseDomain->IsAppDomain()) @@ -2568,8 +2557,8 @@ ClrDataModule::StartEnumExtents( { if (!m_setExtents) { - PEFile* file = m_module->GetFile(); - if (!file) + PEAssembly* assembly = m_module->GetPEAssembly(); + if (!assembly) { *handle = 0; status = E_INVALIDARG; @@ -2578,10 +2567,10 @@ ClrDataModule::StartEnumExtents( CLRDATA_MODULE_EXTENT* extent = m_extents; - if (file->GetLoadedImageContents() != NULL) + if (assembly->GetLoadedImageContents() != NULL) { extent->base = - TO_CDADDR( PTR_TO_TADDR(file->GetLoadedImageContents(&extent->length)) ); + TO_CDADDR( PTR_TO_TADDR(assembly->GetLoadedImageContents(&extent->length)) ); extent->type = CLRDATA_MODULE_PE_FILE; extent++; } @@ -2723,23 +2712,23 @@ ClrDataModule::RequestGetModuleData( ZeroMemory(outGMD, sizeof(DacpGetModuleData)); Module* pModule = GetModule(); - PEFile *pPEFile = pModule->GetFile(); + PEAssembly *pPEAssembly = pModule->GetPEAssembly(); - outGMD->PEFile = TO_CDADDR(PTR_HOST_TO_TADDR(pPEFile)); + outGMD->PEAssembly = TO_CDADDR(PTR_HOST_TO_TADDR(pPEAssembly)); outGMD->IsDynamic = pModule->IsReflection(); - if (pPEFile != NULL) + if (pPEAssembly != NULL) { - outGMD->IsInMemory = pPEFile->GetPath().IsEmpty(); + outGMD->IsInMemory = pPEAssembly->GetPath().IsEmpty(); COUNT_T peSize; - outGMD->LoadedPEAddress = TO_CDADDR(PTR_TO_TADDR(pPEFile->GetLoadedImageContents(&peSize))); + outGMD->LoadedPEAddress = TO_CDADDR(PTR_TO_TADDR(pPEAssembly->GetLoadedImageContents(&peSize))); outGMD->LoadedPESize = (ULONG64)peSize; - // Can not get the file layout for a dynamic module + // Can not get the assembly layout for a dynamic module if (!outGMD->IsDynamic) { - outGMD->IsFileLayout = pPEFile->GetLoaded()->IsFlat(); + outGMD->IsFileLayout = pPEAssembly->GetLoadedLayout()->IsFlat(); } } @@ -2876,17 +2865,10 @@ ClrDataModule::GetMdInterface(PVOID* retIface) { if (m_mdImport == NULL) { - if (!m_module->GetFile()->HasMetadata()) - { - status = E_NOINTERFACE; - goto Exit; - } - // // Make sure internal MD is in RW format. // IMDInternalImport* rwMd; - status = ConvertMDInternalImport(m_module->GetMDImport(), &rwMd); if (FAILED(status)) { diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index e662f8cb86e24..b48e12afc96be 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -82,7 +82,7 @@ CordbModule::CordbModule( m_fDynamic = modInfo.fIsDynamic; m_fInMemory = modInfo.fInMemory; - m_vmPEFile = modInfo.vmPEFile; + m_vmPEFile = modInfo.vmPEAssembly; if (!vmDomainFile.IsNull()) { @@ -268,13 +268,13 @@ IDacDbiInterface::SymbolFormat CordbModule::GetInMemorySymbolStream(IStream ** p // Accessor for PE file. // // Returns: -// VMPTR_PEFile for this module. Should always be non-null +// VMPTR_PEAssembly for this module. Should always be non-null // // Notes: // A main usage of this is to find the proper internal MetaData importer. -// DACized code needs to map from PEFile --> IMDInternalImport. +// DACized code needs to map from PEAssembly --> IMDInternalImport. // -VMPTR_PEFile CordbModule::GetPEFile() +VMPTR_PEAssembly CordbModule::GetPEFile() { return m_vmPEFile; } diff --git a/src/coreclr/debug/di/process.cpp b/src/coreclr/debug/di/process.cpp index 134e3dbab4c96..c6c16d0700a85 100644 --- a/src/coreclr/debug/di/process.cpp +++ b/src/coreclr/debug/di/process.cpp @@ -290,10 +290,10 @@ static inline DWORD CordbGetWaitTimeout() //---------------------------------------------------------------------------- // Implementation of IDacDbiInterface::IMetaDataLookup. -// lookup Internal Metadata Importer keyed by PEFile +// lookup Internal Metadata Importer keyed by PEAssembly // isILMetaDataForNGENImage is true iff the IMDInternalImport returned represents a pointer to // metadata from an IL image when the module was an ngen'ed image. -IMDInternalImport * CordbProcess::LookupMetaData(VMPTR_PEFile vmPEFile, bool &isILMetaDataForNGENImage) +IMDInternalImport * CordbProcess::LookupMetaData(VMPTR_PEAssembly vmPEAssembly, bool &isILMetaDataForNGENImage) { INTERNAL_DAC_CALLBACK(this); @@ -312,7 +312,7 @@ IMDInternalImport * CordbProcess::LookupMetaData(VMPTR_PEFile vmPEFile, bool &is pModule != NULL; pModule = pAppDomain->m_modules.FindNext(&hashFindModule)) { - if (pModule->GetPEFile() == vmPEFile) + if (pModule->GetPEFile() == vmPEAssembly) { pMDII = NULL; ALLOW_DATATARGET_MISSING_MEMORY( @@ -341,7 +341,7 @@ IMDInternalImport * CordbProcess::LookupMetaData(VMPTR_PEFile vmPEFile, bool &is pModule != NULL; pModule = pAppDomain->m_modules.FindNext(&hashFindModule)) { - if (pModule->GetPEFile() == vmPEFile) + if (pModule->GetPEFile() == vmPEAssembly) { pMDII = NULL; ALLOW_DATATARGET_MISSING_MEMORY( @@ -354,7 +354,7 @@ IMDInternalImport * CordbProcess::LookupMetaData(VMPTR_PEFile vmPEFile, bool &is // debugger if it can find the metadata elsewhere. // If this was live debugging, we should have just gotten the memory contents. // Thus this code is for dump debugging, when you don't have the metadata in the dump. - pMDII = LookupMetaDataFromDebugger(vmPEFile, isILMetaDataForNGENImage, pModule); + pMDII = LookupMetaDataFromDebugger(vmPEAssembly, isILMetaDataForNGENImage, pModule); } return pMDII; } @@ -366,7 +366,7 @@ IMDInternalImport * CordbProcess::LookupMetaData(VMPTR_PEFile vmPEFile, bool &is IMDInternalImport * CordbProcess::LookupMetaDataFromDebugger( - VMPTR_PEFile vmPEFile, + VMPTR_PEAssembly vmPEAssembly, bool &isILMetaDataForNGENImage, CordbModule * pModule) { @@ -377,7 +377,7 @@ IMDInternalImport * CordbProcess::LookupMetaDataFromDebugger( IMDInternalImport * pMDII = NULL; // First, see if the debugger can locate the exact metadata we want. - if (this->GetDAC()->GetMetaDataFileInfoFromPEFile(vmPEFile, dwImageTimeStamp, dwImageSize, isNGEN, &filePath)) + if (this->GetDAC()->GetMetaDataFileInfoFromPEFile(vmPEAssembly, dwImageTimeStamp, dwImageSize, isNGEN, &filePath)) { _ASSERTE(filePath.IsSet()); @@ -408,7 +408,7 @@ IMDInternalImport * CordbProcess::LookupMetaDataFromDebugger( filePath.Clear(); if ((pMDII == NULL) && (isNGEN) && - (this->GetDAC()->GetILImageInfoFromNgenPEFile(vmPEFile, dwImageTimeStamp, dwImageSize, &filePath))) + (this->GetDAC()->GetILImageInfoFromNgenPEFile(vmPEAssembly, dwImageTimeStamp, dwImageSize, &filePath))) { _ASSERTE(filePath.IsSet()); @@ -496,7 +496,7 @@ IMDInternalImport * CordbProcess::LookupMetaDataFromDebuggerForSingleFile( if (SUCCEEDED(hr)) { // While we're successfully returning a metadata reader, remember that there's - // absolutely no guarantee this metadata is an exact match for the vmPEFile. + // absolutely no guarantee this metadata is an exact match for the vmPEAssembly. // The debugger could literally send us back a path to any managed file with // metadata content that is readable and we'll 'succeed'. // For now, this is by-design. A debugger should be allowed to decide if it wants diff --git a/src/coreclr/debug/di/rspriv.h b/src/coreclr/debug/di/rspriv.h index 7d257f6556e52..1baa6a9f24afd 100644 --- a/src/coreclr/debug/di/rspriv.h +++ b/src/coreclr/debug/di/rspriv.h @@ -2975,10 +2975,10 @@ class CordbProcess : //----------------------------------------------------------- // IMetaDataLookup // ----------------------------------------------------------- - IMDInternalImport * LookupMetaData(VMPTR_PEFile vmPEFile, bool &isILMetaDataForNGENImage); + IMDInternalImport * LookupMetaData(VMPTR_PEAssembly vmPEAssembly, bool &isILMetaDataForNGENImage); // Helper functions for LookupMetaData implementation - IMDInternalImport * LookupMetaDataFromDebugger(VMPTR_PEFile vmPEFile, + IMDInternalImport * LookupMetaDataFromDebugger(VMPTR_PEAssembly vmPEAssembly, bool &isILMetaDataForNGENImage, CordbModule * pModule); @@ -4368,7 +4368,7 @@ class CordbModule : public CordbBase, IDacDbiInterface::SymbolFormat GetInMemorySymbolStream(IStream ** ppStream); // accessor for PE file - VMPTR_PEFile GetPEFile(); + VMPTR_PEAssembly GetPEFile(); IMetaDataImport * GetMetaDataImporter(); @@ -4419,9 +4419,9 @@ class CordbModule : public CordbBase, // "Global" class for this module. Global functions + vars exist in this class. RSSmartPtr m_pClass; - // Handle to PEFile, useful for metadata lookups. + // Handle to PEAssembly, useful for metadata lookups. // this should always be non-null. - VMPTR_PEFile m_vmPEFile; + VMPTR_PEAssembly m_vmPEFile; // Public metadata importer. This is lazily initialized and accessed from code:GetMetaDataImporter diff --git a/src/coreclr/debug/ee/debugger.cpp b/src/coreclr/debug/ee/debugger.cpp index 2a8f565d686eb..0f61f8d36c78e 100644 --- a/src/coreclr/debug/ee/debugger.cpp +++ b/src/coreclr/debug/ee/debugger.cpp @@ -9537,21 +9537,6 @@ void Debugger::LoadModule(Module* pRuntimeModule, SENDIPCEVENT_END; - // need to update pdb stream for SQL passed in pdb stream - // regardless attach or not. - // - if (pRuntimeModule->IsIStream()) - { - // Just ignore failures. Caller was just sending a debug event and we don't - // want that to interop non-debugging functionality. - HRESULT hr = S_OK; - EX_TRY - { - SendUpdateModuleSymsEventAndBlock(pRuntimeModule, pAppDomain); - } - EX_CATCH_HRESULT(hr); - } - // Now that we're done with the load module event, can no longer change Jit flags. module->SetCanChangeJitFlags(false); } @@ -9710,7 +9695,7 @@ void Debugger::UnloadModule(Module* pRuntimeModule, STRESS_LOG6(LF_CORDB, LL_INFO10000, "D::UM: Unloading RTMod:%#08x (DomFile: %#08x, IsISStream:%#08x); DMod:%#08x(RTMod:%#08x DomFile: %#08x)\n", - pRuntimeModule, pRuntimeModule->GetDomainFile(), pRuntimeModule->IsIStream(), + pRuntimeModule, pRuntimeModule->GetDomainFile(), false, module, module->GetRuntimeModule(), module->GetDomainFile()); // Note: the appdomain the module was loaded in must match the appdomain we're unloading it from. If it doesn't, diff --git a/src/coreclr/debug/inc/dacdbiinterface.h b/src/coreclr/debug/inc/dacdbiinterface.h index 6696da0cbbbb0..0bda865bd0f59 100644 --- a/src/coreclr/debug/inc/dacdbiinterface.h +++ b/src/coreclr/debug/inc/dacdbiinterface.h @@ -521,7 +521,7 @@ class IDacDbiInterface // // For dynamic modules, the CLR will eagerly serialize the metadata at "debuggable" points. This // could be after each type is loaded; or after a bulk update. - // For non-dynamic modules (both in-memory and file-based), the metadata exists in the PEFile's image. + // For non-dynamic modules (both in-memory and file-based), the metadata exists in the PEAssembly's image. // // Failure cases: // This should succeed in normal, live-debugging scenarios. However, common failure paths here would be: @@ -2379,14 +2379,14 @@ class IDacDbiInterface CLR_DEBUGGING_PROCESS_FLAGS GetAttachStateFlags() = 0; virtual - bool GetMetaDataFileInfoFromPEFile(VMPTR_PEFile vmPEFile, + bool GetMetaDataFileInfoFromPEFile(VMPTR_PEAssembly vmPEAssembly, DWORD & dwTimeStamp, DWORD & dwImageSize, bool & isNGEN, IStringHolder* pStrFilename) = 0; virtual - bool GetILImageInfoFromNgenPEFile(VMPTR_PEFile vmPEFile, + bool GetILImageInfoFromNgenPEFile(VMPTR_PEAssembly vmPEAssembly, DWORD & dwTimeStamp, DWORD & dwSize, IStringHolder* pStrFilename) = 0; @@ -2512,17 +2512,17 @@ class IDacDbiInterface virtual void GetGCHeapInformation(OUT COR_HEAPINFO * pHeapInfo) = 0; - // If a PEFile has an RW capable IMDInternalImport, this returns the address of the MDInternalRW + // If a PEAssembly has an RW capable IMDInternalImport, this returns the address of the MDInternalRW // object which implements it. // // // Arguments: - // vmPEFile - target PEFile to get metadata MDInternalRW for. - // pAddrMDInternalRW - If a PEFile has an RW capable IMDInternalImport, this will be set to the address + // vmPEAssembly - target PEAssembly to get metadata MDInternalRW for. + // pAddrMDInternalRW - If a PEAssembly has an RW capable IMDInternalImport, this will be set to the address // of the MDInternalRW object which implements it. Otherwise it will be NULL. // virtual - HRESULT GetPEFileMDInternalRW(VMPTR_PEFile vmPEFile, OUT TADDR* pAddrMDInternalRW) = 0; + HRESULT GetPEFileMDInternalRW(VMPTR_PEAssembly vmPEAssembly, OUT TADDR* pAddrMDInternalRW) = 0; // DEPRECATED - use GetActiveRejitILCodeVersionNode // Retrieves the active ReJitInfo for a given module/methodDef, if it exists. @@ -2814,7 +2814,7 @@ class IDacDbiInterface { public: // - // Lookup a metadata importer via PEFile. + // Lookup a metadata importer via PEAssembly. // // Returns: // A IMDInternalImport used by dac-ized VM code. The object is NOT addref-ed. See lifespan notes below. @@ -2822,7 +2822,7 @@ class IDacDbiInterface // Throws on exceptional circumstances (eg, detects the debuggee is corrupted). // // Notes: - // IMDInternalImport is a property of PEFile. The DAC-ized code uses it as a weak reference, + // IMDInternalImport is a property of PEAssembly. The DAC-ized code uses it as a weak reference, // and so we avoid doing an AddRef() here because that would mean we need to add Release() calls // in DAC-only paths. // The metadata importers are not DAC-ized, and thus we have a local copy in the host. @@ -2837,7 +2837,7 @@ class IDacDbiInterface // - the reference count of the returned object is not adjusted. // virtual - IMDInternalImport * LookupMetaData(VMPTR_PEFile addressPEFile, bool &isILMetaDataForNGENImage) = 0; + IMDInternalImport * LookupMetaData(VMPTR_PEAssembly addressPEAssembly, bool &isILMetaDataForNGENImage) = 0; }; }; // end IDacDbiInterface diff --git a/src/coreclr/debug/inc/dacdbistructures.h b/src/coreclr/debug/inc/dacdbistructures.h index 19c788edb297f..5e02a68a792c9 100644 --- a/src/coreclr/debug/inc/dacdbistructures.h +++ b/src/coreclr/debug/inc/dacdbistructures.h @@ -186,10 +186,10 @@ struct MSLAYOUT ModuleInfo // (such as for a dynamic module that's not persisted to disk). CORDB_ADDRESS pPEBaseAddress; - // The PEFile associated with the module. Every module (even non-file-based ones) has a PEFile. + // The PEAssembly associated with the module. Every module (even non-file-based ones) has a PEAssembly. // This is critical because DAC may ask for a metadata importer via PE-file. - // a PEFile may have 1 or more PEImage child objects (1 for IL, 1 for native image, etc) - VMPTR_PEFile vmPEFile; + // a PEAssembly may have 1 or more PEImage child objects (1 for IL, 1 for native image, etc) + VMPTR_PEAssembly vmPEAssembly; // The PE Base address and size of the module. These may be 0 if there is no image // (such as for a dynamic module that's not persisted to disk). diff --git a/src/coreclr/debug/inc/dbgipcevents.h b/src/coreclr/debug/inc/dbgipcevents.h index da097631b2f8c..db4a00fca1c86 100644 --- a/src/coreclr/debug/inc/dbgipcevents.h +++ b/src/coreclr/debug/inc/dbgipcevents.h @@ -858,7 +858,7 @@ DEFINE_VMPTR(class Module, PTR_Module, VMPTR_Module); DEFINE_VMPTR(class DomainAssembly, PTR_DomainAssembly, VMPTR_DomainAssembly); DEFINE_VMPTR(class Assembly, PTR_Assembly, VMPTR_Assembly); -DEFINE_VMPTR(class PEFile, PTR_PEFile, VMPTR_PEFile); +DEFINE_VMPTR(class PEAssembly, PTR_PEAssembly, VMPTR_PEAssembly); DEFINE_VMPTR(class MethodDesc, PTR_MethodDesc, VMPTR_MethodDesc); DEFINE_VMPTR(class FieldDesc, PTR_FieldDesc, VMPTR_FieldDesc); diff --git a/src/coreclr/inc/corhdr.h b/src/coreclr/inc/corhdr.h index 58cb0aa7f9ca8..f9d4b5abf3b8b 100644 --- a/src/coreclr/inc/corhdr.h +++ b/src/coreclr/inc/corhdr.h @@ -227,7 +227,7 @@ typedef struct IMAGE_COR20_HEADER }; // This is the blob of managed resources. Fetched using code:AssemblyNative.GetResource and - // code:PEFile.GetResource and accessible from managed code from + // code:PEAssembly.GetResource and accessible from managed code from // System.Assembly.GetManifestResourceStream. The meta data has a table that maps names to offsets into // this blob, so logically the blob is a set of resources. IMAGE_DATA_DIRECTORY Resources; diff --git a/src/coreclr/inc/daccess.h b/src/coreclr/inc/daccess.h index 82009b77890e2..b769fcec22b4b 100644 --- a/src/coreclr/inc/daccess.h +++ b/src/coreclr/inc/daccess.h @@ -769,7 +769,7 @@ HRESULT DacReplacePatchesInHostMemory(MemoryRange range, PVOID pBuffer); #ifdef __cplusplus } class ReflectionModule; -interface IMDInternalImport* DacGetMDImport(const class PEFile* peFile, +interface IMDInternalImport* DacGetMDImport(const class PEAssembly* pPEAssembly, bool throwEx); interface IMDInternalImport* DacGetMDImport(const ReflectionModule* reflectionModule, bool throwEx); diff --git a/src/coreclr/inc/dacprivate.h b/src/coreclr/inc/dacprivate.h index 99419667a9635..45a4eda3cc140 100644 --- a/src/coreclr/inc/dacprivate.h +++ b/src/coreclr/inc/dacprivate.h @@ -230,8 +230,8 @@ struct MSLAYOUT DacpThreadLocalModuleData struct MSLAYOUT DacpModuleData { CLRDATA_ADDRESS Address = 0; - CLRDATA_ADDRESS File = 0; // A PEFile addr - CLRDATA_ADDRESS ilBase = 0; + CLRDATA_ADDRESS PEAssembly = 0; // A PEAssembly addr + CLRDATA_ADDRESS ilBase = 0; CLRDATA_ADDRESS metadataStart = 0; ULONG64 metadataSize = 0; CLRDATA_ADDRESS Assembly = 0; // Assembly pointer @@ -981,7 +981,7 @@ struct MSLAYOUT DacpGetModuleData BOOL IsDynamic = FALSE; BOOL IsInMemory = FALSE; BOOL IsFileLayout = FALSE; - CLRDATA_ADDRESS PEFile = 0; + CLRDATA_ADDRESS PEAssembly = 0; CLRDATA_ADDRESS LoadedPEAddress = 0; ULONG64 LoadedPESize = 0; CLRDATA_ADDRESS InMemoryPdbAddress = 0; diff --git a/src/coreclr/inc/vptr_list.h b/src/coreclr/inc/vptr_list.h index 4ea50d9fe4f44..4f8baccd5cd68 100644 --- a/src/coreclr/inc/vptr_list.h +++ b/src/coreclr/inc/vptr_list.h @@ -39,7 +39,6 @@ VPTR_CLASS(DelegateInvokeStubManager) VPTR_CLASS(TailCallStubManager) #endif VPTR_CLASS(CallCountingStubManager) -VPTR_CLASS(PEFile) VPTR_CLASS(PEAssembly) VPTR_CLASS(PEImageLayout) VPTR_CLASS(RawImageLayout) diff --git a/src/coreclr/vm/CMakeLists.txt b/src/coreclr/vm/CMakeLists.txt index da3a36468c06c..a1b164a0af65d 100644 --- a/src/coreclr/vm/CMakeLists.txt +++ b/src/coreclr/vm/CMakeLists.txt @@ -106,7 +106,7 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON nativeimage.cpp object.cpp onstackreplacement.cpp - pefile.cpp + peassembly.cpp peimage.cpp perfmap.cpp perfinfo.cpp @@ -207,8 +207,8 @@ set(VM_HEADERS_DAC_AND_WKS_COMMON object.h object.inl onstackreplacement.h - pefile.h - pefile.inl + peassembly.h + peassembly.inl peimage.h peimage.inl peimagelayout.h diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index d76db29301529..61c4c08e24925 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -1041,7 +1041,6 @@ void SystemDomain::Attach() // Create the one and only app domain AppDomain::Create(); - AppDomain::GetCurrentDomain()->CreateBinderContext(); // Each domain gets its own ReJitManager, and ReJitManager has its own static // initialization to run @@ -1174,7 +1173,7 @@ void SystemDomain::Init() if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_ZapDisable) != 0) g_fAllowNativeImages = false; - m_pSystemFile = NULL; + m_pSystemPEAssembly = NULL; m_pSystemAssembly = NULL; DWORD size = 0; @@ -1320,12 +1319,11 @@ void SystemDomain::LoadBaseSystemClasses() ETWOnStartup(LdSysBases_V1, LdSysBasesEnd_V1); - { - m_pSystemFile = PEAssembly::OpenSystem(); - } + m_pSystemPEAssembly = PEAssembly::OpenSystem(); + // Only partially load the system assembly. Other parts of the code will want to access // the globals in this function before finishing the load. - m_pSystemAssembly = DefaultDomain()->LoadDomainAssembly(NULL, m_pSystemFile, FILE_LOAD_POST_LOADLIBRARY)->GetCurrentAssembly(); + m_pSystemAssembly = DefaultDomain()->LoadDomainAssembly(NULL, m_pSystemPEAssembly, FILE_LOAD_POST_LOADLIBRARY)->GetCurrentAssembly(); // Set up binder for CoreLib CoreLibBinder::AttachModule(m_pSystemAssembly->GetManifestModule()); @@ -1839,6 +1837,8 @@ void AppDomain::Create() pDomain->InitVSD(); pDomain->SetStage(AppDomain::STAGE_OPEN); + pDomain->CreateDefaultBinder(); + pDomain.SuppressRelease(); m_pTheAppDomain = pDomain; @@ -2251,7 +2251,7 @@ DispIDCache* AppDomain::SetupRefDispIDCache() #endif // FEATURE_COMINTEROP -FileLoadLock *FileLoadLock::Create(PEFileListLock *pLock, PEFile *pFile, DomainFile *pDomainFile) +FileLoadLock *FileLoadLock::Create(PEFileListLock *pLock, PEAssembly * pPEAssembly, DomainFile *pDomainFile) { CONTRACTL { @@ -2259,12 +2259,12 @@ FileLoadLock *FileLoadLock::Create(PEFileListLock *pLock, PEFile *pFile, DomainF GC_TRIGGERS; MODE_ANY; PRECONDITION(pLock->HasLock()); - PRECONDITION(pLock->FindFileLock(pFile) == NULL); + PRECONDITION(pLock->FindFileLock(pPEAssembly) == NULL); INJECT_FAULT(COMPlusThrowOM();); } CONTRACTL_END; - NewHolder result(new FileLoadLock(pLock, pFile, pDomainFile)); + NewHolder result(new FileLoadLock(pLock, pPEAssembly, pDomainFile)); pLock->AddElement(result); result->AddRef(); // Add one ref on behalf of the ListLock's reference. The corresponding Release() happens in FileLoadLock::CompleteLoadLevel. @@ -2281,7 +2281,7 @@ FileLoadLock::~FileLoadLock() MODE_ANY; } CONTRACTL_END; - ((PEFile *) m_data)->Release(); + ((PEAssembly *) m_data)->Release(); } DomainFile *FileLoadLock::GetDomainFile() @@ -2476,14 +2476,14 @@ UINT32 FileLoadLock::Release() return count; } -FileLoadLock::FileLoadLock(PEFileListLock *pLock, PEFile *pFile, DomainFile *pDomainFile) - : ListLockEntry(pLock, pFile, "File load lock"), +FileLoadLock::FileLoadLock(PEFileListLock *pLock, PEAssembly * pPEAssembly, DomainFile *pDomainFile) + : ListLockEntry(pLock, pPEAssembly, "File load lock"), m_level((FileLoadLevel) (FILE_LOAD_CREATE)), m_pDomainFile(pDomainFile), m_cachedHR(S_OK) { WRAPPER_NO_CONTRACT; - pFile->AddRef(); + pPEAssembly->AddRef(); } void FileLoadLock::HolderLeave(FileLoadLock *pThis) @@ -2531,7 +2531,7 @@ void AppDomain::LoadSystemAssemblies() // // Right now we have only one system assembly. We shouldn't need to add any more. - LoadAssembly(NULL, SystemDomain::System()->SystemFile(), FILE_ACTIVE); + LoadAssembly(NULL, SystemDomain::System()->SystemPEAssembly(), FILE_ACTIVE); } FileLoadLevel AppDomain::GetDomainFileLoadLevel(DomainFile *pFile) @@ -2546,7 +2546,7 @@ FileLoadLevel AppDomain::GetDomainFileLoadLevel(DomainFile *pFile) LoadLockHolder lock(this); - FileLoadLock* pLockEntry = (FileLoadLock *) lock->FindFileLock(pFile->GetFile()); + FileLoadLock* pLockEntry = (FileLoadLock *) lock->FindFileLock(pFile->GetPEAssembly()); if (pLockEntry == NULL) return pFile->GetLoadLevel(); @@ -2576,7 +2576,7 @@ BOOL AppDomain::IsLoading(DomainFile *pFile, FileLoadLevel level) { LoadLockHolder lock(this); - pLock = (FileLoadLock *) lock->FindFileLock(pFile->GetFile()); + pLock = (FileLoadLock *) lock->FindFileLock(pFile->GetPEAssembly()); if (pLock == NULL) { @@ -2613,7 +2613,7 @@ CHECK AppDomain::CheckLoading(DomainFile *pFile, FileLoadLevel level) LoadLockHolder lock(this); - pLock = (FileLoadLock *) lock->FindFileLock(pFile->GetFile()); + pLock = (FileLoadLock *) lock->FindFileLock(pFile->GetPEAssembly()); if (pLock != NULL && pLock->CanAcquire(level)) @@ -2699,7 +2699,7 @@ void AppDomain::LoadDomainFile(DomainFile *pFile, // Load some more if appropriate LoadLockHolder lock(this); - FileLoadLock* pLockEntry = (FileLoadLock *) lock->FindFileLock(pFile->GetFile()); + FileLoadLock* pLockEntry = (FileLoadLock *) lock->FindFileLock(pFile->GetPEAssembly()); if (pLockEntry == NULL) { _ASSERTE (!pFile->IsLoading()); @@ -2731,7 +2731,7 @@ FileLoadLevel AppDomain::GetThreadFileLoadLevel() Assembly *AppDomain::LoadAssembly(AssemblySpec* pIdentity, - PEAssembly *pFile, + PEAssembly * pPEAssembly, FileLoadLevel targetLevel) { CONTRACT(Assembly *) @@ -2739,20 +2739,20 @@ Assembly *AppDomain::LoadAssembly(AssemblySpec* pIdentity, GC_TRIGGERS; THROWS; MODE_ANY; - PRECONDITION(CheckPointer(pFile)); + PRECONDITION(CheckPointer(pPEAssembly)); POSTCONDITION(CheckPointer(RETVAL, NULL_OK)); // May be NULL in recursive load case INJECT_FAULT(COMPlusThrowOM();); } CONTRACT_END; - DomainAssembly *pAssembly = LoadDomainAssembly(pIdentity, pFile, targetLevel); + DomainAssembly *pAssembly = LoadDomainAssembly(pIdentity, pPEAssembly, targetLevel); PREFIX_ASSUME(pAssembly != NULL); RETURN pAssembly->GetAssembly(); } DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, - PEAssembly *pFile, + PEAssembly * pPEAssembly, FileLoadLevel targetLevel) { STATIC_CONTRACT_THROWS; @@ -2760,13 +2760,13 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, if (pSpec == nullptr) { // skip caching, since we don't have anything to base it on - return LoadDomainAssemblyInternal(pSpec, pFile, targetLevel); + return LoadDomainAssemblyInternal(pSpec, pPEAssembly, targetLevel); } DomainAssembly* pRetVal = NULL; EX_TRY { - pRetVal = LoadDomainAssemblyInternal(pSpec, pFile, targetLevel); + pRetVal = LoadDomainAssemblyInternal(pSpec, pPEAssembly, targetLevel); } EX_HOOK { @@ -2775,7 +2775,7 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, { // Setup the binder reference in AssemblySpec from the PEAssembly if one is not already set. AssemblyBinder* pCurrentBinder = pSpec->GetBinder(); - AssemblyBinder* pBinderFromPEAssembly = pFile->GetAssemblyBinder(); + AssemblyBinder* pBinderFromPEAssembly = pPEAssembly->GetAssemblyBinder(); if (pCurrentBinder == NULL) { @@ -2811,7 +2811,7 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, - PEAssembly *pFile, + PEAssembly * pPEAssembly, FileLoadLevel targetLevel) { CONTRACT(DomainAssembly *) @@ -2819,8 +2819,8 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, GC_TRIGGERS; THROWS; MODE_ANY; - PRECONDITION(CheckPointer(pFile)); - PRECONDITION(pFile->IsSystem() || ::GetAppDomain()==this); + PRECONDITION(CheckPointer(pPEAssembly)); + PRECONDITION(::GetAppDomain()==this); POSTCONDITION(CheckPointer(RETVAL)); POSTCONDITION(RETVAL->GetLoadLevel() >= GetThreadFileLoadLevel() || RETVAL->GetLoadLevel() >= targetLevel); @@ -2836,16 +2836,16 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, GCX_PREEMP(); // Check for existing fully loaded assembly, or for an assembly which has failed during the loading process. - result = FindAssembly(pFile, FindAssemblyOptions_IncludeFailedToLoad); + result = FindAssembly(pPEAssembly, FindAssemblyOptions_IncludeFailedToLoad); if (result == NULL) { LoaderAllocator *pLoaderAllocator = NULL; - AssemblyBinder *pFileBinder = pFile->GetAssemblyBinder(); + AssemblyBinder *pAssemblyBinder = pPEAssembly->GetAssemblyBinder(); // Assemblies loaded with CustomAssemblyBinder need to use a different LoaderAllocator if // marked as collectible - pLoaderAllocator = pFileBinder->GetLoaderAllocator(); + pLoaderAllocator = pAssemblyBinder->GetLoaderAllocator(); if (pLoaderAllocator == NULL) { pLoaderAllocator = this->GetLoaderAllocator(); @@ -2853,22 +2853,22 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, // Allocate the DomainAssembly a bit early to avoid GC mode problems. We could potentially avoid // a rare redundant allocation by moving this closer to FileLoadLock::Create, but it's not worth it. - NewHolder pDomainAssembly = new DomainAssembly(this, pFile, pLoaderAllocator); + NewHolder pDomainAssembly = new DomainAssembly(this, pPEAssembly, pLoaderAllocator); LoadLockHolder lock(this); // Find the list lock entry - FileLoadLock * fileLock = (FileLoadLock *)lock->FindFileLock(pFile); + FileLoadLock * fileLock = (FileLoadLock *)lock->FindFileLock(pPEAssembly); bool registerNewAssembly = false; if (fileLock == NULL) { // Check again in case we were racing - result = FindAssembly(pFile, FindAssemblyOptions_IncludeFailedToLoad); + result = FindAssembly(pPEAssembly, FindAssemblyOptions_IncludeFailedToLoad); if (result == NULL) { // We are the first one in - create the DomainAssembly registerNewAssembly = true; - fileLock = FileLoadLock::Create(lock, pFile, pDomainAssembly); + fileLock = FileLoadLock::Create(lock, pPEAssembly, pDomainAssembly); pDomainAssembly.SuppressRelease(); if (pDomainAssembly->IsCollectible()) { @@ -2901,7 +2901,7 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, if (registerNewAssembly) { - pFile->GetAssemblyBinder()->AddLoadedAssembly(pDomainAssembly->GetCurrentAssembly()); + pPEAssembly->GetAssemblyBinder()->AddLoadedAssembly(pDomainAssembly->GetCurrentAssembly()); } } else @@ -2915,11 +2915,11 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, ThrowHR(COR_E_ASSEMBLYEXPECTED); } - // Cache result in all cases, since found pFile could be from a different AssemblyRef than pIdentity + // Cache result in all cases, since found pPEAssembly could be from a different AssemblyRef than pIdentity if (pIdentity == NULL) { AssemblySpec spec; - spec.InitializeSpec(result->GetFile()); + spec.InitializeSpec(result->GetPEAssembly()); GetAppDomain()->AddAssemblyToCache(&spec, result); } else @@ -2956,26 +2956,6 @@ DomainFile *AppDomain::LoadDomainFile(FileLoadLock *pLock, FileLoadLevel targetL // Make sure we release the lock on exit FileLoadLockRefHolder lockRef(pLock); - // We need to perform the early steps of loading CoreLib without a domain transition. This is - // important for bootstrapping purposes - we need to get CoreLib at least partially loaded - // into a domain before we can run serialization code to do the transition. - // - // Note that we cannot do this in general for all assemblies, because some of the security computations - // require the managed exposed object, which must be created in the correct app domain. - - if (this != GetAppDomain() - && pFile->GetFile()->IsSystem() - && targetLevel > FILE_LOAD_ALLOCATE) - { - // Re-call the routine with a limited load level. This will cause the first part of the load to - // get performed in the current app domain. - - pLock->AddRef(); - LoadDomainFile(pLock, targetLevel > FILE_LOAD_ALLOCATE ? FILE_LOAD_ALLOCATE : targetLevel); - - // Now continue on to complete the rest of the load, if any. - } - // Do a quick out check for the already loaded case. if (pLock->GetLoadLevel() >= targetLevel) { @@ -3151,7 +3131,7 @@ void AppDomain::TryIncrementalLoad(DomainFile *pFile, FileLoadLevel workLevel, F } if (!EEFileLoadException::CheckType(pEx)) - EEFileLoadException::Throw(pFile->GetFile(), pEx->GetHR(), pEx); + EEFileLoadException::Throw(pFile->GetPEAssembly(), pEx->GetHR(), pEx); } // Otherwise, we simply abort this load, and can retry later on. @@ -3212,7 +3192,7 @@ void AppDomain::SetupSharedStatics() SetObjectReference( pEmptyStringHandle, StringObject::GetEmptyString()); } -DomainAssembly * AppDomain::FindAssembly(PEAssembly * pFile, FindAssemblyOptions options/* = FindAssemblyOptions_None*/) +DomainAssembly * AppDomain::FindAssembly(PEAssembly * pPEAssembly, FindAssemblyOptions options/* = FindAssemblyOptions_None*/) { CONTRACTL { @@ -3225,9 +3205,9 @@ DomainAssembly * AppDomain::FindAssembly(PEAssembly * pFile, FindAssemblyOptions const bool includeFailedToLoad = (options & FindAssemblyOptions_IncludeFailedToLoad) != 0; - if (pFile->HasHostAssembly()) + if (pPEAssembly->HasHostAssembly()) { - DomainAssembly * pDA = FindAssembly(pFile->GetHostAssembly()); + DomainAssembly * pDA = FindAssembly(pPEAssembly->GetHostAssembly()); if (pDA != nullptr && (pDA->IsLoaded() || (includeFailedToLoad && pDA->IsError()))) { return pDA; @@ -3243,10 +3223,9 @@ DomainAssembly * AppDomain::FindAssembly(PEAssembly * pFile, FindAssemblyOptions while (i.Next(pDomainAssembly.This())) { - PEFile * pManifestFile = pDomainAssembly->GetFile(); + PEAssembly * pManifestFile = pDomainAssembly->GetPEAssembly(); if (pManifestFile && - !pManifestFile->IsResource() && - pManifestFile->Equals(pFile)) + pManifestFile->Equals(pPEAssembly)) { // Caller already has PEAssembly, so we can give DomainAssembly away freely without added reference return pDomainAssembly.GetValue(); @@ -3412,7 +3391,7 @@ PVOID AppDomain::GetFriendlyNameNoSet(bool* isUtf8) #ifndef DACCESS_COMPILE -BOOL AppDomain::AddFileToCache(AssemblySpec* pSpec, PEAssembly *pFile, BOOL fAllowFailure) +BOOL AppDomain::AddFileToCache(AssemblySpec* pSpec, PEAssembly * pPEAssembly, BOOL fAllowFailure) { CONTRACTL { @@ -3428,7 +3407,7 @@ BOOL AppDomain::AddFileToCache(AssemblySpec* pSpec, PEAssembly *pFile, BOOL fAll DomainCacheCrstHolderForGCCoop holder(this); // !!! suppress exceptions - if(!m_AssemblyCache.StoreFile(pSpec, pFile) && !fAllowFailure) + if(!m_AssemblyCache.StorePEAssembly(pSpec, pPEAssembly) && !fAllowFailure) { // TODO: Disabling the below assertion as currently we experience // inconsistency on resolving the Microsoft.Office.Interop.MSProject.dll @@ -3538,17 +3517,17 @@ NATIVE_LIBRARY_HANDLE AppDomain::FindUnmanagedImageInCache(LPCWSTR libraryName) RETURN existingEntry->Handle; } -BOOL AppDomain::RemoveFileFromCache(PEAssembly *pFile) +BOOL AppDomain::RemoveFileFromCache(PEAssembly * pPEAssembly) { CONTRACTL { GC_TRIGGERS; - PRECONDITION(CheckPointer(pFile)); + PRECONDITION(CheckPointer(pPEAssembly)); } CONTRACTL_END; LoadLockHolder lock(this); - FileLoadLock *fileLock = (FileLoadLock *)lock->FindFileLock(pFile); + FileLoadLock *fileLock = (FileLoadLock *)lock->FindFileLock(pPEAssembly); if (fileLock == NULL) return FALSE; @@ -3611,9 +3590,9 @@ PEAssembly* AppDomain::FindCachedFile(AssemblySpec* pSpec, BOOL fThrow /*=TRUE*/ if (fThrow && pSpec->IsCoreLib()) { CONSISTENCY_CHECK(SystemDomain::System()->SystemAssembly() != NULL); - PEAssembly *pFile = SystemDomain::System()->SystemFile(); - pFile->AddRef(); - return pFile; + PEAssembly * pPEAssembly = SystemDomain::System()->SystemPEAssembly(); + pPEAssembly->AddRef(); + return pPEAssembly; } return m_AssemblyCache.LookupFile(pSpec, fThrow); @@ -3697,16 +3676,16 @@ PEAssembly * AppDomain::BindAssemblySpec( if (boundAssembly) { - if (SystemDomain::SystemFile() && boundAssembly->GetAssemblyName()->IsCoreLib()) + if (SystemDomain::SystemPEAssembly() && boundAssembly->GetAssemblyName()->IsCoreLib()) { // Avoid rebinding to another copy of CoreLib - result = SystemDomain::SystemFile(); + result = SystemDomain::SystemPEAssembly(); result.SuppressRelease(); // Didn't get a refcount } else { - // IsSystem on the PEFile should be false, even for CoreLib satellites - result = PEAssembly::Open(boundAssembly, FALSE); + // IsSystem on the PEAssembly should be false, even for CoreLib satellites + result = PEAssembly::Open(boundAssembly); } // Setup the reference to the binder, which performed the bind, into the AssemblySpec @@ -3861,9 +3840,9 @@ PEAssembly *AppDomain::TryResolveAssemblyUsingEvent(AssemblySpec *pSpec) Assembly *pAssembly = RaiseAssemblyResolveEvent(pSpec); if (pAssembly != nullptr) { - PEAssembly *pFile = pAssembly->GetManifestFile(); - pFile->AddRef(); - result = pFile; + PEAssembly* pPEAssembly = pAssembly->GetManifestFile(); + pPEAssembly->AddRef(); + result = pPEAssembly; } BinderTracing::ResolutionAttemptedOperation::TraceAppDomainAssemblyResolve(pSpec, result); @@ -3924,7 +3903,7 @@ void AppDomain::RaiseLoadingAssemblyEvent(DomainAssembly *pAssembly) } CONTRACTL_END; - if (pAssembly->GetFile()->IsSystem()) + if (pAssembly->GetPEAssembly()->IsSystem()) { return; } @@ -4040,7 +4019,7 @@ AppDomain::RaiseUnhandledExceptionEvent(OBJECTREF *pThrowable, BOOL isTerminatin } -DefaultAssemblyBinder *AppDomain::CreateBinderContext() +DefaultAssemblyBinder *AppDomain::CreateDefaultBinder() { CONTRACT(DefaultAssemblyBinder *) { @@ -5138,7 +5117,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB } else { - pLoadedPEAssembly = pDomainAssembly->GetFile(); + pLoadedPEAssembly = pDomainAssembly->GetPEAssembly(); if (!pLoadedPEAssembly->HasHostAssembly()) { // Reflection emitted assemblies will not have a domain assembly. @@ -5300,9 +5279,9 @@ SystemDomain::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, } BaseDomain::EnumMemoryRegions(flags, false); - if (m_pSystemFile.IsValid()) + if (m_pSystemPEAssembly.IsValid()) { - m_pSystemFile->EnumMemoryRegions(flags); + m_pSystemPEAssembly->EnumMemoryRegions(flags); } if (m_pSystemAssembly.IsValid()) { @@ -5372,11 +5351,11 @@ void AppDomain::PublishHostedAssembly( } CONTRACTL_END - if (pDomainAssembly->GetFile()->HasHostAssembly()) + if (pDomainAssembly->GetPEAssembly()->HasHostAssembly()) { // We have to serialize all Add operations CrstHolder lockAdd(&m_crstHostAssemblyMapAdd); - _ASSERTE(m_hostAssemblyMap.Lookup(pDomainAssembly->GetFile()->GetHostAssembly()) == nullptr); + _ASSERTE(m_hostAssemblyMap.Lookup(pDomainAssembly->GetPEAssembly()->GetHostAssembly()) == nullptr); // Wrapper for m_hostAssemblyMap.Add that avoids call out into host HostAssemblyMap::AddPhases addCall; @@ -5401,75 +5380,6 @@ void AppDomain::PublishHostedAssembly( } } -//--------------------------------------------------------------------------------------------------------------------- -void AppDomain::UpdatePublishHostedAssembly( - DomainAssembly * pAssembly, - PTR_PEFile pFile) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_ANY; - CAN_TAKE_LOCK; - } - CONTRACTL_END - - if (pAssembly->GetFile()->HasHostAssembly()) - { - // We have to serialize all Add operations - CrstHolder lockAdd(&m_crstHostAssemblyMapAdd); - { - // Wrapper for m_hostAssemblyMap.Add that avoids call out into host - OriginalFileHostAssemblyMap::AddPhases addCall; - bool fAddOrigFile = false; - - // For cases where the pefile is being updated - // 1. Preallocate one element - if (pFile != pAssembly->GetFile()) - { - addCall.PreallocateForAdd(&m_hostAssemblyMapForOrigFile); - fAddOrigFile = true; - } - - { - // We cannot call out into host from ForbidSuspend region (i.e. no allocations/deallocations) - ForbidSuspendThreadHolder suspend; - { - CrstHolder lock(&m_crstHostAssemblyMap); - - // Remove from hash table. - _ASSERTE(m_hostAssemblyMap.Lookup(pAssembly->GetFile()->GetHostAssembly()) != nullptr); - m_hostAssemblyMap.Remove(pAssembly->GetFile()->GetHostAssembly()); - - // Update PEFile on DomainAssembly. (This may cause the key for the hash to change, which is why we need this function) - pAssembly->UpdatePEFileWorker(pFile); - - _ASSERTE(fAddOrigFile == (pAssembly->GetOriginalFile() != pAssembly->GetFile())); - if (fAddOrigFile) - { - // Add to the orig file hash table if we might be in a case where we've cached the original pefile and not the final pe file (for use during GetAssemblyIfLoaded) - addCall.Add(pAssembly); - } - - // Add back to the hashtable (the call to Remove above guarantees that we will not call into host for table reallocation) - _ASSERTE(m_hostAssemblyMap.Lookup(pAssembly->GetFile()->GetHostAssembly()) == nullptr); - m_hostAssemblyMap.Add(pAssembly); - } - } - - // 4. Cleanup the old memory (if any) - if (fAddOrigFile) - addCall.DeleteOldTable(); - } - } - else - { - - pAssembly->UpdatePEFileWorker(pFile); - } -} - //--------------------------------------------------------------------------------------------------------------------- void AppDomain::UnPublishHostedAssembly( DomainAssembly * pAssembly) @@ -5483,19 +5393,13 @@ void AppDomain::UnPublishHostedAssembly( } CONTRACTL_END - if (pAssembly->GetFile()->HasHostAssembly()) + if (pAssembly->GetPEAssembly()->HasHostAssembly()) { ForbidSuspendThreadHolder suspend; { CrstHolder lock(&m_crstHostAssemblyMap); - _ASSERTE(m_hostAssemblyMap.Lookup(pAssembly->GetFile()->GetHostAssembly()) != nullptr); - m_hostAssemblyMap.Remove(pAssembly->GetFile()->GetHostAssembly()); - - // We also have an entry in m_hostAssemblyMapForOrigFile. Handle that case. - if (pAssembly->GetOriginalFile() != pAssembly->GetFile()) - { - m_hostAssemblyMapForOrigFile.Remove(pAssembly->GetOriginalFile()->GetHostAssembly()); - } + _ASSERTE(m_hostAssemblyMap.Lookup(pAssembly->GetPEAssembly()->GetHostAssembly()) != nullptr); + m_hostAssemblyMap.Remove(pAssembly->GetPEAssembly()->GetHostAssembly()); } } } @@ -5521,18 +5425,7 @@ PTR_DomainAssembly AppDomain::FindAssembly(PTR_BINDER_SPACE_Assembly pHostAssemb ForbidSuspendThreadHolder suspend; { CrstHolder lock(&m_crstHostAssemblyMap); - PTR_DomainAssembly returnValue = m_hostAssemblyMap.Lookup(pHostAssembly); - if (returnValue == NULL) - { - // If not found in the m_hostAssemblyMap, look in the m_hostAssemblyMapForOrigFile - // This is necessary as it may happen during in a second AppDomain that the PEFile - // first discovered in the AppDomain may not be used by the DomainFile, but the CLRPrivBinderFusion - // will in some cases find the pHostAssembly associated with this no longer used PEFile - // instead of the PEFile that was finally decided upon. - returnValue = m_hostAssemblyMapForOrigFile.Lookup(pHostAssembly); - } - - return returnValue; + return m_hostAssemblyMap.Lookup(pHostAssembly); } } } diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index d31dc9af6d8ab..27509c601e4cc 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -700,7 +700,7 @@ class PEFileListLock : public ListLock { public: #ifndef DACCESS_COMPILE - ListLockEntry *FindFileLock(PEFile *pFile) + ListLockEntry *FindFileLock(PEAssembly *pPEAssembly) { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; @@ -714,7 +714,7 @@ class PEFileListLock : public ListLock pEntry != NULL; pEntry = pEntry->m_pNext) { - if (((PEFile *)pEntry->m_data)->Equals(pFile)) + if (((PEAssembly *)pEntry->m_data)->Equals(pPEAssembly)) { return pEntry; } @@ -777,7 +777,7 @@ class FileLoadLock : public ListLockEntry HRESULT m_cachedHR; public: - static FileLoadLock *Create(PEFileListLock *pLock, PEFile *pFile, DomainFile *pDomainFile); + static FileLoadLock *Create(PEFileListLock *pLock, PEAssembly *pPEAssembly, DomainFile *pDomainFile); ~FileLoadLock(); DomainFile *GetDomainFile(); @@ -807,7 +807,7 @@ class FileLoadLock : public ListLockEntry private: - FileLoadLock(PEFileListLock *pLock, PEFile *pFile, DomainFile *pDomainFile); + FileLoadLock(PEFileListLock *pLock, PEAssembly *pPEAssembly, DomainFile *pDomainFile); static void HolderLeave(FileLoadLock *pThis); @@ -1812,11 +1812,11 @@ class AppDomain : public BaseDomain FindAssemblyOptions_IncludeFailedToLoad = 0x1 }; - DomainAssembly * FindAssembly(PEAssembly * pFile, FindAssemblyOptions options = FindAssemblyOptions_None) DAC_EMPTY_RET(NULL); + DomainAssembly * FindAssembly(PEAssembly* pPEAssembly, FindAssemblyOptions options = FindAssemblyOptions_None) DAC_EMPTY_RET(NULL); Assembly *LoadAssembly(AssemblySpec* pIdentity, - PEAssembly *pFile, + PEAssembly *pPEAssembly, FileLoadLevel targetLevel); // this function does not provide caching, you must use LoadDomainAssembly @@ -1826,11 +1826,11 @@ class AppDomain : public BaseDomain // resulting in multiple DomainAssembly objects that share the same PEAssembly for ngen image //which is violating our internal assumptions DomainAssembly *LoadDomainAssemblyInternal( AssemblySpec* pIdentity, - PEAssembly *pFile, + PEAssembly *pPEAssembly, FileLoadLevel targetLevel); DomainAssembly *LoadDomainAssembly( AssemblySpec* pIdentity, - PEAssembly *pFile, + PEAssembly *pPEAssembly, FileLoadLevel targetLevel); @@ -1859,8 +1859,8 @@ class AppDomain : public BaseDomain BOOL IsCached(AssemblySpec *pSpec); #endif // DACCESS_COMPILE - BOOL AddFileToCache(AssemblySpec* pSpec, PEAssembly *pFile, BOOL fAllowFailure = FALSE); - BOOL RemoveFileFromCache(PEAssembly *pFile); + BOOL AddFileToCache(AssemblySpec* pSpec, PEAssembly *pPEAssembly, BOOL fAllowFailure = FALSE); + BOOL RemoveFileFromCache(PEAssembly *pPEAssembly); BOOL AddAssemblyToCache(AssemblySpec* pSpec, DomainAssembly *pAssembly); BOOL RemoveAssemblyFromCache(DomainAssembly* pAssembly); @@ -1974,7 +1974,7 @@ class AppDomain : public BaseDomain return m_tpIndex; } - DefaultAssemblyBinder *CreateBinderContext(); + DefaultAssemblyBinder *CreateDefaultBinder(); void SetIgnoreUnhandledExceptions() { @@ -2364,7 +2364,7 @@ class AppDomain : public BaseDomain //----------------------------------------------------------- // Static BINDER_SPACE::Assembly -> DomainAssembly mapping functions. // This map does not maintain a reference count to either key or value. - // PEFile maintains a reference count on the BINDER_SPACE::Assembly through its code:PEFile::m_pHostAssembly field. + // PEAssembly maintains a reference count on the BINDER_SPACE::Assembly through its code:PEAssembly::m_pHostAssembly field. // It is removed from this hash table by code:DomainAssembly::~DomainAssembly. struct HostAssemblyHashTraits : public DefaultSHashTraits { @@ -2374,7 +2374,7 @@ class AppDomain : public BaseDomain static key_t GetKey(element_t const & elem) { STATIC_CONTRACT_WRAPPER; - return elem->GetFile()->GetHostAssembly(); + return elem->GetPEAssembly()->GetHostAssembly(); } static BOOL Equals(key_t key1, key_t key2) @@ -2396,20 +2396,8 @@ class AppDomain : public BaseDomain static bool IsDeleted(const element_t & e) { return dac_cast(e) == (TADDR)-1; } }; - struct OriginalFileHostAssemblyHashTraits : public HostAssemblyHashTraits - { - public: - static key_t GetKey(element_t const & elem) - { - STATIC_CONTRACT_WRAPPER; - return elem->GetOriginalFile()->GetHostAssembly(); - } - }; - typedef SHash HostAssemblyMap; - typedef SHash OriginalFileHostAssemblyMap; HostAssemblyMap m_hostAssemblyMap; - OriginalFileHostAssemblyMap m_hostAssemblyMapForOrigFile; CrstExplicitInit m_crstHostAssemblyMap; // Lock to serialize all Add operations (in addition to the "read-lock" above) CrstExplicitInit m_crstHostAssemblyMapAdd; @@ -2427,11 +2415,6 @@ class AppDomain : public BaseDomain void PublishHostedAssembly( DomainAssembly* pAssembly); - // Called from DomainAssembly::UpdatePEFile. - void UpdatePublishHostedAssembly( - DomainAssembly* pAssembly, - PTR_PEFile pFile); - // Called from DomainAssembly::~DomainAssembly void UnPublishHostedAssembly( DomainAssembly* pAssembly); @@ -2512,12 +2495,12 @@ class SystemDomain : public BaseDomain return m_pSystemDomain; } - static PEAssembly* SystemFile() + static PEAssembly* SystemPEAssembly() { WRAPPER_NO_CONTRACT; _ASSERTE(m_pSystemDomain); - return System()->m_pSystemFile; + return System()->m_pSystemPEAssembly; } static Assembly* SystemAssembly() @@ -2708,7 +2691,7 @@ class SystemDomain : public BaseDomain } #endif - PTR_PEAssembly m_pSystemFile; // Single assembly (here for quicker reference); + PTR_PEAssembly m_pSystemPEAssembly;// Single assembly (here for quicker reference); PTR_Assembly m_pSystemAssembly; // Single assembly (here for quicker reference); GlobalLoaderAllocator m_GlobalAllocator; diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index c0fe297fc1ecc..754cf91696ff7 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -62,9 +62,56 @@ #ifndef DACCESS_COMPILE volatile uint32_t g_cAssemblies = 0; - static CrstStatic g_friendAssembliesCrst; +namespace +{ + void DefineEmitScope(GUID iid, void** ppEmit) + { + CONTRACT_VOID + { + PRECONDITION(CheckPointer(ppEmit)); + POSTCONDITION(CheckPointer(*ppEmit)); + THROWS; + GC_TRIGGERS; + MODE_ANY; + INJECT_FAULT(COMPlusThrowOM();); + } + CONTRACT_END; + + SafeComHolder pDispenser; + + // Get the Dispenser interface. + MetaDataGetDispenser( + CLSID_CorMetaDataDispenser, + IID_IMetaDataDispenserEx, + (void**)&pDispenser); + if (pDispenser == NULL) + { + ThrowOutOfMemory(); + } + + // Set the option on the dispenser turn on duplicate check for TypeDef and moduleRef + VARIANT varOption; + V_VT(&varOption) = VT_UI4; + V_I4(&varOption) = MDDupDefault | MDDupTypeDef | MDDupModuleRef | MDDupExportedType | MDDupAssemblyRef | MDDupPermission | MDDupFile; + IfFailThrow(pDispenser->SetOption(MetaDataCheckDuplicatesFor, &varOption)); + + // Set minimal MetaData size + V_VT(&varOption) = VT_UI4; + V_I4(&varOption) = MDInitialSizeMinimal; + IfFailThrow(pDispenser->SetOption(MetaDataInitialSize, &varOption)); + + // turn on the thread safety! + V_I4(&varOption) = MDThreadSafetyOn; + IfFailThrow(pDispenser->SetOption(MetaDataThreadSafetyOptions, &varOption)); + + IfFailThrow(pDispenser->DefineScope(CLSID_CorMetaDataRuntime, 0, iid, (IUnknown**)ppEmit)); + + RETURN; + } +} + void Assembly::Initialize() { g_friendAssembliesCrst.Init(CrstLeafLock); @@ -75,12 +122,12 @@ void Assembly::Initialize() // It cannot do any allocations or operations that might fail. Those operations should be done // in Assembly::Init() //---------------------------------------------------------------------------------------------- -Assembly::Assembly(BaseDomain *pDomain, PEAssembly* pFile, DebuggerAssemblyControlFlags debuggerFlags, BOOL fIsCollectible) : +Assembly::Assembly(BaseDomain *pDomain, PEAssembly* pPEAssembly, DebuggerAssemblyControlFlags debuggerFlags, BOOL fIsCollectible) : m_pDomain(pDomain), m_pClassLoader(NULL), m_pEntryPoint(NULL), m_pManifest(NULL), - m_pManifestFile(clr::SafeAddRef(pFile)), + m_pManifestFile(clr::SafeAddRef(pPEAssembly)), m_pFriendAssemblyDescriptor(NULL), m_isDynamic(false), #ifdef FEATURE_COLLECTIBLE_TYPES @@ -164,7 +211,7 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat if (IsCollectible()) { COUNT_T size; - BYTE *start = (BYTE*)m_pManifest->GetFile()->GetLoadedImageContents(&size); + BYTE *start = (BYTE*)m_pManifest->GetPEAssembly()->GetLoadedImageContents(&size); if (start != NULL) { GCX_COOP(); @@ -381,14 +428,14 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C // Set up the assembly manifest metadata // When we create dynamic assembly, we always use a working copy of IMetaDataAssemblyEmit // to store temporary runtime assembly information. This is to preserve the invariant that - // an assembly must have a PEFile with proper metadata. + // an assembly must have a PEAssembly with proper metadata. // This working copy of IMetaDataAssemblyEmit will store every AssemblyRef as a simple name // reference as we must have an instance of Assembly(can be dynamic assembly) before we can // add such a reference. Also because the referenced assembly if dynamic strong name, it may // not be ready to be hashed! SafeComHolder pAssemblyEmit; - PEFile::DefineEmitScope( + DefineEmitScope( IID_IMetaDataAssemblyEmit, &pAssemblyEmit); @@ -453,7 +500,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C DWORD dwFlags = args->assemblyName->GetFlags(); // Now create a dynamic PE file out of the name & metadata - PEAssemblyHolder pFile; + PEAssemblyHolder pPEAssembly; { GCX_PREEMP(); @@ -462,7 +509,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C IfFailThrow(pAssemblyEmit->DefineAssembly(publicKey, publicKey.GetSize(), ulHashAlgId, name, &assemData, dwFlags, &ma)); - pFile = PEAssembly::Create(pCallerAssembly->GetManifestFile(), pAssemblyEmit); + pPEAssembly = PEAssembly::Create(pCallerAssembly->GetManifestFile(), pAssemblyEmit); AssemblyBinder* pFallbackBinder = pBinder; @@ -477,7 +524,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C // and will have a fallback load context binder associated with it. // There is always a manifest file - wehther working with static or dynamic assemblies. - PEFile* pCallerAssemblyManifestFile = pCallerAssembly->GetManifestFile(); + PEAssembly* pCallerAssemblyManifestFile = pCallerAssembly->GetManifestFile(); _ASSERTE(pCallerAssemblyManifestFile != NULL); if (!pCallerAssemblyManifestFile->IsDynamic()) @@ -503,7 +550,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C _ASSERTE(pFallbackBinder != nullptr); // Set it as the fallback load context binder for the dynamic assembly being created - pFile->SetFallbackBinder(pFallbackBinder); + pPEAssembly->SetFallbackBinder(pFallbackBinder); } NewHolder pDomainAssembly; @@ -551,7 +598,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C } // Create a domain assembly - pDomainAssembly = new DomainAssembly(pDomain, pFile, pLoaderAllocator); + pDomainAssembly = new DomainAssembly(pDomain, pPEAssembly, pLoaderAllocator); if (pDomainAssembly->IsCollectible()) { // We add the assembly to the LoaderAllocator only when we are sure that it can be added @@ -569,7 +616,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C { GCX_PREEMP(); // Assembly::Create will call SuppressRelease on the NewHolder that holds the LoaderAllocator when it transfers ownership - pAssem = Assembly::Create(pDomain, pFile, pDomainAssembly->GetDebuggerInfoBits(), pLoaderAllocator->IsCollectible(), pamTracker, pLoaderAllocator); + pAssem = Assembly::Create(pDomain, pPEAssembly, pDomainAssembly->GetDebuggerInfoBits(), pLoaderAllocator->IsCollectible(), pamTracker, pLoaderAllocator); ReflectionModule* pModule = (ReflectionModule*) pAssem->GetManifestModule(); pModule->SetCreatingAssembly( pCallerAssembly ); @@ -817,7 +864,7 @@ Module *Assembly::FindModuleByExportedType(mdExportedType mdType, // Note that we don't want to attempt a LoadModule if a GetModuleIfLoaded will // succeed, because it has a stronger contract. - Module *pModule = GetManifestModule()->GetModuleIfLoaded(mdLinkRef, TRUE, FALSE); + Module *pModule = GetManifestModule()->GetModuleIfLoaded(mdLinkRef); #ifdef DACCESS_COMPILE return pModule; #else @@ -830,7 +877,11 @@ Module *Assembly::FindModuleByExportedType(mdExportedType mdType, // We should never get here in the GC case - the above should have succeeded. CONSISTENCY_CHECK(!FORBIDGC_LOADER_USE_ENABLED()); - DomainFile * pDomainModule = GetManifestModule()->LoadModule(::GetAppDomain(), mdLinkRef, FALSE, loadFlag!=Loader::Load); + DomainFile* pDomainModule = NULL; + if (loadFlag == Loader::Load) + { + pDomainModule = GetManifestModule()->LoadModule(::GetAppDomain(), mdLinkRef); + } if (pDomainModule == NULL) RETURN NULL; @@ -953,18 +1004,18 @@ Module * Assembly::FindModuleByTypeRef( // Either we're not supposed to load, or we're doing a GC or stackwalk // in which case we shouldn't need to load. So just look up the module // and return what we find. - RETURN(pModule->LookupModule(tkType,FALSE)); + RETURN(pModule->LookupModule(tkType)); } #ifndef DACCESS_COMPILE - DomainFile * pActualDomainFile = pModule->LoadModule(::GetAppDomain(), tkType, FALSE, loadFlag!=Loader::Load); - if (pActualDomainFile == NULL) + if (loadFlag == Loader::Load) { - RETURN NULL; + DomainFile* pActualDomainFile = pModule->LoadModule(::GetAppDomain(), tkType); + RETURN(pActualDomainFile->GetModule()); } else { - RETURN(pActualDomainFile->GetModule()); + RETURN NULL; } #else //DACCESS_COMPILE @@ -1056,7 +1107,7 @@ Module *Assembly::FindModuleByName(LPCSTR pszModuleName) ThrowHR(COR_E_UNAUTHORIZEDACCESS); if (this == SystemDomain::SystemAssembly()) - RETURN m_pManifest->GetModuleIfLoaded(kFile, TRUE, TRUE); + RETURN m_pManifest->GetModuleIfLoaded(kFile); else RETURN m_pManifest->LoadModule(::GetAppDomain(), kFile)->GetModule(); } @@ -1124,7 +1175,7 @@ void Assembly::PrepareModuleForAssembly(Module* module, AllocMemTracker *pamTrac module->SetDebuggerInfoBits(GetDebuggerInfoBits()); LOG((LF_CORDB, LL_INFO10, "Module %s: bits=0x%x\n", - module->GetFile()->GetSimpleName(), + module->GetPEAssembly()->GetSimpleName(), module->GetDebuggerInfoBits())); #endif // DEBUGGING_SUPPORTED @@ -1648,7 +1699,7 @@ MethodDesc* Assembly::GetEntryPoint() Module *pModule = NULL; switch(TypeFromToken(mdEntry)) { case mdtFile: - pModule = m_pManifest->LoadModule(::GetAppDomain(), mdEntry, FALSE)->GetModule(); + pModule = m_pManifest->LoadModule(::GetAppDomain(), mdEntry)->GetModule(); mdEntry = pModule->GetEntryPointToken(); if ( (TypeFromToken(mdEntry) != mdtMethodDef) || @@ -1657,7 +1708,7 @@ MethodDesc* Assembly::GetEntryPoint() break; case mdtMethodDef: - if (m_pManifestFile->GetPersistentMDImport()->IsValidToken(mdEntry)) + if (m_pManifestFile->GetMDImport()->IsValidToken(mdEntry)) pModule = m_pManifest; break; } @@ -2240,7 +2291,7 @@ ReleaseHolder FriendAssemblyDescriptor::CreateFriendAs ReleaseHolder pFriendAssemblies = new FriendAssemblyDescriptor; // We're going to do this twice, once for InternalsVisibleTo and once for IgnoresAccessChecks - ReleaseHolder pImport(pAssembly->GetMDImportWithRef()); + IMDInternalImport* pImport = pAssembly->GetMDImport(); for(int count = 0 ; count < 2 ; ++count) { _ASSERTE(pImport != NULL); diff --git a/src/coreclr/vm/assembly.hpp b/src/coreclr/vm/assembly.hpp index db972f0ccf149..f8de5c162e752 100644 --- a/src/coreclr/vm/assembly.hpp +++ b/src/coreclr/vm/assembly.hpp @@ -79,13 +79,13 @@ class Assembly friend class ClrDataAccess; public: - Assembly(BaseDomain *pDomain, PEAssembly *pFile, DebuggerAssemblyControlFlags debuggerFlags, BOOL fIsCollectible); + Assembly(BaseDomain *pDomain, PEAssembly *pPEAssembly, DebuggerAssemblyControlFlags debuggerFlags, BOOL fIsCollectible); void Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocator); void StartUnload(); void Terminate( BOOL signalProfiler = TRUE ); - static Assembly *Create(BaseDomain *pDomain, PEAssembly *pFile, DebuggerAssemblyControlFlags debuggerFlags, BOOL fIsCollectible, AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocator); + static Assembly *Create(BaseDomain *pDomain, PEAssembly *pPEAssembly, DebuggerAssemblyControlFlags debuggerFlags, BOOL fIsCollectible, AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocator); static void Initialize(); BOOL IsSystem() { WRAPPER_NO_CONTRACT; return m_pManifestFile->IsSystem(); } @@ -299,7 +299,7 @@ class Assembly { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - return m_pManifestFile->GetPersistentMDImport(); + return m_pManifestFile->GetMDImport(); } HRESULT GetCustomAttribute(mdToken parentToken, @@ -312,14 +312,6 @@ class Assembly return GetManifestModule()->GetCustomAttribute(parentToken, attribute, ppData, pcbData); } -#ifndef DACCESS_COMPILE - IMetaDataAssemblyImport* GetManifestAssemblyImporter() - { - WRAPPER_NO_CONTRACT; - return m_pManifestFile->GetAssemblyImporter(); - } -#endif // DACCESS_COMPILE - mdAssembly GetManifestToken() { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/assemblybinder.cpp b/src/coreclr/vm/assemblybinder.cpp index 1ce6d2e93beb1..2e231741efbd3 100644 --- a/src/coreclr/vm/assemblybinder.cpp +++ b/src/coreclr/vm/assemblybinder.cpp @@ -32,7 +32,7 @@ NativeImage* AssemblyBinder::LoadNativeImage(Module* componentModule, LPCUTF8 na STANDARD_VM_CONTRACT; BaseDomain::LoadLockHolder lock(AppDomain::GetCurrentDomain()); - AssemblyBinder* binder = componentModule->GetFile()->GetAssemblyBinder(); + AssemblyBinder* binder = componentModule->GetPEAssembly()->GetAssemblyBinder(); PTR_LoaderAllocator moduleLoaderAllocator = componentModule->GetLoaderAllocator(); bool isNewNativeImage; diff --git a/src/coreclr/vm/assemblyname.cpp b/src/coreclr/vm/assemblyname.cpp index 0983c80715fae..c04a01408bbf8 100644 --- a/src/coreclr/vm/assemblyname.cpp +++ b/src/coreclr/vm/assemblyname.cpp @@ -56,7 +56,7 @@ FCIMPL1(Object*, AssemblyNameNative::GetFileInformation, StringObject* filenameU // waiting for it to happen during HasNTHeaders. This allows us to // get the assembly name for images that contain native code for a // non-native platform. - PEImageLayoutHolder pLayout(pImage->GetLayout(PEImageLayout::LAYOUT_FLAT, PEImage::LAYOUT_CREATEIFNEEDED)); + PEImageLayout* pLayout = pImage->GetOrCreateLayout(PEImageLayout::LAYOUT_FLAT); pImage->VerifyIsAssembly(); diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index 37d27fb1a9c25..a67c9e5c4c0b6 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -108,7 +108,7 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN { // If the requesting assembly has Fallback LoadContext binder available, // then set it up in the AssemblySpec. - PEFile *pRefAssemblyManifestFile = pRefAssembly->GetManifestFile(); + PEAssembly *pRefAssemblyManifestFile = pRefAssembly->GetManifestFile(); spec.SetFallbackBinderForRequestingAssembly(pRefAssemblyManifestFile->GetFallbackBinder()); } @@ -157,7 +157,7 @@ Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pIma // Set the caller's assembly to be CoreLib DomainAssembly *pCallersAssembly = SystemDomain::System()->SystemAssembly()->GetDomainAssembly(); - PEAssembly *pParentAssembly = pCallersAssembly->GetFile(); + PEAssembly *pParentAssembly = pCallersAssembly->GetPEAssembly(); // Initialize the AssemblySpec AssemblySpec spec; @@ -289,7 +289,7 @@ void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyBinder, I // we created above. We need pointer comparison instead of pe image equivalence // to avoid mixed binaries/PDB pairs of other images. // This applies to both Desktop CLR and CoreCLR, with or without fusion. - BOOL fIsSameAssembly = (pLoadedAssembly->GetManifestFile()->GetILimage() == pILImage); + BOOL fIsSameAssembly = (pLoadedAssembly->GetManifestFile()->GetPEImage() == pILImage); // Setting the PDB info is only applicable for our original assembly. // This applies to both Desktop CLR and CoreCLR, with or without fusion. @@ -351,7 +351,7 @@ void QCALLTYPE AssemblyNative::GetLocation(QCall::AssemblyHandle pAssembly, QCal BEGIN_QCALL; { - retString.Set(pAssembly->GetFile()->GetPath()); + retString.Set(pAssembly->GetPEAssembly()->GetPath()); } END_QCALL; @@ -449,7 +449,7 @@ FCIMPL1(FC_BOOL_RET, AssemblyNative::IsDynamic, AssemblyBaseObject* pAssemblyUNS if (refAssembly == NULL) FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle")); - FC_RETURN_BOOL(refAssembly->GetDomainAssembly()->GetFile()->IsDynamic()); + FC_RETURN_BOOL(refAssembly->GetDomainAssembly()->GetPEAssembly()->IsDynamic()); } FCIMPLEND @@ -461,7 +461,7 @@ void QCALLTYPE AssemblyNative::GetVersion(QCall::AssemblyHandle pAssembly, INT32 UINT16 major=0xffff, minor=0xffff, build=0xffff, revision=0xffff; - pAssembly->GetFile()->GetVersion(&major, &minor, &build, &revision); + pAssembly->GetPEAssembly()->GetVersion(&major, &minor, &build, &revision); *pMajorVersion = major; *pMinorVersion = minor; @@ -478,7 +478,7 @@ void QCALLTYPE AssemblyNative::GetPublicKey(QCall::AssemblyHandle pAssembly, QCa BEGIN_QCALL; DWORD cbPublicKey = 0; - const void *pbPublicKey = pAssembly->GetFile()->GetPublicKey(&cbPublicKey); + const void *pbPublicKey = pAssembly->GetPEAssembly()->GetPublicKey(&cbPublicKey); retPublicKey.SetByteArray((BYTE *)pbPublicKey, cbPublicKey); END_QCALL; @@ -499,7 +499,7 @@ void QCALLTYPE AssemblyNative::GetLocale(QCall::AssemblyHandle pAssembly, QCall: BEGIN_QCALL; - LPCUTF8 pLocale = pAssembly->GetFile()->GetLocale(); + LPCUTF8 pLocale = pAssembly->GetPEAssembly()->GetLocale(); if(pLocale) { retString.Set(pLocale); @@ -519,7 +519,7 @@ BOOL QCALLTYPE AssemblyNative::GetCodeBase(QCall::AssemblyHandle pAssembly, QCal StackSString codebase; { - ret = pAssembly->GetFile()->GetCodeBase(codebase); + ret = pAssembly->GetPEAssembly()->GetCodeBase(codebase); } retString.Set(codebase); @@ -534,7 +534,7 @@ INT32 QCALLTYPE AssemblyNative::GetHashAlgorithm(QCall::AssemblyHandle pAssembly INT32 retVal=0; BEGIN_QCALL; - retVal = pAssembly->GetFile()->GetHashAlgId(); + retVal = pAssembly->GetPEAssembly()->GetHashAlgId(); END_QCALL; return retVal; } @@ -545,7 +545,7 @@ INT32 QCALLTYPE AssemblyNative::GetFlags(QCall::AssemblyHandle pAssembly) INT32 retVal=0; BEGIN_QCALL; - retVal = pAssembly->GetFile()->GetFlags(); + retVal = pAssembly->GetPEAssembly()->GetFlags(); END_QCALL; return retVal; } @@ -639,9 +639,9 @@ void QCALLTYPE AssemblyNative::GetModules(QCall::AssemblyHandle pAssembly, BOOL mdFile mdFile; while (pAssembly->GetMDImport()->EnumNext(&phEnum, &mdFile)) { - DomainFile *pModule = pAssembly->GetModule()->LoadModule(GetAppDomain(), mdFile, fGetResourceModules, !fLoadIfNotFound); - - if (pModule) { + if (fLoadIfNotFound) + { + DomainFile* pModule = pAssembly->GetModule()->LoadModule(GetAppDomain(), mdFile); modules.Append(pModule); } } @@ -1065,7 +1065,7 @@ void QCALLTYPE AssemblyNative::GetFullName(QCall::AssemblyHandle pAssembly, QCal BEGIN_QCALL; StackSString name; - pAssembly->GetFile()->GetDisplayName(name); + pAssembly->GetPEAssembly()->GetDisplayName(name); retString.Set(name); END_QCALL; @@ -1135,12 +1135,12 @@ void QCALLTYPE AssemblyNative::GetImageRuntimeVersion(QCall::AssemblyHandle pAss BEGIN_QCALL; - // Retrieve the PEFile from the assembly. - PEFile* pPEFile = pAssembly->GetFile(); - PREFIX_ASSUME(pPEFile!=NULL); + // Retrieve the PEAssembly from the assembly. + PEAssembly* pPEAssembly = pAssembly->GetPEAssembly(); + PREFIX_ASSUME(pPEAssembly!=NULL); LPCSTR pszVersion = NULL; - IfFailThrow(pPEFile->GetMDImport()->GetVersionString(&pszVersion)); + IfFailThrow(pPEAssembly->GetMDImport()->GetVersionString(&pszVersion)); SString version(SString::Utf8, pszVersion); @@ -1253,7 +1253,7 @@ INT_PTR QCALLTYPE AssemblyNative::GetLoadContextForAssembly(QCall::AssemblyHandl _ASSERTE(pAssembly != NULL); - AssemblyBinder* pAssemblyBinder = pAssembly->GetFile()->GetAssemblyBinder(); + AssemblyBinder* pAssemblyBinder = pAssembly->GetPEAssembly()->GetAssemblyBinder(); if (!pAssemblyBinder->IsDefault()) { @@ -1284,7 +1284,7 @@ BOOL QCALLTYPE AssemblyNative::InternalTryGetRawMetadata( _ASSERTE(lengthRef != nullptr); static_assert_no_msg(sizeof(*lengthRef) == sizeof(COUNT_T)); - metadata = assembly->GetFile()->GetLoadedMetadata(reinterpret_cast(lengthRef)); + metadata = assembly->GetPEAssembly()->GetLoadedMetadata(reinterpret_cast(lengthRef)); *blobRef = reinterpret_cast(const_cast(metadata)); _ASSERTE(*lengthRef >= 0); diff --git a/src/coreclr/vm/assemblynative.hpp b/src/coreclr/vm/assemblynative.hpp index a4ecc62da9a32..6270e5072612e 100644 --- a/src/coreclr/vm/assemblynative.hpp +++ b/src/coreclr/vm/assemblynative.hpp @@ -108,7 +108,7 @@ class AssemblyNative static FCDECL0(uint32_t, GetAssemblyCount); // - // PEFile QCalls + // PEAssembly QCalls // static INT_PTR QCALLTYPE InitializeAssemblyLoadContext(INT_PTR ptrManagedAssemblyLoadContext, BOOL fRepresentsTPALoadContext, BOOL fIsCollectible); diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index af5862a9ac5ff..dfbee7152df19 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -231,7 +231,7 @@ void AssemblySpec::InitializeSpec(PEAssembly * pFile) INJECT_FAULT(COMPlusThrowOM();); } CONTRACTL_END; - ReleaseHolder pImport(pFile->GetMDImportWithRef()); + IMDInternalImport* pImport = pFile->GetMDImport(); mdAssembly a; IfFailThrow(pImport->GetAssemblyFromScope(&a)); @@ -690,7 +690,7 @@ AssemblyBinder* AssemblySpec::GetBinderFromParentAssembly(AppDomain *pDomain) if(pParentDomainAssembly != NULL) { // Get the PEAssembly associated with the parent's domain assembly - PEAssembly *pParentPEAssembly = pParentDomainAssembly->GetFile(); + PEAssembly *pParentPEAssembly = pParentDomainAssembly->GetPEAssembly(); pParentAssemblyBinder = pParentPEAssembly->GetAssemblyBinder(); } @@ -754,7 +754,7 @@ DomainAssembly *AssemblySpec::LoadDomainAssembly(FileLoadLevel targetLevel, if (pAssembly) { BinderTracing::AssemblyBindOperation bindOperation(this); - bindOperation.SetResult(pAssembly->GetFile(), true /*cached*/); + bindOperation.SetResult(pAssembly->GetPEAssembly(), true /*cached*/); pDomain->LoadDomainFile(pAssembly, targetLevel); RETURN pAssembly; @@ -1219,7 +1219,7 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly UPTR key = (UPTR)pSpec->Hash(); - AssemblyBinder* pBinderContextForLookup = pAssembly->GetFile()->GetAssemblyBinder(); + AssemblyBinder* pBinderContextForLookup = pAssembly->GetPEAssembly()->GetAssemblyBinder(); key = key ^ (UPTR)pBinderContextForLookup; if (!pSpec->GetBinder()) @@ -1240,13 +1240,13 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly } entry = abHolder.CreateAssemblyBinding(pHeap); - entry->Init(pSpec,pAssembly->GetFile(),pAssembly,NULL,pHeap, abHolder.GetPamTracker()); + entry->Init(pSpec,pAssembly->GetPEAssembly(),pAssembly,NULL,pHeap, abHolder.GetPamTracker()); m_map.InsertValue(key, entry); abHolder.SuppressRelease(); - STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StoreFile (StoreAssembly): Add cached entry (%p) with PEFile %p",entry,pAssembly->GetFile()); + STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly (StoreAssembly): Add cached entry (%p) with PEAssembly %p",entry,pAssembly->GetPEAssembly()); RETURN TRUE; } else @@ -1263,7 +1263,7 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly { // OK if we have have a matching PEAssembly if (entry->GetFile() != NULL - && pAssembly->GetFile()->Equals(entry->GetFile())) + && pAssembly->GetPEAssembly()->Equals(entry->GetFile())) { entry->SetAssembly(pAssembly); RETURN TRUE; @@ -1280,7 +1280,7 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly // Returns TRUE if add was successful - if FALSE is returned, caller should honor current // cached value to ensure consistency. -BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) +BOOL AssemblySpecBindingCache::StorePEAssembly(AssemblySpec *pSpec, PEAssembly *pPEAssembly) { CONTRACT(BOOL) { @@ -1288,14 +1288,14 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) THROWS; GC_TRIGGERS; MODE_ANY; - POSTCONDITION((!RETVAL) || (UnsafeContains(this, pSpec) && UnsafeVerifyLookupFile(this, pSpec, pFile))); + POSTCONDITION((!RETVAL) || (UnsafeContains(this, pSpec) && UnsafeVerifyLookupFile(this, pSpec, pPEAssembly))); INJECT_FAULT(COMPlusThrowOM();); } CONTRACT_END; UPTR key = (UPTR)pSpec->Hash(); - AssemblyBinder* pBinderContextForLookup = pFile->GetAssemblyBinder(); + AssemblyBinder* pBinderContextForLookup = pPEAssembly->GetAssemblyBinder(); key = key ^ (UPTR)pBinderContextForLookup; if (!pSpec->GetBinder()) @@ -1325,12 +1325,12 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) entry = abHolder.CreateAssemblyBinding(pHeap); - entry->Init(pSpec,pFile,NULL,NULL,pHeap, abHolder.GetPamTracker()); + entry->Init(pSpec, pPEAssembly,NULL,NULL,pHeap, abHolder.GetPamTracker()); m_map.InsertValue(key, entry); abHolder.SuppressRelease(); - STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StoreFile: Add cached entry (%p) with PEFile %p\n", entry, pFile); + STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly: Add cached entry (%p) with PEAssembly %p\n", entry, pPEAssembly); RETURN TRUE; } @@ -1340,7 +1340,7 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) { // OK if this is a duplicate if (entry->GetFile() != NULL - && pFile->Equals(entry->GetFile())) + && pPEAssembly->Equals(entry->GetFile())) RETURN TRUE; } else @@ -1350,7 +1350,7 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) entry->ThrowIfError(); } - STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"Incompatible cached entry found (%p) when adding PEFile %p\n", entry, pFile); + STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"Incompatible cached entry found (%p) when adding PEAssembly %p\n", entry, pPEAssembly); // Invalid cache transition (see above note about state transitions) RETURN FALSE; } @@ -1396,7 +1396,7 @@ BOOL AssemblySpecBindingCache::StoreException(AssemblySpec *pSpec, Exception* pE m_map.InsertValue(key, entry); abHolder.SuppressRelease(); - STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StoreFile (StoreException): Add cached entry (%p) with exception %p",entry,pEx); + STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly (StoreException): Add cached entry (%p) with exception %p",entry,pEx); RETURN TRUE; } else diff --git a/src/coreclr/vm/assemblyspec.hpp b/src/coreclr/vm/assemblyspec.hpp index 63ffac82f6e7a..5d09b5b75a664 100644 --- a/src/coreclr/vm/assemblyspec.hpp +++ b/src/coreclr/vm/assemblyspec.hpp @@ -102,7 +102,7 @@ class AssemblySpec : public BaseAssemblySpec }; - void InitializeSpec(PEAssembly *pFile); + void InitializeSpec(PEAssembly* pPEAssembly); HRESULT InitializeSpec(StackingAllocator* alloc, ASSEMBLYNAMEREF* pName, BOOL fParse = TRUE); @@ -332,8 +332,8 @@ class AssemblySpecBindingCache { WRAPPER_NO_CONTRACT; - if (m_pFile != NULL) - m_pFile->Release(); + if (m_pPEAssembly != NULL) + m_pPEAssembly->Release(); if (m_exceptionType==EXTYPE_EE) delete m_pException; @@ -341,7 +341,7 @@ class AssemblySpecBindingCache inline DomainAssembly* GetAssembly(){ LIMITED_METHOD_CONTRACT; return m_pAssembly;}; inline void SetAssembly(DomainAssembly* pAssembly){ LIMITED_METHOD_CONTRACT; m_pAssembly=pAssembly;}; - inline PEAssembly* GetFile(){ LIMITED_METHOD_CONTRACT; return m_pFile;}; + inline PEAssembly* GetFile(){ LIMITED_METHOD_CONTRACT; return m_pPEAssembly;}; inline BOOL IsError(){ LIMITED_METHOD_CONTRACT; return (m_exceptionType!=EXTYPE_NONE);}; // bound to the file, but failed later @@ -365,7 +365,7 @@ class AssemblySpecBindingCache default: _ASSERTE(!"Unexpected exception type"); } }; - inline void Init(AssemblySpec* pSpec, PEAssembly* pFile, DomainAssembly* pAssembly, Exception* pEx, LoaderHeap *pHeap, AllocMemTracker *pamTracker) + inline void Init(AssemblySpec* pSpec, PEAssembly* pPEAssembly, DomainAssembly* pAssembly, Exception* pEx, LoaderHeap *pHeap, AllocMemTracker *pamTracker) { CONTRACTL { @@ -375,7 +375,7 @@ class AssemblySpecBindingCache } CONTRACTL_END; - InitInternal(pSpec,pFile,pAssembly); + InitInternal(pSpec,pPEAssembly,pAssembly); if (pHeap != NULL) { m_spec.CloneFieldsToLoaderHeap(AssemblySpec::ALL_OWNED,pHeap, pamTracker); @@ -444,19 +444,19 @@ class AssemblySpecBindingCache }; protected: - inline void InitInternal(AssemblySpec* pSpec, PEAssembly* pFile, DomainAssembly* pAssembly ) + inline void InitInternal(AssemblySpec* pSpec, PEAssembly* pPEAssembly, DomainAssembly* pAssembly ) { WRAPPER_NO_CONTRACT; m_spec.CopyFrom(pSpec); - m_pFile = pFile; - if (m_pFile) - m_pFile->AddRef(); + m_pPEAssembly = pPEAssembly; + if (m_pPEAssembly) + m_pPEAssembly->AddRef(); m_pAssembly = pAssembly; m_exceptionType=EXTYPE_NONE; } AssemblySpec m_spec; - PEAssembly *m_pFile; + PEAssembly *m_pPEAssembly; DomainAssembly *m_pAssembly; enum{ EXTYPE_NONE = 0x00000000, @@ -490,7 +490,7 @@ class AssemblySpecBindingCache PEAssembly *LookupFile(AssemblySpec *pSpec, BOOL fThrow = TRUE); BOOL StoreAssembly(AssemblySpec *pSpec, DomainAssembly *pAssembly); - BOOL StoreFile(AssemblySpec *pSpec, PEAssembly *pFile); + BOOL StorePEAssembly(AssemblySpec *pSpec, PEAssembly *pPEAssembly); BOOL StoreException(AssemblySpec *pSpec, Exception* pEx); diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 3ffb9a83b1511..02374e18df61c 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -214,7 +214,7 @@ void Module::UpdateNewlyAddedTypes() // R2R pre-computes an export table and tries to avoid populating a class hash at runtime. However the profiler can // still add new types on the fly by calling here. If that occurs we fallback to the slower path of creating the // in memory hashtable as usual. - if (!IsResource() && GetAvailableClassHash() == NULL) + if (GetAvailableClassHash() == NULL) { // This call will populate the hash tables with anything that is in metadata already. GetClassLoader()->LazyPopulateCaseSensitiveHashTablesDontHaveLock(); @@ -266,12 +266,9 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr) if (SetTransientFlagInterlocked(IS_PROFILER_NOTIFIED)) { // Record how many types are already present - if (!IsResource()) - { - m_dwTypeCount = GetMDImport()->GetCountWithTokenKind(mdtTypeDef); - m_dwExportedTypeCount = GetMDImport()->GetCountWithTokenKind(mdtExportedType); - m_dwCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute); - } + m_dwTypeCount = GetMDImport()->GetCountWithTokenKind(mdtTypeDef); + m_dwExportedTypeCount = GetMDImport()->GetCountWithTokenKind(mdtExportedType); + m_dwCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute); BOOL profilerCallbackHappened = FALSE; // Notify the profiler, this may cause metadata to be updated @@ -294,7 +291,7 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr) // If there are more types than before, add these new types to the // assembly - if (profilerCallbackHappened && !IsResource()) + if (profilerCallbackHappened) { UpdateNewlyAddedTypes(); } @@ -337,7 +334,7 @@ void Module::NotifyEtwLoadFinished(HRESULT hr) // The constructor phase initializes just enough so that Destruct() can be safely called. // It cannot throw or fail. // -Module::Module(Assembly *pAssembly, mdFile moduleRef, PEFile *file) +Module::Module(Assembly *pAssembly, mdFile moduleRef, PEAssembly *pPEAssembly) { CONTRACTL { @@ -351,13 +348,13 @@ Module::Module(Assembly *pAssembly, mdFile moduleRef, PEFile *file) m_pAssembly = pAssembly; m_moduleRef = moduleRef; - m_file = file; + m_pPEAssembly = pPEAssembly; m_dwTransientFlags = CLASSES_FREED; // Memory allocated on LoaderHeap is zero-filled. Spot-check it here. _ASSERTE(m_pBinder == NULL); - file->AddRef(); + pPEAssembly->AddRef(); } void Module::InitializeForProfiling() @@ -457,7 +454,7 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) } CONTRACTL_END; - m_pSimpleName = m_file->GetSimpleName(); + m_pSimpleName = m_pPEAssembly->GetSimpleName(); m_Crst.Init(CrstModule); m_LookupTableCrst.Init(CrstModuleLookupTable, CrstFlags(CRST_UNSAFE_ANYMODE | CRST_DEBUGGER_THREAD)); @@ -486,62 +483,56 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) #ifdef FEATURE_READYTORUN m_pNativeImage = NULL; - if (!IsResource()) + if ((m_pReadyToRunInfo = ReadyToRunInfo::Initialize(this, pamTracker)) != NULL) { - if ((m_pReadyToRunInfo = ReadyToRunInfo::Initialize(this, pamTracker)) != NULL) + m_pNativeImage = m_pReadyToRunInfo->GetNativeImage(); + if (m_pNativeImage != NULL) { - m_pNativeImage = m_pReadyToRunInfo->GetNativeImage(); - if (m_pNativeImage != NULL) - { - m_NativeMetadataAssemblyRefMap = m_pNativeImage->GetManifestMetadataAssemblyRefMap(); - } - else + m_NativeMetadataAssemblyRefMap = m_pNativeImage->GetManifestMetadataAssemblyRefMap(); + } + else + { + // For composite images, manifest metadata gets loaded as part of the native image + COUNT_T cMeta = 0; + if (GetPEAssembly()->GetPEImage()->GetNativeManifestMetadata(&cMeta) != NULL) { - // For composite images, manifest metadata gets loaded as part of the native image - COUNT_T cMeta = 0; - if (GetFile()->GetOpenedILimage()->GetNativeManifestMetadata(&cMeta) != NULL) - { - // Load the native assembly import - GetNativeAssemblyImport(TRUE /* loadAllowed */); - } + // Load the native assembly import + GetNativeAssemblyImport(TRUE /* loadAllowed */); } } } #endif - // Initialize the instance fields that we need for all non-Resource Modules - if (!IsResource()) + // Initialize the instance fields that we need for all Modules + if (m_pAvailableClasses == NULL && !IsReadyToRun()) { - if (m_pAvailableClasses == NULL && !IsReadyToRun()) - { - m_pAvailableClasses = EEClassHashTable::Create(this, - GetAssembly()->IsCollectible() ? AVAILABLE_CLASSES_HASH_BUCKETS_COLLECTIBLE : AVAILABLE_CLASSES_HASH_BUCKETS, - FALSE /* bCaseInsensitive */, pamTracker); - } + m_pAvailableClasses = EEClassHashTable::Create(this, + GetAssembly()->IsCollectible() ? AVAILABLE_CLASSES_HASH_BUCKETS_COLLECTIBLE : AVAILABLE_CLASSES_HASH_BUCKETS, + FALSE /* bCaseInsensitive */, pamTracker); + } - if (m_pAvailableParamTypes == NULL) - { - m_pAvailableParamTypes = EETypeHashTable::Create(GetLoaderAllocator(), this, PARAMTYPES_HASH_BUCKETS, pamTracker); - } + if (m_pAvailableParamTypes == NULL) + { + m_pAvailableParamTypes = EETypeHashTable::Create(GetLoaderAllocator(), this, PARAMTYPES_HASH_BUCKETS, pamTracker); + } - if (m_pInstMethodHashTable == NULL) + if (m_pInstMethodHashTable == NULL) + { + m_pInstMethodHashTable = InstMethodHashTable::Create(GetLoaderAllocator(), this, PARAMMETHODS_HASH_BUCKETS, pamTracker); + } + + if (m_pMemberRefToDescHashTable == NULL) + { + if (IsReflection()) { - m_pInstMethodHashTable = InstMethodHashTable::Create(GetLoaderAllocator(), this, PARAMMETHODS_HASH_BUCKETS, pamTracker); + m_pMemberRefToDescHashTable = MemberRefToDescHashTable::Create(this, MEMBERREF_MAP_INITIAL_SIZE, pamTracker); } - - if(m_pMemberRefToDescHashTable == NULL) + else { - if (IsReflection()) - { - m_pMemberRefToDescHashTable = MemberRefToDescHashTable::Create(this, MEMBERREF_MAP_INITIAL_SIZE, pamTracker); - } - else - { - IMDInternalImport * pImport = GetMDImport(); + IMDInternalImport* pImport = GetMDImport(); - // Get #MemberRefs and create memberrefToDesc hash table - m_pMemberRefToDescHashTable = MemberRefToDescHashTable::Create(this, pImport->GetCountWithTokenKind(mdtMemberRef)+1, pamTracker); - } + // Get #MemberRefs and create memberrefToDesc hash table + m_pMemberRefToDescHashTable = MemberRefToDescHashTable::Create(this, pImport->GetCountWithTokenKind(mdtMemberRef) + 1, pamTracker); } } @@ -563,7 +554,7 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) InitializeForProfiling(); } - if (!IsResource() && (m_AssemblyRefByNameTable == NULL)) + if (m_AssemblyRefByNameTable == NULL) { Module::CreateAssemblyRefByNameTable(pamTracker); } @@ -744,16 +735,15 @@ void Module::SetDebuggerInfoBits(DebuggerAssemblyControlFlags newBits) #ifndef DACCESS_COMPILE /* static */ -Module *Module::Create(Assembly *pAssembly, mdFile moduleRef, PEFile *file, AllocMemTracker *pamTracker) +Module *Module::Create(Assembly *pAssembly, mdFile moduleRef, PEAssembly *pPEAssembly, AllocMemTracker *pamTracker) { CONTRACT(Module *) { STANDARD_VM_CHECK; PRECONDITION(CheckPointer(pAssembly)); - PRECONDITION(CheckPointer(file)); - PRECONDITION(!IsNilToken(moduleRef) || file->IsAssembly()); + PRECONDITION(CheckPointer(pPEAssembly)); POSTCONDITION(CheckPointer(RETVAL)); - POSTCONDITION(RETVAL->GetFile() == file); + POSTCONDITION(RETVAL->GetPEAssembly() == pPEAssembly); } CONTRACT_END; @@ -764,19 +754,19 @@ Module *Module::Create(Assembly *pAssembly, mdFile moduleRef, PEFile *file, Allo // Create the module #ifdef EnC_SUPPORTED - if (IsEditAndContinueCapable(pAssembly, file)) + if (IsEditAndContinueCapable(pAssembly, pPEAssembly)) { // if file is EnCCapable, always create an EnC-module, but EnC won't necessarily be enabled. // Debugger enables this by calling SetJITCompilerFlags on LoadModule callback. void* pMemory = pamTracker->Track(pAssembly->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(EditAndContinueModule)))); - pModule = new (pMemory) EditAndContinueModule(pAssembly, moduleRef, file); + pModule = new (pMemory) EditAndContinueModule(pAssembly, moduleRef, pPEAssembly); } else #endif // EnC_SUPPORTED { void* pMemory = pamTracker->Track(pAssembly->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(Module)))); - pModule = new (pMemory) Module(pAssembly, moduleRef, file); + pModule = new (pMemory) Module(pAssembly, moduleRef, pPEAssembly); } PREFIX_ASSUME(pModule != NULL); @@ -802,10 +792,7 @@ void Module::ApplyMetaData() ULONG ulCount; #if defined(PROFILING_SUPPORTED) || defined(EnC_SUPPORTED) - if (!IsResource()) - { - UpdateNewlyAddedTypes(); - } + UpdateNewlyAddedTypes(); #endif // PROFILING_SUPPORTED || EnC_SUPPORTED // Ensure for TypeRef @@ -953,7 +940,7 @@ void Module::Destruct() delete m_debuggerSpecificData.m_pILOffsetMappingTable; } - m_file->Release(); + m_pPEAssembly->Release(); // If this module was loaded as domain-specific, then // we must free its ModuleIndex so that it can be reused @@ -972,7 +959,7 @@ bool Module::NeedsGlobalMethodTable() CONTRACTL_END; IMDInternalImport * pImport = GetMDImport(); - if (!IsResource() && pImport->IsValidToken(COR_GLOBAL_PARENT_TOKEN)) + if (pImport->IsValidToken(COR_GLOBAL_PARENT_TOKEN)) { { HENUMInternalHolder funcEnum(pImport); @@ -1032,7 +1019,7 @@ MethodTable *Module::GetGlobalMethodTable() #endif // !DACCESS_COMPILE /*static*/ -BOOL Module::IsEditAndContinueCapable(Assembly *pAssembly, PEFile *file) +BOOL Module::IsEditAndContinueCapable(Assembly *pAssembly, PEAssembly *pPEAssembly) { CONTRACTL { @@ -1043,13 +1030,12 @@ BOOL Module::IsEditAndContinueCapable(Assembly *pAssembly, PEFile *file) } CONTRACTL_END; - _ASSERTE(pAssembly != NULL && file != NULL); + _ASSERTE(pAssembly != NULL && pPEAssembly != NULL); // Some modules are never EnC-capable return ! (pAssembly->GetDebuggerInfoBits() & DACF_ALLOW_JIT_OPTS || - file->IsSystem() || - file->IsResource() || - file->IsDynamic()); + pPEAssembly->IsSystem() || + pPEAssembly->IsDynamic()); } BOOL Module::IsManifest() @@ -1975,17 +1961,6 @@ void Module::AllocateStatics(AllocMemTracker *pamTracker) { STANDARD_VM_CONTRACT; - if (IsResource()) - { - m_dwRegularStaticsBlockSize = DomainLocalModule::OffsetOfDataBlob(); - m_dwThreadStaticsBlockSize = ThreadLocalModule::OffsetOfDataBlob(); - - // If it has no code, we don't have to allocate anything - LOG((LF_CLASSLOADER, LL_INFO10000, "STATICS: Resource module %s. No statics needed\n", GetSimpleName())); - _ASSERTE(m_maxTypeRidStaticsAllocated == 0); - return; - } - LOG((LF_CLASSLOADER, LL_INFO10000, "STATICS: Allocating statics for module %s\n", GetSimpleName())); // Build the offset table, which will tell us what the offsets for the statics of each class are (one offset for gc handles, one offset @@ -2114,9 +2089,6 @@ void Module::AllocateMaps() PTR_TADDR pTable = NULL; - if (IsResource()) - return; - if (IsReflection()) { // For dynamic modules, it is essential that we at least have a TypeDefToMethodTable @@ -2402,7 +2374,7 @@ BOOL Module::IsInSameVersionBubble(Module *target) { // Check if the current module's image has native manifest metadata, otherwise the current->GetNativeAssemblyImport() asserts. COUNT_T cMeta=0; - const void* pMeta = GetFile()->GetOpenedILimage()->GetNativeManifestMetadata(&cMeta); + const void* pMeta = GetPEAssembly()->GetPEImage()->GetNativeManifestMetadata(&cMeta); if (pMeta == NULL) { return FALSE; @@ -2529,10 +2501,6 @@ ISymUnmanagedReader *Module::GetISymUnmanagedReader(void) } CONTRACT_END; - // No symbols for resource modules - if (IsResource()) - RETURN NULL; - if (g_fEEShutDown) RETURN NULL; @@ -2565,16 +2533,15 @@ ISymUnmanagedReader *Module::GetISymUnmanagedReader(void) // There are 4 main cases here: // 1. Assembly is on disk and we'll get the symbols from a file next to the assembly - // 2. Assembly is provided by the host and we'll get the symbols from the host - // 3. Assembly was loaded in-memory (by byte array or ref-emit), and symbols were + // 2. Assembly was loaded in-memory (by byte array or ref-emit), and symbols were // provided along with it. - // 4. Assembly was loaded in-memory but no symbols were provided. + // 3. Assembly was loaded in-memory but no symbols were provided. - // Determine whether we should be looking in memory for the symbols (cases 2 & 3) - bool fInMemorySymbols = ( m_file->IsIStream() || GetInMemorySymbolStream() ); - if( !fInMemorySymbols && m_file->GetPath().IsEmpty() ) + // Determine whether we should be looking in memory for the symbols (case 2) + bool fInMemorySymbols = GetInMemorySymbolStream(); + if( !fInMemorySymbols && m_pPEAssembly->GetPath().IsEmpty() ) { - // Case 4. We don't have a module path, an IStream or an in memory symbol stream, + // Case 3. We don't have a module path or an in memory symbol stream, // so there is no-where to try and get symbols from. RETURN (NULL); } @@ -2657,7 +2624,7 @@ ISymUnmanagedReader *Module::GetISymUnmanagedReader(void) else { // The assembly is on disk, so try and load symbols based on the path to the assembly (case 1) - const SString &path = m_file->GetPath(); + const SString &path = m_pPEAssembly->GetPath(); // Call Fusion to ensure that any PDB's are shadow copied before // trying to get a symbol reader. This has to be done once per @@ -2856,7 +2823,6 @@ void Module::AddClass(mdTypeDef classdef) THROWS; GC_TRIGGERS; MODE_PREEMPTIVE; - PRECONDITION(!IsResource()); } CONTRACTL_END; @@ -2913,8 +2879,8 @@ void Module::BuildClassForModule() // Returns true iff the debugger should be notified about this module // // Notes: -// Debugger doesn't need to be notified about modules that can't be executed, -// like inspection and resource only. These are just pure data. +// Debugger doesn't need to be notified about modules that can't be executed. +// (we do not have such cases at the moment) // // This should be immutable for an instance of a module. That ensures that the debugger gets consistent // notifications about it. It this value mutates, than the debugger may miss relevant notifications. @@ -2923,11 +2889,6 @@ BOOL Module::IsVisibleToDebugger() WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - if (IsResource()) - { - return FALSE; - } - return TRUE; } @@ -2987,7 +2948,7 @@ TADDR Module::GetIL(DWORD target) if (target == 0) return NULL; - return m_file->GetIL(target); + return m_pPEAssembly->GetIL(target); } PTR_VOID Module::GetRvaField(DWORD rva) @@ -2995,7 +2956,7 @@ PTR_VOID Module::GetRvaField(DWORD rva) WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - return m_file->GetRvaField(rva); + return m_pPEAssembly->GetRvaField(rva); } #ifndef DACCESS_COMPILE @@ -3004,7 +2965,7 @@ CHECK Module::CheckRvaField(RVA field) { WRAPPER_NO_CONTRACT; if (!IsReflection()) - CHECK(m_file->CheckRvaField(field)); + CHECK(m_pPEAssembly->CheckRvaField(field)); CHECK_OK; } @@ -3018,7 +2979,7 @@ CHECK Module::CheckRvaField(RVA field, COUNT_T size) CONTRACTL_END; if (!IsReflection()) - CHECK(m_file->CheckRvaField(field, size)); + CHECK(m_pPEAssembly->CheckRvaField(field, size)); CHECK_OK; } @@ -3028,28 +2989,28 @@ BOOL Module::HasTls() { WRAPPER_NO_CONTRACT; - return m_file->HasTls(); + return m_pPEAssembly->HasTls(); } BOOL Module::IsRvaFieldTls(DWORD rva) { WRAPPER_NO_CONTRACT; - return m_file->IsRvaFieldTls(rva); + return m_pPEAssembly->IsRvaFieldTls(rva); } UINT32 Module::GetFieldTlsOffset(DWORD rva) { WRAPPER_NO_CONTRACT; - return m_file->GetFieldTlsOffset(rva); + return m_pPEAssembly->GetFieldTlsOffset(rva); } UINT32 Module::GetTlsIndex() { WRAPPER_NO_CONTRACT; - return m_file->GetTlsIndex(); + return m_pPEAssembly->GetTlsIndex(); } @@ -3077,7 +3038,7 @@ BOOL Module::IsSigInIL(PCCOR_SIGNATURE signature) } CONTRACTL_END; - return m_file->IsPtrInILImage(signature); + return m_pPEAssembly->IsPtrInPEImage(signature); } void Module::InitializeStringData(DWORD token, EEStringData *pstrData, CQuickBytes *pqb) @@ -3182,7 +3143,7 @@ mdToken Module::GetEntryPointToken() { WRAPPER_NO_CONTRACT; - return m_file->GetEntryPointToken(); + return m_pPEAssembly->GetEntryPointToken(); } BYTE *Module::GetProfilerBase() @@ -3195,13 +3156,13 @@ BYTE *Module::GetProfilerBase() } CONTRACT_END; - if (m_file == NULL) // I'd rather assert this is not the case... + if (m_pPEAssembly == NULL) // I'd rather assert this is not the case... { RETURN NULL; } - else if (m_file->IsLoaded()) + else if (m_pPEAssembly->HasLoadedPEImage()) { - RETURN (BYTE*)(m_file->GetLoadedIL()->GetBase()); + RETURN (BYTE*)(m_pPEAssembly->GetLoadedLayout()->GetBase()); } else { @@ -3413,20 +3374,18 @@ DomainAssembly * Module::LoadAssembly(mdAssemblyRef kAssemblyRef) } { - PEAssemblyHolder pFile = GetDomainAssembly()->GetFile()->LoadAssembly( - kAssemblyRef, - NULL); + PEAssemblyHolder pPEAssembly = GetDomainAssembly()->GetPEAssembly()->LoadAssembly(kAssemblyRef); AssemblySpec spec; spec.InitializeSpec(kAssemblyRef, GetMDImport(), GetDomainAssembly()); // Set the binding context in the AssemblySpec if one is available. This can happen if the LoadAssembly ended up // invoking the custom AssemblyLoadContext implementation that returned a reference to an assembly bound to a different // AssemblyLoadContext implementation. - AssemblyBinder *pBinder = pFile->GetAssemblyBinder(); + AssemblyBinder *pBinder = pPEAssembly->GetAssemblyBinder(); if (pBinder != NULL) { spec.SetBinder(pBinder); } - pDomainAssembly = GetAppDomain()->LoadDomainAssembly(&spec, pFile, FILE_LOADED); + pDomainAssembly = GetAppDomain()->LoadDomainAssembly(&spec, pPEAssembly, FILE_LOADED); } if (pDomainAssembly != NULL) @@ -3434,7 +3393,7 @@ DomainAssembly * Module::LoadAssembly(mdAssemblyRef kAssemblyRef) _ASSERTE( pDomainAssembly->IsSystem() || // GetAssemblyIfLoaded will not find CoreLib (see AppDomain::FindCachedFile) !pDomainAssembly->IsLoaded() || // GetAssemblyIfLoaded will not find not-yet-loaded assemblies - GetAssemblyIfLoaded(kAssemblyRef, NULL, FALSE, pDomainAssembly->GetFile()->GetHostAssembly()->GetBinder()) != NULL); // GetAssemblyIfLoaded should find all remaining cases + GetAssemblyIfLoaded(kAssemblyRef, NULL, FALSE, pDomainAssembly->GetPEAssembly()->GetHostAssembly()->GetBinder()) != NULL); // GetAssemblyIfLoaded should find all remaining cases if (pDomainAssembly->GetCurrentAssembly() != NULL) { @@ -3447,7 +3406,7 @@ DomainAssembly * Module::LoadAssembly(mdAssemblyRef kAssemblyRef) #endif // !DACCESS_COMPILE -Module *Module::GetModuleIfLoaded(mdFile kFile, BOOL onlyLoadedInAppDomain, BOOL permitResources) +Module *Module::GetModuleIfLoaded(mdFile kFile) { CONTRACT(Module *) { @@ -3479,7 +3438,7 @@ Module *Module::GetModuleIfLoaded(mdFile kFile, BOOL onlyLoadedInAppDomain, BOOL if (kFile == mdTokenNil) RETURN NULL; - RETURN GetAssembly()->GetManifestModule()->GetModuleIfLoaded(kFile, onlyLoadedInAppDomain, permitResources); + RETURN GetAssembly()->GetManifestModule()->GetModuleIfLoaded(kFile); } Module *pModule = LookupFile(kFile); @@ -3519,10 +3478,6 @@ Module *Module::GetModuleIfLoaded(mdFile kFile, BOOL onlyLoadedInAppDomain, BOOL #endif } - // We may not want to return a resource module - if (!permitResources && pModule && pModule->IsResource()) - pModule = NULL; - #ifndef DACCESS_COMPILE #endif // !DACCESS_COMPILE RETURN pModule; @@ -3530,8 +3485,7 @@ Module *Module::GetModuleIfLoaded(mdFile kFile, BOOL onlyLoadedInAppDomain, BOOL #ifndef DACCESS_COMPILE -DomainFile *Module::LoadModule(AppDomain *pDomain, mdFile kFile, - BOOL permitResources/*=TRUE*/, BOOL bindOnly/*=FALSE*/) +DomainFile *Module::LoadModule(AppDomain *pDomain, mdFile kFile) { CONTRACT(DomainFile *) { @@ -3541,38 +3495,32 @@ DomainFile *Module::LoadModule(AppDomain *pDomain, mdFile kFile, MODE_ANY; PRECONDITION(TypeFromToken(kFile) == mdtFile || TypeFromToken(kFile) == mdtModuleRef); - POSTCONDITION(CheckPointer(RETVAL, !permitResources || bindOnly ? NULL_OK : NULL_NOT_OK)); } CONTRACT_END; - if (bindOnly) + LPCSTR psModuleName=NULL; + if (TypeFromToken(kFile) == mdtModuleRef) { - RETURN NULL; + // This is a moduleRef + IfFailThrow(GetMDImport()->GetModuleRefProps(kFile, &psModuleName)); } else { - LPCSTR psModuleName=NULL; - if (TypeFromToken(kFile) == mdtModuleRef) - { - // This is a moduleRef - IfFailThrow(GetMDImport()->GetModuleRefProps(kFile, &psModuleName)); - } - else - { - // This is mdtFile - IfFailThrow(GetAssembly()->GetManifestImport()->GetFileProps(kFile, - &psModuleName, - NULL, - NULL, - NULL)); - } - SString name(SString::Utf8, psModuleName); - EEFileLoadException::Throw(name, COR_E_MULTIMODULEASSEMBLIESDIALLOWED, NULL); + // This is mdtFile + IfFailThrow(GetAssembly()->GetManifestImport()->GetFileProps(kFile, + &psModuleName, + NULL, + NULL, + NULL)); } + + SString name(SString::Utf8, psModuleName); + EEFileLoadException::Throw(name, COR_E_MULTIMODULEASSEMBLIESDIALLOWED, NULL); + RETURN NULL; } #endif // !DACCESS_COMPILE -PTR_Module Module::LookupModule(mdToken kFile,BOOL permitResources/*=TRUE*/) +PTR_Module Module::LookupModule(mdToken kFile) { CONTRACT(PTR_Module) { @@ -3598,7 +3546,7 @@ PTR_Module Module::LookupModule(mdToken kFile,BOOL permitResources/*=TRUE*/) if (kFileLocal == mdTokenNil) COMPlusThrowHR(COR_E_BADIMAGEFORMAT); - RETURN GetAssembly()->GetManifestModule()->LookupModule(kFileLocal, permitResources); + RETURN GetAssembly()->GetManifestModule()->LookupModule(kFileLocal); } PTR_Module pModule = LookupFile(kFile); @@ -4111,8 +4059,8 @@ BOOL Module::NotifyDebuggerLoad(AppDomain *pDomain, DomainFile * pDomainFile, in if (flags & ATTACH_MODULE_LOAD) { g_pDebugInterface->LoadModule(this, - m_file->GetPath(), - m_file->GetPath().GetCount(), + m_pPEAssembly->GetPath(), + m_pPEAssembly->GetPath().GetCount(), GetAssembly(), pDomain, pDomainFile, @@ -4168,9 +4116,9 @@ using GetTokenForVTableEntry_t = mdToken(STDMETHODCALLTYPE*)(HMODULE module, BYT static HMODULE GetIJWHostForModule(Module* module) { #if !defined(TARGET_UNIX) - PEDecoder* pe = module->GetFile()->GetLoadedIL(); + PEDecoder* pe = module->GetPEAssembly()->GetLoadedLayout(); - BYTE* baseAddress = (BYTE*)module->GetFile()->GetIJWBase(); + BYTE* baseAddress = (BYTE*)module->GetPEAssembly()->GetIJWBase(); IMAGE_IMPORT_DESCRIPTOR* importDescriptor = (IMAGE_IMPORT_DESCRIPTOR*)pe->GetDirectoryData(pe->GetDirectoryEntry(IMAGE_DIRECTORY_ENTRY_IMPORT)); @@ -4286,7 +4234,7 @@ void Module::FixupVTables() // If we've already fixed up, or this is not an IJW module, just return. // NOTE: This relies on ILOnly files not having fixups. If this changes, // we need to change this conditional. - if (IsIJWFixedUp() || m_file->IsILOnly()) { + if (IsIJWFixedUp() || m_pPEAssembly->IsILOnly()) { return; } @@ -4302,11 +4250,11 @@ void Module::FixupVTables() GetTokenForVTableEntryCallback = GetTokenForVTableEntry; } - HINSTANCE hInstThis = GetFile()->GetIJWBase(); + HINSTANCE hInstThis = GetPEAssembly()->GetIJWBase(); // Get vtable fixup data COUNT_T cFixupRecords; - IMAGE_COR_VTABLEFIXUP *pFixupTable = m_file->GetVTableFixups(&cFixupRecords); + IMAGE_COR_VTABLEFIXUP *pFixupTable = m_pPEAssembly->GetVTableFixups(&cFixupRecords); // No records then return if (cFixupRecords == 0) { @@ -4314,7 +4262,7 @@ void Module::FixupVTables() } // Now, we need to take a lock to serialize fixup. - PEImage::IJWFixupData *pData = PEImage::GetIJWData(m_file->GetIJWBase()); + PEImage::IJWFixupData *pData = PEImage::GetIJWData(m_pPEAssembly->GetIJWBase()); // If it's already been fixed (in some other appdomain), record the fact and return if (pData->IsFixedUp()) { @@ -4381,7 +4329,7 @@ void Module::FixupVTables() (pFixupTable[iFixup].Type == (COR_VTABLE_PTRSIZED | COR_VTABLE_FROM_UNMANAGED)) || (pFixupTable[iFixup].Type == (COR_VTABLE_PTRSIZED | COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN))) { - const BYTE** pPointers = (const BYTE **)m_file->GetVTable(pFixupTable[iFixup].RVA); + const BYTE** pPointers = (const BYTE **)m_pPEAssembly->GetVTable(pFixupTable[iFixup].RVA); for (int iMethod = 0; iMethod < pFixupTable[iFixup].Count; iMethod++) { if (pData->IsMethodFixedUp(iFixup, iMethod)) @@ -4465,7 +4413,7 @@ void Module::FixupVTables() continue; const BYTE** pPointers = (const BYTE **) - m_file->GetVTable(pFixupTable[iFixup].RVA); + m_pPEAssembly->GetVTable(pFixupTable[iFixup].RVA); // Vtables can be 32 or 64 bit. if (pFixupTable[iFixup].Type == COR_VTABLE_PTRSIZED) @@ -4556,7 +4504,7 @@ LoaderHeap *Module::GetDllThunkHeap() MODE_ANY; } CONTRACTL_END; - return PEImage::GetDllThunkHeap(GetFile()->GetIJWBase()); + return PEImage::GetDllThunkHeap(GetPEAssembly()->GetIJWBase()); } @@ -4661,7 +4609,7 @@ IMDInternalImport* Module::GetNativeAssemblyImport(BOOL loadAllowed) } CONTRACT_END; - RETURN GetFile()->GetOpenedILimage()->GetNativeMDImport(loadAllowed); + RETURN GetPEAssembly()->GetPEImage()->GetNativeMDImport(loadAllowed); } BYTE* Module::GetNativeFixupBlobData(RVA rva) @@ -4930,7 +4878,7 @@ HANDLE Module::OpenMethodProfileDataLogFile(GUID mvid) HANDLE profileDataFile = INVALID_HANDLE_VALUE; SString path; - LPCWSTR assemblyPath = m_file->GetPath(); + LPCWSTR assemblyPath = m_pPEAssembly->GetPath(); LPCWSTR ibcDir = g_pConfig->GetZapBBInstrDir(); // should we put the ibc data into a particular directory? if (ibcDir == 0) { path.Set(assemblyPath); // no, then put it beside the IL dll @@ -6402,9 +6350,6 @@ HRESULT Module::WriteMethodProfileDataLogFile(bool cleanup) HRESULT hr = S_OK; - if (IsResource()) - return S_OK; - EX_TRY { if (GetAssembly()->IsInstrumented() && (m_pProfilingBlobTable != NULL) && (m_tokenProfileData != NULL)) @@ -6990,14 +6935,14 @@ idMethodSpec Module::LogInstantiatedMethod(const MethodDesc * md, ULONG flagNum) // =========================================================================== /* static */ -ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName) +ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEAssembly *pPEAssembly, AllocMemTracker *pamTracker, LPCWSTR szName) { CONTRACT(ReflectionModule *) { STANDARD_VM_CHECK; PRECONDITION(CheckPointer(pAssembly)); - PRECONDITION(CheckPointer(pFile)); - PRECONDITION(pFile->IsDynamic()); + PRECONDITION(CheckPointer(pPEAssembly)); + PRECONDITION(pPEAssembly->IsDynamic()); POSTCONDITION(CheckPointer(RETVAL)); } CONTRACT_END; @@ -7005,14 +6950,13 @@ ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, A // Hoist CONTRACT into separate routine because of EX incompatibility mdFile token; - _ASSERTE(pFile->IsAssembly()); token = mdFileNil; // Initial memory block for Modules must be zero-initialized (to make it harder // to introduce Destruct crashes arising from OOM's during initialization.) void* pMemory = pamTracker->Track(pAssembly->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(ReflectionModule)))); - ReflectionModuleHolder pModule(new (pMemory) ReflectionModule(pAssembly, token, pFile)); + ReflectionModuleHolder pModule(new (pMemory) ReflectionModule(pAssembly, token, pPEAssembly)); pModule->DoInit(pamTracker, szName); @@ -7025,8 +6969,8 @@ ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, A // The constructor phase initializes just enough so that Destruct() can be safely called. // It cannot throw or fail. // -ReflectionModule::ReflectionModule(Assembly *pAssembly, mdFile token, PEFile *pFile) - : Module(pAssembly, token, pFile) +ReflectionModule::ReflectionModule(Assembly *pAssembly, mdFile token, PEAssembly *pPEAssembly) + : Module(pAssembly, token, pPEAssembly) { CONTRACTL { @@ -7569,9 +7513,9 @@ void Module::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, m_ModuleID->EnumMemoryRegions(flags); } - if (m_file.IsValid()) + if (m_pPEAssembly.IsValid()) { - m_file->EnumMemoryRegions(flags); + m_pPEAssembly->EnumMemoryRegions(flags); } if (m_pAssembly.IsValid()) { @@ -7724,11 +7668,11 @@ LPCWSTR Module::GetPathForErrorMessages() } CONTRACTL_END - PEFile *pFile = GetFile(); + PEAssembly *pPEAssembly = GetPEAssembly(); - if (pFile) + if (pPEAssembly) { - return pFile->GetPathForErrorMessages(); + return pPEAssembly->GetPathForErrorMessages(); } else { diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 2e3b474ef298a..e7dd5629a2c84 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -19,7 +19,7 @@ #include "corsym.h" #include "typehandle.h" #include "arraylist.h" -#include "pefile.h" +#include "peassembly.h" #include "typehash.h" #include "contractimpl.h" #include "bitmask.h" @@ -43,7 +43,6 @@ #include "ilinstrumentation.h" -class PELoader; class Stub; class MethodDesc; class FieldDesc; @@ -736,7 +735,7 @@ struct ThreadLocalModule; // Native code (NGEN module). A module live in a code:Assembly // // Some important fields are -// * code:Module.m_file - this points at a code:PEFile that understands the layout of a PE file. The most +// * code:Module.m_pPEAssembly - this points at a code:PEAssembly that understands the layout of a PE assembly. The most // important part is getting at the code:Module (see file:..\inc\corhdr.h#ManagedHeader) from there // you can get at the Meta-data and IL) // * code:Module.m_pAvailableClasses - this is a table that lets you look up the types (the code:EEClass) @@ -758,7 +757,7 @@ class Module private: PTR_CUTF8 m_pSimpleName; // Cached simple name for better performance and easier diagnostics - PTR_PEFile m_file; + PTR_PEAssembly m_pPEAssembly; enum { // These are the values set in m_dwTransientFlags. @@ -1079,10 +1078,10 @@ class Module #endif // _DEBUG public: - static Module *Create(Assembly *pAssembly, mdFile kFile, PEFile *pFile, AllocMemTracker *pamTracker); + static Module *Create(Assembly *pAssembly, mdFile kFile, PEAssembly *pPEAssembly, AllocMemTracker *pamTracker); protected: - Module(Assembly *pAssembly, mdFile moduleRef, PEFile *file); + Module(Assembly *pAssembly, mdFile moduleRef, PEAssembly *file); public: @@ -1092,9 +1091,7 @@ class Module PTR_LoaderAllocator GetLoaderAllocator(); - PTR_PEFile GetFile() const { LIMITED_METHOD_DAC_CONTRACT; return m_file; } - - static size_t GetFileOffset() { LIMITED_METHOD_CONTRACT; return offsetof(Module, m_file); } + PTR_PEAssembly GetPEAssembly() const { LIMITED_METHOD_DAC_CONTRACT; return m_pPEAssembly; } BOOL IsManifest(); @@ -1153,10 +1150,8 @@ class Module return m_moduleRef; } - BOOL IsResource() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return GetFile()->IsResource(); } - BOOL IsPEFile() const { WRAPPER_NO_CONTRACT; return !GetFile()->IsDynamic(); } - BOOL IsReflection() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return GetFile()->IsDynamic(); } - BOOL IsIbcOptimized() const { WRAPPER_NO_CONTRACT; return GetFile()->IsIbcOptimized(); } + BOOL IsPEFile() const { WRAPPER_NO_CONTRACT; return !GetPEAssembly()->IsDynamic(); } + BOOL IsReflection() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return GetPEAssembly()->IsDynamic(); } // Returns true iff the debugger can see this module. BOOL IsVisibleToDebugger(); @@ -1170,11 +1165,9 @@ class Module virtual BOOL IsEditAndContinueCapable() const { return FALSE; } - BOOL IsIStream() { LIMITED_METHOD_CONTRACT; return GetFile()->IsIStream(); } - - BOOL IsSystem() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return m_file->IsSystem(); } + BOOL IsSystem() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return m_pPEAssembly->IsSystem(); } - static BOOL IsEditAndContinueCapable(Assembly *pAssembly, PEFile *file); + static BOOL IsEditAndContinueCapable(Assembly *pAssembly, PEAssembly *file); void EnableEditAndContinue() { @@ -1265,7 +1258,7 @@ class Module return DacGetMDImport(GetReflectionModule(), true); } #endif // DACCESS_COMPILE - return m_file->GetPersistentMDImport(); + return m_pPEAssembly->GetMDImport(); } #ifndef DACCESS_COMPILE @@ -1273,21 +1266,14 @@ class Module { WRAPPER_NO_CONTRACT; - return m_file->GetEmitter(); + return m_pPEAssembly->GetEmitter(); } IMetaDataImport2 *GetRWImporter() { WRAPPER_NO_CONTRACT; - return m_file->GetRWImporter(); - } - - IMetaDataAssemblyImport *GetAssemblyImporter() - { - WRAPPER_NO_CONTRACT; - - return m_file->GetAssemblyImporter(); + return m_pPEAssembly->GetRWImporter(); } HRESULT GetReadablePublicMetaDataInterface(DWORD dwOpenFlags, REFIID riid, LPVOID * ppvInterface); @@ -1379,54 +1365,26 @@ class Module { LIMITED_METHOD_CONTRACT; SUPPORTS_DAC; - { - // IsResource() may lock when accessing metadata, but this is only in debug, - // for the assert below - CONTRACT_VIOLATION(TakesLockViolation); - - _ASSERTE(!IsResource()); - } return m_pAvailableClasses; } #ifndef DACCESS_COMPILE void SetAvailableClassHash(EEClassHashTable *pAvailableClasses) { - LIMITED_METHOD_CONTRACT; - { - // IsResource() may lock when accessing metadata, but this is only in debug, - // for the assert below - CONTRACT_VIOLATION(TakesLockViolation); - _ASSERTE(!IsResource()); - } m_pAvailableClasses = pAvailableClasses; } #endif // !DACCESS_COMPILE PTR_EEClassHashTable GetAvailableClassCaseInsHash() { LIMITED_METHOD_CONTRACT; - SUPPORTS_DAC; - { - // IsResource() may lock when accessing metadata, but this is only in debug, - // for the assert below - CONTRACT_VIOLATION(TakesLockViolation); - _ASSERTE(!IsResource()); - } return m_pAvailableClassesCaseIns; } #ifndef DACCESS_COMPILE void SetAvailableClassCaseInsHash(EEClassHashTable *pAvailableClassesCaseIns) { - LIMITED_METHOD_CONTRACT; - { - // IsResource() may lock when accessing metadata, but this is only in debug, - // for the assert below - CONTRACT_VIOLATION(TakesLockViolation); - _ASSERTE(!IsResource()); - } m_pAvailableClassesCaseIns = pAvailableClassesCaseIns; } #endif // !DACCESS_COMPILE @@ -1436,26 +1394,14 @@ class Module { LIMITED_METHOD_CONTRACT; SUPPORTS_DAC; - { - // IsResource() may lock when accessing metadata, but this is only in debug, - // for the assert below - CONTRACT_VIOLATION(TakesLockViolation); - _ASSERTE(!IsResource()); - } return m_pAvailableParamTypes; } InstMethodHashTable *GetInstMethodHashTable() { LIMITED_METHOD_CONTRACT; - { - // IsResource() may lock when accessing metadata, but this is only in debug, - // for the assert below - CONTRACT_VIOLATION(TakesLockViolation); - _ASSERTE(!IsResource()); - } return m_pInstMethodHashTable; } @@ -1484,9 +1430,9 @@ class Module public: DomainAssembly * LoadAssembly(mdAssemblyRef kAssemblyRef); - Module *GetModuleIfLoaded(mdFile kFile, BOOL onlyLoadedInAppDomain, BOOL loadAllowed); - DomainFile *LoadModule(AppDomain *pDomain, mdFile kFile, BOOL loadResources = TRUE, BOOL bindOnly = FALSE); - PTR_Module LookupModule(mdToken kFile, BOOL loadResources = TRUE); //wrapper over GetModuleIfLoaded, takes modulerefs as well + Module *GetModuleIfLoaded(mdFile kFile); + DomainFile *LoadModule(AppDomain *pDomain, mdFile kFile); + PTR_Module LookupModule(mdToken kFile); //wrapper over GetModuleIfLoaded, takes modulerefs as well DWORD GetAssemblyRefFlags(mdAssemblyRef tkAssemblyRef); // RID maps @@ -1806,8 +1752,8 @@ class Module public: #ifndef DACCESS_COMPILE - BOOL Equals(Module *pModule) { WRAPPER_NO_CONTRACT; return m_file->Equals(pModule->m_file); } - BOOL Equals(PEFile *pFile) { WRAPPER_NO_CONTRACT; return m_file->Equals(pFile); } + BOOL Equals(Module *pModule) { WRAPPER_NO_CONTRACT; return m_pPEAssembly->Equals(pModule->m_pPEAssembly); } + BOOL Equals(PEAssembly *pPEAssembly) { WRAPPER_NO_CONTRACT; return m_pPEAssembly->Equals(pPEAssembly); } #endif // !DACCESS_COMPILE LPCUTF8 GetSimpleName() @@ -1817,11 +1763,11 @@ class Module return m_pSimpleName; } - HRESULT GetScopeName(LPCUTF8 * pszName) { WRAPPER_NO_CONTRACT; return m_file->GetScopeName(pszName); } - const SString &GetPath() { WRAPPER_NO_CONTRACT; return m_file->GetPath(); } + HRESULT GetScopeName(LPCUTF8 * pszName) { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetScopeName(pszName); } + const SString &GetPath() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetPath(); } #ifdef LOGGING - LPCWSTR GetDebugName() { WRAPPER_NO_CONTRACT; return m_file->GetDebugName(); } + LPCWSTR GetDebugName() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetDebugName(); } #endif PEImageLayout * GetReadyToRunImage(); @@ -1837,7 +1783,7 @@ class Module CHECK CheckRvaField(RVA field, COUNT_T size); const void *GetInternalPInvokeTarget(RVA target) - { WRAPPER_NO_CONTRACT; return m_file->GetInternalPInvokeTarget(target); } + { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetInternalPInvokeTarget(target); } BOOL HasTls(); BOOL IsRvaFieldTls(DWORD field); @@ -2268,7 +2214,7 @@ class ReflectionModule : public Module bool m_fSuppressMetadataCapture; #if !defined DACCESS_COMPILE - ReflectionModule(Assembly *pAssembly, mdFile token, PEFile *pFile); + ReflectionModule(Assembly *pAssembly, mdFile token, PEAssembly *pPEAssembly); #endif // !DACCESS_COMPILE public: @@ -2279,7 +2225,7 @@ class ReflectionModule : public Module #endif #if !defined DACCESS_COMPILE - static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName); + static ReflectionModule *Create(Assembly *pAssembly, PEAssembly *pPEAssembly, AllocMemTracker *pamTracker, LPCWSTR szName); void Initialize(AllocMemTracker *pamTracker, LPCWSTR szName); void Destruct(); #endif // !DACCESS_COMPILE diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index 9c68686b31d6e..8f347255d4e0d 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -848,7 +848,6 @@ void EEStartupHelper() // Setup the domains. Threads are started in a default domain. // Static initialization - PEAssembly::Attach(); BaseDomain::Attach(); SystemDomain::Attach(); diff --git a/src/coreclr/vm/clrex.cpp b/src/coreclr/vm/clrex.cpp index b4959ad479237..a1fe3e4c8985d 100644 --- a/src/coreclr/vm/clrex.cpp +++ b/src/coreclr/vm/clrex.cpp @@ -1733,7 +1733,7 @@ void DECLSPEC_NORETURN EEFileLoadException::Throw(AssemblySpec *pSpec, HRESULT } /* static */ -void DECLSPEC_NORETURN EEFileLoadException::Throw(PEFile *pFile, HRESULT hr, Exception *pInnerException /* = NULL*/) +void DECLSPEC_NORETURN EEFileLoadException::Throw(PEAssembly *pPEAssembly, HRESULT hr, Exception *pInnerException /* = NULL*/) { CONTRACTL { @@ -1749,11 +1749,8 @@ void DECLSPEC_NORETURN EEFileLoadException::Throw(PEFile *pFile, HRESULT hr, Exc COMPlusThrowOM(); StackSString name; + pPEAssembly->GetDisplayName(name); - if (pFile->IsAssembly()) - ((PEAssembly*)pFile)->GetDisplayName(name); - else - name = StackSString(SString::Utf8, pFile->GetSimpleName()); EX_THROW_WITH_INNER(EEFileLoadException, (name, hr), pInnerException); } diff --git a/src/coreclr/vm/clrex.h b/src/coreclr/vm/clrex.h index 569e8442854cd..cf7d458f90ff3 100644 --- a/src/coreclr/vm/clrex.h +++ b/src/coreclr/vm/clrex.h @@ -18,7 +18,6 @@ class BaseBind; class AssemblySpec; -class PEFile; class PEAssembly; enum StackTraceElementFlags @@ -678,7 +677,7 @@ class EEFileLoadException : public EEException static RuntimeExceptionKind GetFileLoadKind(HRESULT hr); static void DECLSPEC_NORETURN Throw(AssemblySpec *pSpec, HRESULT hr, Exception *pInnerException = NULL); - static void DECLSPEC_NORETURN Throw(PEFile *pFile, HRESULT hr, Exception *pInnerException = NULL); + static void DECLSPEC_NORETURN Throw(PEAssembly *pPEAssembly, HRESULT hr, Exception *pInnerException = NULL); static void DECLSPEC_NORETURN Throw(LPCWSTR path, HRESULT hr, Exception *pInnerException = NULL); static void DECLSPEC_NORETURN Throw(PEAssembly *parent, const void *memory, COUNT_T size, HRESULT hr, Exception *pInnerException = NULL); static BOOL CheckType(Exception* ex); // typeof(EEFileLoadException) diff --git a/src/coreclr/vm/clsload.cpp b/src/coreclr/vm/clsload.cpp index 8b53e019d39aa..9392f6c11d93e 100644 --- a/src/coreclr/vm/clsload.cpp +++ b/src/coreclr/vm/clsload.cpp @@ -654,8 +654,6 @@ void ClassLoader::GetClassValue(NameHandleTable nhTable, Module * pCurrentClsModule = i.GetModule(); PREFIX_ASSUME(pCurrentClsModule != NULL); - if (pCurrentClsModule->IsResource()) - continue; if (pLookInThisModuleOnly && (pCurrentClsModule != pLookInThisModuleOnly)) continue; @@ -844,7 +842,7 @@ void ClassLoader::LazyPopulateCaseSensitiveHashTables() { Module *pModule = i.GetModule(); PREFIX_ASSUME(pModule != NULL); - if (pModule->IsResource() || pModule->GetAvailableClassHash() != NULL) + if (pModule->GetAvailableClassHash() != NULL) continue; // Lazy construction of the case-sensitive hashtable of types is *only* a scenario for ReadyToRun images @@ -858,16 +856,13 @@ void ClassLoader::LazyPopulateCaseSensitiveHashTables() } // Add exported types of the manifest module to the hashtable - if (!GetAssembly()->GetManifestModule()->IsResource()) - { - IMDInternalImport * pManifestImport = GetAssembly()->GetManifestImport(); - HENUMInternalHolder phEnum(pManifestImport); - phEnum.EnumInit(mdtExportedType, mdTokenNil); + IMDInternalImport * pManifestImport = GetAssembly()->GetManifestImport(); + HENUMInternalHolder phEnum(pManifestImport); + phEnum.EnumInit(mdtExportedType, mdTokenNil); - mdToken mdExportedType; - while (pManifestImport->EnumNext(&phEnum, &mdExportedType)) - AddExportedTypeHaveLock(GetAssembly()->GetManifestModule(), mdExportedType, &amTracker); - } + mdToken mdExportedType; + while (pManifestImport->EnumNext(&phEnum, &mdExportedType)) + AddExportedTypeHaveLock(GetAssembly()->GetManifestModule(), mdExportedType, &amTracker); amTracker.SuppressRelease(); } @@ -884,7 +879,7 @@ void ClassLoader::LazyPopulateCaseInsensitiveHashTables() } CONTRACTL_END; - if (!GetAssembly()->GetManifestModule()->IsResource() && GetAssembly()->GetManifestModule()->GetAvailableClassHash() == NULL) + if (GetAssembly()->GetManifestModule()->GetAvailableClassHash() == NULL) { // This is a R2R assembly, and a case insensitive type lookup was triggered. // Construct the case-sensitive table first, since the case-insensitive table @@ -900,9 +895,6 @@ void ClassLoader::LazyPopulateCaseInsensitiveHashTables() while (i.Next()) { Module *pModule = i.GetModule(); - if (pModule->IsResource()) - continue; - if (pModule->GetAvailableClassCaseInsHash() == NULL) { EEClassHashTable *pNewClassCaseInsHash = pModule->GetAvailableClassHash()->MakeCaseInsensitiveTable(pModule, &amTracker); diff --git a/src/coreclr/vm/commodule.cpp b/src/coreclr/vm/commodule.cpp index 99b4982329f04..c00a08336a7c2 100644 --- a/src/coreclr/vm/commodule.cpp +++ b/src/coreclr/vm/commodule.cpp @@ -651,26 +651,13 @@ void QCALLTYPE COMModule::GetScopeName(QCall::ModuleHandle pModule, QCall::Strin BEGIN_QCALL; - LPCSTR szName = NULL; - - if (pModule->IsResource()) - { - IfFailThrow(pModule->GetAssembly()->GetManifestImport()->GetFileProps( - pModule->GetModuleRef(), - &szName, - NULL, - NULL, - NULL)); - } - else + if (!pModule->GetMDImport()->IsValidToken(pModule->GetMDImport()->GetModuleFromScope())) { - if (!pModule->GetMDImport()->IsValidToken(pModule->GetMDImport()->GetModuleFromScope())) - { - ThrowHR(COR_E_BADIMAGEFORMAT); - } - IfFailThrow(pModule->GetMDImport()->GetScopeProps(&szName, 0)); + ThrowHR(COR_E_BADIMAGEFORMAT); } + LPCSTR szName = NULL; + IfFailThrow(pModule->GetMDImport()->GetScopeProps(&szName, 0)); retString.Set(szName); END_QCALL; @@ -734,10 +721,10 @@ HINSTANCE QCALLTYPE COMModule::GetHINSTANCE(QCall::ModuleHandle pModule) // This returns the base address // Other modules should have zero base - PEFile *pPEFile = pModule->GetFile(); - if (!pPEFile->IsDynamic() && !pPEFile->IsResource()) + PEAssembly *pPEAssembly = pModule->GetPEAssembly(); + if (!pPEAssembly->IsDynamic()) { - hMod = (HMODULE) pModule->GetFile()->GetManagedFileContents(); + hMod = (HMODULE) pModule->GetPEAssembly()->GetManagedFileContents(); } //If we don't have an hMod, set it to -1 so that they know that there's none @@ -801,12 +788,6 @@ Object* GetTypesInner(Module* pModule) int AllocSize = 0; MethodTable* pMT = NULL; - if (pModule->IsResource()) - { - refArrClasses = (PTRARRAYREF) AllocateObjectArray(0, CoreLibBinder::GetClass(CLASS__CLASS)); - RETURN(OBJECTREFToObject(refArrClasses)); - } - GCPROTECT_BEGIN(refArrClasses); GCPROTECT_BEGIN(xcept); @@ -890,15 +871,3 @@ Object* GetTypesInner(Module* pModule) RETURN(OBJECTREFToObject(refArrClasses)); } - - -FCIMPL1(FC_BOOL_RET, COMModule::IsResource, ReflectModuleBaseObject* pModuleUNSAFE) -{ - FCALL_CONTRACT; - - if (pModuleUNSAFE == NULL) - FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle")); - - FC_RETURN_BOOL(pModuleUNSAFE->GetModule()->IsResource()); -} -FCIMPLEND diff --git a/src/coreclr/vm/commodule.h b/src/coreclr/vm/commodule.h index c995ec80dfd82..4453214c473a5 100644 --- a/src/coreclr/vm/commodule.h +++ b/src/coreclr/vm/commodule.h @@ -90,8 +90,6 @@ class COMModule static void QCALLTYPE SetModuleName(QCall::ModuleHandle pModule, LPCWSTR wszModuleName); - static FCDECL1(FC_BOOL_RET, IsResource, ReflectModuleBaseObject* pModuleUNSAFE); - static FCDECL1(Object*, GetMethods, ReflectModuleBaseObject* refThisUNSAFE); static diff --git a/src/coreclr/vm/common.h b/src/coreclr/vm/common.h index 7d2f3532219a3..bcd9af84555c6 100644 --- a/src/coreclr/vm/common.h +++ b/src/coreclr/vm/common.h @@ -345,7 +345,7 @@ inline void ClrRestoreNonvolatileContext(PCONTEXT ContextRecord) #include "specialstatics.h" #include "object.h" // We should not really need to put this so early... #include "gchelpers.h" -#include "pefile.h" +#include "peassembly.h" #include "clrex.h" #include "clsload.hpp" // We should not really need to put this so early... #include "siginfo.hpp" @@ -362,7 +362,7 @@ inline void ClrRestoreNonvolatileContext(PCONTEXT ContextRecord) #include "appdomain.hpp" #include "appdomain.inl" #include "assembly.hpp" -#include "pefile.inl" +#include "peassembly.inl" #include "excep.h" #include "method.hpp" #include "field.h" diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 9d1547cda8edd..eaaddafdbe9c6 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -116,7 +116,7 @@ STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, { PEImageHolder pImage = PEImage::OpenImage(wszAssemblyPath, MDInternalImport_Default, bundleFileLocation); - // Make sure that the IL image can be opened if the native image is not available. + // Make sure that the IL image can be opened. hr=pImage->TryOpenFile(); if (FAILED(hr)) { @@ -144,7 +144,7 @@ STDAPI BinderAcquireImport(PEImage *pPEImage, EX_TRY { - PEImageLayoutHolder pLayout(pPEImage->GetLayout(PEImageLayout::LAYOUT_ANY,PEImage::LAYOUT_CREATEIFNEEDED)); + PEImageLayout* pLayout = pPEImage->GetOrCreateLayout(PEImageLayout::LAYOUT_ANY); // CheckCorHeader includes check of NT headers too if (!pLayout->CheckCorHeader()) diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index a4b2bfa74a876..861ec15be77a8 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -612,8 +612,6 @@ HRESULT CorHost2::CreateAppDomainWithManager( if (dwFlags & APPDOMAIN_FORCE_TRIVIAL_WAIT_OPERATIONS) pDomain->SetForceTrivialWaitOperations(); - pDomain->CreateBinderContext(); - { GCX_COOP(); diff --git a/src/coreclr/vm/debugdebugger.cpp b/src/coreclr/vm/debugdebugger.cpp index e21939990405c..e6313d9c20be9 100644 --- a/src/coreclr/vm/debugdebugger.cpp +++ b/src/coreclr/vm/debugdebugger.cpp @@ -713,11 +713,11 @@ FCIMPL4(void, DebugStackTrace::GetStackFramesInternal, I4 *pMethodToken = (I4 *)((I4ARRAYREF)pStackFrameHelper->rgiMethodToken)->GetDirectPointerToNonObjectElements(); pMethodToken[iNumValidFrames] = pMethod->GetMemberDef(); - PEFile *pPEFile = pModule->GetFile(); + PEAssembly *pPEAssembly = pModule->GetPEAssembly(); // Get the address and size of the loaded PE image COUNT_T peSize; - PTR_CVOID peAddress = pPEFile->GetLoadedImageContents(&peSize); + PTR_CVOID peAddress = pPEAssembly->GetLoadedImageContents(&peSize); // Save the PE address and size PTR_CVOID *pLoadedPeAddress = (PTR_CVOID *)pStackFrameHelper->rgLoadedPeAddress->GetDataPtr(); @@ -727,11 +727,11 @@ FCIMPL4(void, DebugStackTrace::GetStackFramesInternal, pLoadedPeSize[iNumValidFrames] = (I4)peSize; // Set flag indicating PE file in memory has the on disk layout - if (!pPEFile->IsDynamic()) + if (!pPEAssembly->IsDynamic()) { // This flag is only available for non-dynamic assemblies. U1 *pIsFileLayout = (U1 *)((BOOLARRAYREF)pStackFrameHelper->rgiIsFileLayout)->GetDirectPointerToNonObjectElements(); - pIsFileLayout[iNumValidFrames] = (U1) pPEFile->GetLoaded()->IsFlat(); + pIsFileLayout[iNumValidFrames] = (U1) pPEAssembly->GetLoadedLayout()->IsFlat(); } // If there is a in memory symbol stream @@ -750,7 +750,7 @@ FCIMPL4(void, DebugStackTrace::GetStackFramesInternal, else { // Set the pdb path (assembly file name) - SString assemblyPath = pPEFile->GetIdentityPath(); + SString assemblyPath = pPEAssembly->GetIdentityPath(); if (!assemblyPath.IsEmpty()) { OBJECTREF obj = (OBJECTREF)StringObject::NewString(assemblyPath); diff --git a/src/coreclr/vm/domainfile.cpp b/src/coreclr/vm/domainfile.cpp index 70f03913f1879..ca9ea6565d3f7 100644 --- a/src/coreclr/vm/domainfile.cpp +++ b/src/coreclr/vm/domainfile.cpp @@ -30,10 +30,9 @@ #endif // FEATURE_PERFMAP #ifndef DACCESS_COMPILE -DomainFile::DomainFile(AppDomain *pDomain, PEFile *pFile) +DomainFile::DomainFile(AppDomain *pDomain, PEAssembly *pPEAssembly) : m_pDomain(pDomain), - m_pFile(pFile), - m_pOriginalFile(NULL), + m_pPEAssembly(pPEAssembly), m_pModule(NULL), m_level(FILE_LOAD_CREATE), m_pError(NULL), @@ -54,7 +53,7 @@ DomainFile::DomainFile(AppDomain *pDomain, PEFile *pFile) CONTRACTL_END; m_hExposedModuleObject = NULL; - pFile->AddRef(); + pPEAssembly->AddRef(); } DomainFile::~DomainFile() @@ -68,9 +67,7 @@ DomainFile::~DomainFile() } CONTRACTL_END; - m_pFile->Release(); - if(m_pOriginalFile) - m_pOriginalFile->Release(); + m_pPEAssembly->Release(); if (m_pDynamicMethodTable) m_pDynamicMethodTable->Destroy(); delete m_pError; @@ -282,10 +279,10 @@ CHECK DomainFile::CheckLoaded() // assemblies for bootstrapping purposes. This is because it has no // dependencies, security checks, and doesn't rely on loader notifications. - if (GetFile()->IsSystem()) + if (GetPEAssembly()->IsSystem()) CHECK_OK; - CHECK_MSG(GetFile()->CheckLoaded(), "PEFile has not been loaded"); + CHECK_MSG(GetPEAssembly()->IsLoaded(), "PEAssembly has not been loaded"); CHECK_OK; } @@ -310,10 +307,10 @@ CHECK DomainFile::CheckActivated() // assemblies for bootstrapping purposes. This is because it has no // dependencies, security checks, and doesn't rely on loader notifications. - if (GetFile()->IsSystem()) + if (GetPEAssembly()->IsSystem()) CHECK_OK; - CHECK_MSG(GetFile()->CheckLoaded(), "PEFile has not been loaded"); + CHECK_MSG(GetPEAssembly()->IsLoaded(), "PEAssembly has not been loaded"); CHECK_MSG(IsLoaded(), "DomainFile has not been fully loaded"); CHECK_MSG(m_bDisableActivationCheck || CheckLoadLevel(FILE_ACTIVE), "File has not had execution verified"); @@ -392,7 +389,7 @@ OBJECTREF DomainFile::GetExposedModuleObject() GCPROTECT_BEGIN(refClass); - if (GetFile()->IsDynamic()) + if (GetPEAssembly()->IsDynamic()) { refClass = (REFLECTMODULEBASEREF) AllocateObject(CoreLibBinder::GetClass(CLASS__MODULE_BUILDER)); } @@ -528,7 +525,7 @@ void DomainFile::LoadLibrary() } CONTRACTL_END; - GetFile()->LoadLibrary(); + GetPEAssembly()->EnsureLoaded(); } void DomainFile::PostLoadLibrary() @@ -536,8 +533,8 @@ void DomainFile::PostLoadLibrary() CONTRACTL { INSTANCE_CHECK; - // Note that GetFile()->LoadLibrary must be called before this OUTSIDE OF THE LOCKS - PRECONDITION(GetFile()->CheckLoaded()); + // Note that GetPEAssembly()->EnsureLoaded must be called before this OUTSIDE OF THE LOCKS + PRECONDITION(GetPEAssembly()->IsLoaded()); STANDARD_VM_CHECK; } CONTRACTL_END; @@ -597,8 +594,7 @@ void DomainFile::VtableFixups() { WRAPPER_NO_CONTRACT; - if (!GetCurrentModule()->IsResource()) - GetCurrentModule()->FixupVTables(); + GetCurrentModule()->FixupVTables(); } void DomainFile::FinishLoad() @@ -622,7 +618,7 @@ void DomainFile::FinishLoad() #ifdef FEATURE_PERFMAP // Notify the perfmap of the IL image load. - PerfMap::LogImageLoad(m_pFile); + PerfMap::LogImageLoad(m_pPEAssembly); #endif } @@ -682,8 +678,8 @@ void DomainFile::Activate() // DomainAssembly //-------------------------------------------------------------------------------- -DomainAssembly::DomainAssembly(AppDomain *pDomain, PEFile *pFile, LoaderAllocator *pLoaderAllocator) - : DomainFile(pDomain, pFile), +DomainAssembly::DomainAssembly(AppDomain *pDomain, PEAssembly *pPEAssembly, LoaderAllocator *pLoaderAllocator) + : DomainFile(pDomain, pPEAssembly), m_pAssembly(NULL), m_debuggerFlags(DACF_NONE), m_fDebuggerUnloadStarted(FALSE), @@ -700,7 +696,7 @@ DomainAssembly::DomainAssembly(AppDomain *pDomain, PEFile *pFile, LoaderAllocato } CONTRACTL_END; - pFile->ValidateForExecution(); + pPEAssembly->ValidateForExecution(); // !!! backout @@ -747,8 +743,9 @@ void DomainAssembly::SetAssembly(Assembly* pAssembly) { STANDARD_VM_CONTRACT; - UpdatePEFile(pAssembly->GetManifestFile()); - _ASSERTE(pAssembly->GetManifestModule()->GetFile()==m_pFile); + _ASSERTE(pAssembly->GetManifestModule()->GetPEAssembly()==m_pPEAssembly); + _ASSERTE(m_pAssembly == NULL); + m_pAssembly = pAssembly; m_pModule = pAssembly->GetManifestModule(); @@ -793,7 +790,7 @@ OBJECTREF DomainAssembly::GetExposedAssemblyObject() { ASSEMBLYREF assemblyObj = NULL; MethodTable * pMT; - if (GetFile()->IsDynamic()) + if (GetPEAssembly()->IsDynamic()) { // This is unnecessary because the managed InternalAssemblyBuilder object // should have already been created at the time of DefineDynamicAssembly @@ -879,18 +876,11 @@ void DomainAssembly::Allocate() { //! If you decide to remove "if" do not remove this brace: order is important here - in the case of an exception, //! the Assembly holder must destruct before the AllocMemTracker declared above. - - // We can now rely on the fact that our MDImport will not change so we can stop refcounting it. - GetFile()->MakeMDImportPersistent(); - NewHolder assemblyHolder(NULL); - assemblyHolder = pAssembly = Assembly::Create(m_pDomain, GetFile(), GetDebuggerInfoBits(), this->IsCollectible(), pamTracker, this->IsCollectible() ? this->GetLoaderAllocator() : NULL); + assemblyHolder = pAssembly = Assembly::Create(m_pDomain, GetPEAssembly(), GetDebuggerInfoBits(), this->IsCollectible(), pamTracker, this->IsCollectible() ? this->GetLoaderAllocator() : NULL); assemblyHolder->SetIsTenured(); - //@todo! This is too early to be calling SuppressRelease. The right place to call it is below after - // the CANNOTTHROWCOMPLUSEXCEPTION. Right now, we have to do this to unblock OOM injection testing quickly - // as doing the right thing is nontrivial. pamTracker->SuppressRelease(); assemblyHolder.SuppressRelease(); } @@ -973,7 +963,7 @@ BOOL DomainAssembly::GetResource(LPCSTR szName, DWORD *cbResource, } CONTRACTL_END; - return GetFile()->GetResource( szName, + return GetPEAssembly()->GetResource( szName, cbResource, pbInMemoryResource, pAssemblyRef, @@ -1048,7 +1038,7 @@ HRESULT DomainAssembly::GetDebuggingCustomAttributes(DWORD *pdwFlags) ULONG size; BYTE *blob; mdModule mdMod; - ReleaseHolder mdImport(GetFile()->GetMDImportWithRef()); + IMDInternalImport* mdImport = GetPEAssembly()->GetMDImport(); mdMod = mdImport->GetModuleFromScope(); mdAssembly asTK = TokenFromRid(mdtAssembly, 1); @@ -1202,9 +1192,9 @@ DomainFile::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) // so we don't need to duplicate effort; thus we do noting with m_pModule. // For MiniDumpNormal, we only want the file name. - if (m_pFile.IsValid()) + if (m_pPEAssembly.IsValid()) { - m_pFile->EnumMemoryRegions(flags); + m_pPEAssembly->EnumMemoryRegions(flags); } if (flags != CLRDATA_ENUM_MEM_MINI && flags != CLRDATA_ENUM_MEM_TRIAGE diff --git a/src/coreclr/vm/domainfile.h b/src/coreclr/vm/domainfile.h index 4396ad6c8d990..49a8344b21e84 100644 --- a/src/coreclr/vm/domainfile.h +++ b/src/coreclr/vm/domainfile.h @@ -87,23 +87,16 @@ class DomainFile return m_pDomain; } - PEFile *GetFile() + PEAssembly *GetPEAssembly() { LIMITED_METHOD_DAC_CONTRACT; - return m_pFile; + return PTR_PEAssembly(m_pPEAssembly); } - PEFile *GetOriginalFile() - { - LIMITED_METHOD_DAC_CONTRACT; - return m_pOriginalFile!= NULL ? m_pOriginalFile : m_pFile; - } - - IMDInternalImport *GetMDImport() { WRAPPER_NO_CONTRACT; - return m_pFile->GetPersistentMDImport(); + return m_pPEAssembly->GetMDImport(); } OBJECTREF GetExposedModuleObjectIfExists() @@ -120,20 +113,20 @@ class DomainFile BOOL IsSystem() { WRAPPER_NO_CONTRACT; - return GetFile()->IsSystem(); + return GetPEAssembly()->IsSystem(); } LPCUTF8 GetSimpleName() { WRAPPER_NO_CONTRACT; - return GetFile()->GetSimpleName(); + return GetPEAssembly()->GetSimpleName(); } #ifdef LOGGING LPCWSTR GetDebugName() { WRAPPER_NO_CONTRACT; - return GetFile()->GetDebugName(); + return GetPEAssembly()->GetDebugName(); } #endif @@ -252,8 +245,8 @@ class DomainFile // ------------------------------------------------------------ #ifndef DACCESS_COMPILE - BOOL Equals(DomainFile *pFile) { WRAPPER_NO_CONTRACT; return GetFile()->Equals(pFile->GetFile()); } - BOOL Equals(PEFile *pFile) { WRAPPER_NO_CONTRACT; return GetFile()->Equals(pFile); } + BOOL Equals(DomainFile *pFile) { WRAPPER_NO_CONTRACT; return GetPEAssembly()->Equals(pFile->GetPEAssembly()); } + BOOL Equals(PEAssembly *pPEAssembly) { WRAPPER_NO_CONTRACT; return GetPEAssembly()->Equals(pPEAssembly); } #endif // DACCESS_COMPILE Module* GetCurrentModule(); @@ -279,7 +272,7 @@ class DomainFile friend class Module; friend class FileLoadLock; - DomainFile(AppDomain *pDomain, PEFile *pFile); + DomainFile(AppDomain *pDomain, PEAssembly *pPEAssembly); BOOL DoIncrementalLoad(FileLoadLevel targetLevel); void ClearLoading() { LIMITED_METHOD_CONTRACT; m_loading = FALSE; } @@ -306,17 +299,13 @@ class DomainFile void SetProfilerNotified() { LIMITED_METHOD_CONTRACT; m_notifyflags|= PROFILER_NOTIFIED; } void SetDebuggerNotified() { LIMITED_METHOD_CONTRACT; m_notifyflags|=DEBUGGER_NOTIFIED; } void SetShouldNotifyDebugger() { LIMITED_METHOD_CONTRACT; m_notifyflags|=DEBUGGER_NEEDNOTIFICATION; } -#ifndef DACCESS_COMPILE - void UpdatePEFileWorker(PTR_PEFile pFile); -#endif // ------------------------------------------------------------ // Instance data // ------------------------------------------------------------ PTR_AppDomain m_pDomain; - PTR_PEFile m_pFile; - PTR_PEFile m_pOriginalFile; // keep file alive just in case someone is sitill using it. If this is not NULL then m_pFile contains reused file from the shared assembly + PTR_PEAssembly m_pPEAssembly; PTR_Module m_pModule; FileLoadLevel m_level; LOADERHANDLE m_hExposedModuleObject; @@ -425,12 +414,6 @@ class DomainAssembly : public DomainFile // Public API // ------------------------------------------------------------ - PEAssembly *GetFile() - { - LIMITED_METHOD_CONTRACT; - return PTR_PEAssembly(m_pFile); - } - LoaderAllocator *GetLoaderAllocator() { LIMITED_METHOD_CONTRACT; @@ -592,7 +575,7 @@ class DomainAssembly : public DomainFile public: ~DomainAssembly(); private: - DomainAssembly(AppDomain *pDomain, PEFile *pFile, LoaderAllocator *pLoaderAllocator); + DomainAssembly(AppDomain *pDomain, PEAssembly *pPEAssembly, LoaderAllocator *pLoaderAllocator); #endif // ------------------------------------------------------------ @@ -606,10 +589,6 @@ class DomainAssembly : public DomainFile void DeliverAsyncEvents(); #endif - void UpdatePEFile(PTR_PEFile pFile); - - BOOL IsInstrumented(); - public: ULONG HashIdentity(); diff --git a/src/coreclr/vm/domainfile.inl b/src/coreclr/vm/domainfile.inl index 91ed0ae4a1ff3..a87d9aaef1309 100644 --- a/src/coreclr/vm/domainfile.inl +++ b/src/coreclr/vm/domainfile.inl @@ -58,39 +58,10 @@ inline Assembly* DomainAssembly::GetAssembly() return m_pAssembly; } -#ifndef DACCESS_COMPILE -inline void DomainFile::UpdatePEFileWorker(PTR_PEFile pFile) -{ - LIMITED_METHOD_CONTRACT; - CONSISTENCY_CHECK(CheckPointer(pFile)); - if (pFile==m_pFile) - return; - _ASSERTE(m_pOriginalFile==NULL); - m_pOriginalFile=m_pFile; - pFile->AddRef(); - m_pFile=pFile; -} - -inline void DomainAssembly::UpdatePEFile(PTR_PEFile pFile) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_ANY; - CAN_TAKE_LOCK; - } - CONTRACTL_END; - - GetAppDomain()->UpdatePublishHostedAssembly(this, pFile); -} - -#endif // DACCESS_COMPILE - inline ULONG DomainAssembly::HashIdentity() { WRAPPER_NO_CONTRACT; - return GetFile()->HashIdentity(); + return GetPEAssembly()->HashIdentity(); } inline BOOL DomainAssembly::IsCollectible() diff --git a/src/coreclr/vm/dwbucketmanager.hpp b/src/coreclr/vm/dwbucketmanager.hpp index cf360ac7322a5..21267b8f36070 100644 --- a/src/coreclr/vm/dwbucketmanager.hpp +++ b/src/coreclr/vm/dwbucketmanager.hpp @@ -701,14 +701,14 @@ void BaseBucketParamsManager::GetModuleTimeStamp(__out_ecount(maxLength) WCHAR* { // We only store the IL timestamp in the native image for the // manifest module. We should consider fixing this for Orcas. - PTR_PEFile pFile = pModule->GetAssembly()->GetManifestModule()->GetFile(); + PTR_PEAssembly pFile = pModule->GetAssembly()->GetManifestModule()->GetPEAssembly(); // for dynamic modules use 0 as the time stamp ULONG ulTimeStamp = 0; if (!pFile->IsDynamic()) { - ulTimeStamp = pFile->GetILImageTimeDateStamp(); + ulTimeStamp = pFile->GetPEImageTimeDateStamp(); _ASSERTE(ulTimeStamp != 0); } @@ -957,13 +957,13 @@ bool BaseBucketParamsManager::GetFileVersionInfoForModule(Module* pModule, USHOR bool succeeded = false; - PEFile* pFile = pModule->GetFile(); - if (pFile) + PEAssembly* pPEAssembly = pModule->GetPEAssembly(); + if (pPEAssembly) { // if we failed to get the version info from the native image then fall back to the IL image. if (!succeeded) { - LPCWSTR modulePath = pFile->GetPath().GetUnicode(); + LPCWSTR modulePath = pPEAssembly->GetPath().GetUnicode(); if (modulePath != NULL && modulePath != SString::Empty() && SUCCEEDED(DwGetFileVersionInfo(modulePath, major, minor, build, revision))) { succeeded = true; diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index a93343b112a41..5abf6c7d87c9a 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -314,7 +314,6 @@ FCFuncStart(gCOMModuleFuncs) QCFuncElement("GetScopeName", COMModule::GetScopeName) FCFuncElement("GetTypes", COMModule::GetTypes) QCFuncElement("GetFullyQualifiedName", COMModule::GetFullyQualifiedName) - FCFuncElement("IsResource", COMModule::IsResource) FCFuncEnd() FCFuncStart(gCOMModuleBuilderFuncs) diff --git a/src/coreclr/vm/eedbginterfaceimpl.h b/src/coreclr/vm/eedbginterfaceimpl.h index d4d790c9e886f..72594c336794c 100644 --- a/src/coreclr/vm/eedbginterfaceimpl.h +++ b/src/coreclr/vm/eedbginterfaceimpl.h @@ -26,7 +26,7 @@ #include "debugdebugger.h" #include "eeconfig.h" -#include "pefile.h" +#include "peassembly.h" class EEDbgInterfaceImpl : public EEDebugInterface { diff --git a/src/coreclr/vm/encee.cpp b/src/coreclr/vm/encee.cpp index b11e2d8437068..3f745d299427c 100644 --- a/src/coreclr/vm/encee.cpp +++ b/src/coreclr/vm/encee.cpp @@ -35,8 +35,8 @@ static int g_BreakOnEnCResolveField = -1; // The constructor phase initializes just enough so that Destruct() can be safely called. // It cannot throw or fail. // -EditAndContinueModule::EditAndContinueModule(Assembly *pAssembly, mdToken moduleRef, PEFile *file) - : Module(pAssembly, moduleRef, file) +EditAndContinueModule::EditAndContinueModule(Assembly *pAssembly, mdToken moduleRef, PEAssembly *pPEAssembly) + : Module(pAssembly, moduleRef, pPEAssembly) { CONTRACTL { @@ -175,7 +175,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( { // ConvertMDInternalToReadWrite should only ever be called on EnC capable files. _ASSERTE(IsEditAndContinueCapable()); // this also checks that the file is EnC capable - GetFile()->ConvertMDInternalToReadWrite(); + GetPEAssembly()->ConvertMDInternalToReadWrite(); } EX_CATCH_HRESULT(hr); diff --git a/src/coreclr/vm/encee.h b/src/coreclr/vm/encee.h index 2c7a834f32803..bd20a4057651a 100644 --- a/src/coreclr/vm/encee.h +++ b/src/coreclr/vm/encee.h @@ -202,13 +202,13 @@ class EditAndContinueModule : public Module // Return the minimum permissable address for new IL to be stored at // This can't be less than the current load address because then we'd // have negative RVAs. - BYTE *GetEnCBase() { return (BYTE *) GetFile()->GetManagedFileContents(); } + BYTE *GetEnCBase() { return (BYTE *) GetPEAssembly()->GetManagedFileContents(); } #endif // DACCESS_COMPILE private: // Constructor is invoked only by Module::Create - friend Module *Module::Create(Assembly *pAssembly, mdToken moduleRef, PEFile *file, AllocMemTracker *pamTracker); - EditAndContinueModule(Assembly *pAssembly, mdToken moduleRef, PEFile *file); + friend Module *Module::Create(Assembly *pAssembly, mdToken moduleRef, PEAssembly *pPEAssembly, AllocMemTracker *pamTracker); + EditAndContinueModule(Assembly *pAssembly, mdToken moduleRef, PEAssembly *pPEAssembly); protected: #ifndef DACCESS_COMPILE diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index dd36960e257e5..c549018584d70 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -6135,13 +6135,13 @@ static void GetCodeViewInfo(Module * pModule, CV_INFO_PDB70 * pCvInfoIL, CV_INFO ZeroMemory(pCvInfoIL, sizeof(*pCvInfoIL)); ZeroMemory(pCvInfoNative, sizeof(*pCvInfoNative)); - PTR_PEFile pPEFile = pModule->GetFile(); - _ASSERTE(pPEFile != NULL); + PTR_PEAssembly pPEAssembly = pModule->GetPEAssembly(); + _ASSERTE(pPEAssembly != NULL); PTR_PEImageLayout pLayout = NULL; - if (pPEFile->HasOpenedILimage()) + if (pPEAssembly->HasPEImage()) { - pLayout = pPEFile->GetLoadedIL(); + pLayout = pPEAssembly->GetLoadedLayout(); } if (pLayout == NULL) @@ -6338,7 +6338,7 @@ VOID ETW::LoaderLog::SendModuleEvent(Module *pModule, DWORD dwEventOptions, BOOL if(!bIsDynamicAssembly) { - ModuleILPath = (PWCHAR)pModule->GetAssembly()->GetManifestFile()->GetILimage()->GetPath().GetUnicode(); + ModuleILPath = (PWCHAR)pModule->GetAssembly()->GetManifestFile()->GetPEImage()->GetPath().GetUnicode(); ModuleNativePath = (PWCHAR)pEmptyString; } diff --git a/src/coreclr/vm/exceptmacros.h b/src/coreclr/vm/exceptmacros.h index 1eba8ca9c47fc..70e1fe0871e0d 100644 --- a/src/coreclr/vm/exceptmacros.h +++ b/src/coreclr/vm/exceptmacros.h @@ -520,7 +520,7 @@ VOID ThrowBadFormatWorkerT(UINT resID, T * pImgObj DEBUGARG(__in_z const char *c // Worker macro for throwing BadImageFormat exceptions. // // resID: resource ID in mscorrc.rc. Message may not have substitutions. resID is permitted (but not encouraged) to be 0. -// imgObj: one of Module* or PEFile* or PEImage* (must support GetPathForErrorMessages method.) +// imgObj: one of Module* or PEAssembly* or PEImage* (must support GetPathForErrorMessages method.) // #define IfFailThrowBF(hresult, resID, imgObj) \ do \ diff --git a/src/coreclr/vm/inlinetracking.cpp b/src/coreclr/vm/inlinetracking.cpp index bfd420850c1bd..86d73ea0a7657 100644 --- a/src/coreclr/vm/inlinetracking.cpp +++ b/src/coreclr/vm/inlinetracking.cpp @@ -45,7 +45,7 @@ bool MethodInModule::operator <(const MethodInModule& other) const } else { - m_module->GetFile()->GetMVID(&thisGuid); + m_module->GetPEAssembly()->GetMVID(&thisGuid); } if (other.m_module == NULL) @@ -54,7 +54,7 @@ bool MethodInModule::operator <(const MethodInModule& other) const } else { - other.m_module->GetFile()->GetMVID(&otherGuid); + other.m_module->GetPEAssembly()->GetMVID(&otherGuid); } return memcmp(&thisGuid, &otherGuid, sizeof(GUID)) < 0; diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 71f197444c9b6..e897648797ba3 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -984,7 +984,7 @@ void CEEInfo::resolveToken(/* IN, OUT */ CORINFO_RESOLVED_TOKEN * pResolvedToken ThrowBadTokenException(pResolvedToken); { - DomainFile *pTargetModule = pModule->LoadModule(GetAppDomain(), metaTOK, FALSE /* loadResources */); + DomainFile *pTargetModule = pModule->LoadModule(GetAppDomain(), metaTOK); if (pTargetModule == NULL) COMPlusThrowHR(COR_E_BADIMAGEFORMAT); th = TypeHandle(pTargetModule->GetModule()->GetGlobalMethodTable()); @@ -7798,14 +7798,14 @@ void CEEInfo::reportInliningDecision (CORINFO_METHOD_HANDLE inlinerHnd, if (LoggingOn(LF_JIT, LL_INFO100000)) { SString currentMethodName; - currentMethodName.AppendUTF8(m_pMethodBeingCompiled->GetModule_NoLogging()->GetFile()->GetSimpleName()); + currentMethodName.AppendUTF8(m_pMethodBeingCompiled->GetModule_NoLogging()->GetPEAssembly()->GetSimpleName()); currentMethodName.Append(L'/'); TypeString::AppendMethodInternal(currentMethodName, m_pMethodBeingCompiled, TypeString::FormatBasic); SString inlineeMethodName; if (GetMethod(inlineeHnd)) { - inlineeMethodName.AppendUTF8(GetMethod(inlineeHnd)->GetModule_NoLogging()->GetFile()->GetSimpleName()); + inlineeMethodName.AppendUTF8(GetMethod(inlineeHnd)->GetModule_NoLogging()->GetPEAssembly()->GetSimpleName()); inlineeMethodName.Append(L'/'); TypeString::AppendMethodInternal(inlineeMethodName, GetMethod(inlineeHnd), TypeString::FormatBasic); } @@ -7817,7 +7817,7 @@ void CEEInfo::reportInliningDecision (CORINFO_METHOD_HANDLE inlinerHnd, SString inlinerMethodName; if (GetMethod(inlinerHnd)) { - inlinerMethodName.AppendUTF8(GetMethod(inlinerHnd)->GetModule_NoLogging()->GetFile()->GetSimpleName()); + inlinerMethodName.AppendUTF8(GetMethod(inlinerHnd)->GetModule_NoLogging()->GetPEAssembly()->GetSimpleName()); inlinerMethodName.Append(L'/'); TypeString::AppendMethodInternal(inlinerMethodName, GetMethod(inlinerHnd), TypeString::FormatBasic); } @@ -12818,7 +12818,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, LARGE_INTEGER methodJitTimeStop; QueryPerformanceCounter(&methodJitTimeStop); SString codeBase; - ftn->GetModule()->GetDomainFile()->GetFile()->GetCodeBaseOrName(codeBase); + ftn->GetModule()->GetDomainFile()->GetPEAssembly()->GetPathOrCodeBase(codeBase); codeBase.AppendPrintf(W(",0x%x,%d,%d\n"), //(const WCHAR *)codeBase, //module name ftn->GetMemberDef(), //method token diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index f30f3f83daecd..d92fba38536e5 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -481,9 +481,9 @@ LoaderAllocator * LoaderAllocator::GCLoaderAllocators_RemoveAssemblies(AppDomain if (!domainAssemblyToRemove->GetAssembly()->IsDynamic()) { - pAppDomain->RemoveFileFromCache(domainAssemblyToRemove->GetFile()); + pAppDomain->RemoveFileFromCache(domainAssemblyToRemove->GetPEAssembly()); AssemblySpec spec; - spec.InitializeSpec(domainAssemblyToRemove->GetFile()); + spec.InitializeSpec(domainAssemblyToRemove->GetPEAssembly()); VERIFY(pAppDomain->RemoveAssemblyFromCache(domainAssemblyToRemove)); } diff --git a/src/coreclr/vm/memberload.cpp b/src/coreclr/vm/memberload.cpp index ce53bf22589f8..78fdb518a1618 100644 --- a/src/coreclr/vm/memberload.cpp +++ b/src/coreclr/vm/memberload.cpp @@ -277,7 +277,7 @@ void MemberLoader::GetDescFromMemberRef(Module * pModule, { case mdtModuleRef: { - DomainFile *pTargetModule = pModule->LoadModule(GetAppDomain(), parent, FALSE /* loadResources */); + DomainFile *pTargetModule = pModule->LoadModule(GetAppDomain(), parent); if (pTargetModule == NULL) COMPlusThrowHR(COR_E_BADIMAGEFORMAT); typeHnd = TypeHandle(pTargetModule->GetModule()->GetGlobalMethodTable()); diff --git a/src/coreclr/vm/methoditer.cpp b/src/coreclr/vm/methoditer.cpp index 5bd7e81f5de2d..841b3214d2e2d 100644 --- a/src/coreclr/vm/methoditer.cpp +++ b/src/coreclr/vm/methoditer.cpp @@ -83,9 +83,6 @@ BOOL LoadedMethodDescIterator::Next( if (!m_moduleIterator.Next()) goto ADVANCE_ASSEMBLY; - if (GetCurrentModule()->IsResource()) - goto ADVANCE_MODULE; - if (m_mainMD->HasClassInstantiation()) { m_typeIterator.Reset(); diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index 8751224545933..90f451a1dfde1 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -4337,9 +4337,8 @@ VOID MethodTableBuilder::InitializeFieldDescs(FieldDesc *pFieldDescList, DWORD rva; IfFailThrow(pInternalImport->GetFieldRVA(pFD->GetMemberDef(), &rva)); - // Ensure that the IL image is loaded. Note that this assembly may - // have an ngen image, but this type may have failed to load during ngen. - GetModule()->GetFile()->LoadLibrary(FALSE); + // Ensure that the IL image is loaded. + GetModule()->GetPEAssembly()->EnsureLoaded(); DWORD fldSize; if (FieldDescElementType == ELEMENT_TYPE_VALUETYPE) @@ -11216,7 +11215,7 @@ BOOL MethodTableBuilder::NeedsAlignedBaseOffset() // Always use the ReadyToRun field layout algorithm if the source IL image was ReadyToRun, independent on // whether ReadyToRun is actually enabled for the module. It is required to allow mixing and matching // ReadyToRun images with and without input bubble enabled. - if (!GetModule()->GetFile()->IsReadyToRun()) + if (!GetModule()->GetPEAssembly()->IsReadyToRun()) { // Always use ReadyToRun field layout algorithm to produce ReadyToRun images return FALSE; diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index b94be184959d7..e66e6e39d8f49 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -255,25 +255,20 @@ bool ModuleVersion::GetModuleVersion(Module * pModule) // GetMVID can throw exception EX_TRY { - PEFile * pFile = pModule->GetFile(); + PEAssembly * pAsm = pModule->GetPEAssembly(); - if (pFile != NULL) + if (pAsm != NULL) { - PEAssembly * pAsm = pFile->GetAssembly(); + // CorAssemblyFlags, only 16-bit used + versionFlags = pAsm->GetFlags(); - if (pAsm != NULL) - { - // CorAssemblyFlags, only 16-bit used - versionFlags = pAsm->GetFlags(); - - _ASSERTE((versionFlags & 0x80000000) == 0); + _ASSERTE((versionFlags & 0x80000000) == 0); - pAsm->GetVersion(& major, & minor, & build, & revision); + pAsm->GetVersion(&major, &minor, &build, &revision); - pAsm->GetMVID(& mvid); + pAsm->GetMVID(&mvid); - hr = S_OK; - } + hr = S_OK; } // If the load context is LOADFROM, store it in the flags. diff --git a/src/coreclr/vm/multicorejitplayer.cpp b/src/coreclr/vm/multicorejitplayer.cpp index d84ed388c9c44..7aae1dadaf873 100644 --- a/src/coreclr/vm/multicorejitplayer.cpp +++ b/src/coreclr/vm/multicorejitplayer.cpp @@ -396,11 +396,6 @@ bool MulticoreJitManager::ModuleHasNoCode(Module * pModule) { LIMITED_METHOD_CONTRACT; - if (pModule->IsResource()) - { - return true; - } - IMDInternalImport * pImport = pModule->GetMDImport(); if (pImport != NULL) @@ -434,15 +429,15 @@ bool MulticoreJitManager::IsSupportedModule(Module * pModule, bool fMethodJit) return false; } - PEFile * pFile = pModule->GetFile(); + PEAssembly * pPEAssembly = pModule->GetPEAssembly(); // dynamic module. - if (pFile->IsDynamic()) // Ignore dynamic modules + if (pPEAssembly->IsDynamic()) // Ignore dynamic modules { return false; } - if (pFile->GetPath().IsEmpty()) // Ignore in-memory modules + if (pPEAssembly->GetPath().IsEmpty()) // Ignore in-memory modules { return false; } diff --git a/src/coreclr/vm/nativeimage.cpp b/src/coreclr/vm/nativeimage.cpp index 13a39a2d4666e..b081091f1b94e 100644 --- a/src/coreclr/vm/nativeimage.cpp +++ b/src/coreclr/vm/nativeimage.cpp @@ -146,8 +146,9 @@ NativeImage *NativeImage::Open( BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(fullPath, /*pathIsBundleRelative */ true); if (bundleFileLocation.IsValid()) { - PEImageHolder pImage = PEImage::OpenImage(fullPath, MDInternalImport_NoCache, bundleFileLocation); - peLoadedImage = pImage->GetLayout(PEImageLayout::LAYOUT_MAPPED, PEImage::LAYOUT_CREATEIFNEEDED); + PEImageHolder pImage = PEImage::OpenImage(fullPath, MDInternalImport_Default, bundleFileLocation); + peLoadedImage = pImage->GetOrCreateLayout(PEImageLayout::LAYOUT_MAPPED); + peLoadedImage.SuppressRelease(); } if (peLoadedImage.IsNull()) diff --git a/src/coreclr/vm/nativeimage.h b/src/coreclr/vm/nativeimage.h index bf3f7b6272edf..4774365197f2b 100644 --- a/src/coreclr/vm/nativeimage.h +++ b/src/coreclr/vm/nativeimage.h @@ -57,7 +57,7 @@ class NativeImageIndexTraits : public NoRemoveSHashTraitsGetManifestFile(); + PEAssembly *pManifestFile = pAssembly->GetManifestFile(); PTR_AssemblyBinder pBinder = pManifestFile->GetAssemblyBinder(); //Step 0: Check if the assembly was bound using TPA. diff --git a/src/coreclr/vm/pefile.cpp b/src/coreclr/vm/peassembly.cpp similarity index 67% rename from src/coreclr/vm/pefile.cpp rename to src/coreclr/vm/peassembly.cpp index 8e7d70732a27f..956512a3dbe06 100644 --- a/src/coreclr/vm/pefile.cpp +++ b/src/coreclr/vm/peassembly.cpp @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // -------------------------------------------------------------------------------- -// PEFile.cpp +// PEAssembly.cpp // // -------------------------------------------------------------------------------- #include "common.h" -#include "pefile.h" +#include "peassembly.h" #include "eecontract.h" #include "eeconfig.h" #include "eventtrace.h" @@ -28,127 +28,19 @@ #ifndef DACCESS_COMPILE -// ================================================================================ -// PEFile class - this is an abstract base class for PEAssembly -// ================================================================================ - -PEFile::PEFile(PEImage *identity) : -#if _DEBUG - m_pDebugName(NULL), -#endif - m_identity(NULL), - m_openedILimage(NULL), - m_MDImportIsRW_Debugger_Use_Only(FALSE), - m_bHasPersistentMDImport(FALSE), - m_pMDImport(NULL), - m_pImporter(NULL), - m_pEmitter(NULL), - m_pMetadataLock(::new SimpleRWLock(PREEMPTIVE, LOCK_TYPE_DEFAULT)), - m_refCount(1), - m_flags(0), - m_pHostAssembly(nullptr), - m_pFallbackBinder(nullptr) -{ - CONTRACTL - { - CONSTRUCTOR_CHECK; - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - if (identity) - { - identity->AddRef(); - m_identity = identity; - - if(identity->IsOpened()) - { - //already opened, prepopulate - identity->AddRef(); - m_openedILimage = identity; - } - } - - -} - - - -PEFile::~PEFile() -{ - CONTRACTL - { - DESTRUCTOR_CHECK; - NOTHROW; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - ReleaseMetadataInterfaces(TRUE); - - - if (m_openedILimage != NULL) - m_openedILimage->Release(); - if (m_identity != NULL) - m_identity->Release(); - if (m_pMetadataLock) - delete m_pMetadataLock; - - if (m_pHostAssembly != NULL) - { - m_pHostAssembly->Release(); - } -} - -/* static */ -PEFile *PEFile::Open(PEImage *image) -{ - CONTRACT(PEFile *) - { - PRECONDITION(image != NULL); - PRECONDITION(image->CheckFormat()); - POSTCONDITION(RETVAL != NULL); - POSTCONDITION(!RETVAL->IsAssembly()); - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACT_END; - - PEFile *pFile = new PEFile(image); - - if (image->HasNTHeaders() && image->HasCorHeader()) - pFile->OpenMDImport_Unsafe(); //no one else can see the object yet - -#if _DEBUG - pFile->m_debugName = image->GetPath(); - pFile->m_debugName.Normalize(); - pFile->m_pDebugName = pFile->m_debugName; -#endif - - RETURN pFile; -} - //----------------------------------------------------------------------------------------------------- // Catch attempts to load x64 assemblies on x86, etc. //----------------------------------------------------------------------------------------------------- -static void ValidatePEFileMachineType(PEFile *peFile) +static void ValidatePEFileMachineType(PEAssembly *pPEAssembly) { STANDARD_VM_CONTRACT; - if (peFile->IsDynamic()) + if (pPEAssembly->IsDynamic()) return; // PEFiles for ReflectionEmit assemblies don't cache the machine type. - if (peFile->IsResource()) - return; // PEFiles for resource assemblies don't cache the machine type. - DWORD peKind; DWORD actualMachineType; - peFile->GetPEKindAndMachine(&peKind, &actualMachineType); + pPEAssembly->GetPEKindAndMachine(&peKind, &actualMachineType); if (actualMachineType == IMAGE_FILE_MACHINE_I386 && ((peKind & (peILonly | pe32BitRequired)) == peILonly)) return; // Image is marked CPU-agnostic. @@ -167,10 +59,7 @@ static void ValidatePEFileMachineType(PEFile *peFile) // Image has required machine that doesn't match the CLR. StackSString name; - if (peFile->IsAssembly()) - ((PEAssembly*)peFile)->GetDisplayName(name); - else - name = StackSString(SString::Utf8, peFile->GetSimpleName()); + pPEAssembly->GetDisplayName(name); COMPlusThrow(kBadImageFormatException, IDS_CLASSLOAD_WRONGCPU, name.GetUnicode()); } @@ -178,12 +67,12 @@ static void ValidatePEFileMachineType(PEFile *peFile) return; // If we got here, all is good. } -void PEFile::LoadLibrary(BOOL allowNativeSkip/*=TRUE*/) // if allowNativeSkip==FALSE force IL image load +void PEAssembly::EnsureLoaded() { CONTRACT_VOID { INSTANCE_CHECK; - POSTCONDITION(CheckLoaded()); + POSTCONDITION(IsLoaded()); STANDARD_VM_CHECK; } CONTRACT_END; @@ -191,142 +80,64 @@ void PEFile::LoadLibrary(BOOL allowNativeSkip/*=TRUE*/) // if allowNativeSkip==F // Catch attempts to load x64 assemblies on x86, etc. ValidatePEFileMachineType(this); - // See if we've already loaded it. - if (CheckLoaded(allowNativeSkip)) + // See if we do not have anything to load or have already loaded it. + if (IsLoaded()) { RETURN; } // Note that we may be racing other threads here, in the case of domain neutral files - // Resource images are always flat. - if (IsResource()) - { - GetILimage()->LoadNoMetaData(); - RETURN; - } - #if !defined(TARGET_64BIT) - if (!GetILimage()->Has32BitNTHeaders()) + if (!GetPEImage()->Has32BitNTHeaders()) { // Tried to load 64-bit assembly on 32-bit platform. EEFileLoadException::Throw(this, COR_E_BADIMAGEFORMAT, NULL); } #endif - // We need contents now - EnsureImageOpened(); - // Since we couldn't call LoadLibrary, we must be an IL only image // or the image may still contain unfixed up stuff - if (!GetILimage()->IsILOnly()) + if (!GetPEImage()->IsILOnly()) { - if (!GetILimage()->HasV1Metadata()) + if (!GetPEImage()->HasV1Metadata()) ThrowHR(COR_E_FIXUPSINEXE); // @todo: better error } - if (GetILimage()->IsFile()) + if (GetPEImage()->IsFile()) { #ifdef TARGET_UNIX - bool loadILImage = GetILimage()->IsILOnly(); + bool loadILImage = GetPEImage()->IsILOnly(); #else // TARGET_UNIX - bool loadILImage = GetILimage()->IsILOnly() && GetILimage()->IsInBundle(); + bool loadILImage = GetPEImage()->IsILOnly() && GetPEImage()->IsInBundle(); #endif // TARGET_UNIX if (loadILImage) { - GetILimage()->Load(); + GetPEImage()->Load(); } else { - GetILimage()->LoadFromMapped(); + GetPEImage()->LoadFromMapped(); } } else { - GetILimage()->LoadNoFile(); - } - - RETURN; -} - -void PEFile::SetLoadedHMODULE(HMODULE hMod) -{ - CONTRACT_VOID - { - INSTANCE_CHECK; - PRECONDITION(CheckPointer(hMod)); - POSTCONDITION(CheckLoaded()); - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); + GetPEImage()->LoadNoFile(); } - CONTRACT_END; - - // See if the image is an internal PEImage. - GetILimage()->SetLoadedHMODULE(hMod); RETURN; } -/* static */ -void PEFile::DefineEmitScope( - GUID iid, - void **ppEmit) -{ - CONTRACT_VOID - { - PRECONDITION(CheckPointer(ppEmit)); - POSTCONDITION(CheckPointer(*ppEmit)); - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACT_END; - - SafeComHolder pDispenser; - - // Get the Dispenser interface. - MetaDataGetDispenser( - CLSID_CorMetaDataDispenser, - IID_IMetaDataDispenserEx, - (void **)&pDispenser); - if (pDispenser == NULL) - { - ThrowOutOfMemory(); - } - - // Set the option on the dispenser turn on duplicate check for TypeDef and moduleRef - VARIANT varOption; - V_VT(&varOption) = VT_UI4; - V_I4(&varOption) = MDDupDefault | MDDupTypeDef | MDDupModuleRef | MDDupExportedType | MDDupAssemblyRef | MDDupPermission | MDDupFile; - IfFailThrow(pDispenser->SetOption(MetaDataCheckDuplicatesFor, &varOption)); - - // Set minimal MetaData size - V_VT(&varOption) = VT_UI4; - V_I4(&varOption) = MDInitialSizeMinimal; - IfFailThrow(pDispenser->SetOption(MetaDataInitialSize, &varOption)); - - // turn on the thread safety! - V_I4(&varOption) = MDThreadSafetyOn; - IfFailThrow(pDispenser->SetOption(MetaDataThreadSafetyOptions, &varOption)); - - IfFailThrow(pDispenser->DefineScope(CLSID_CorMetaDataRuntime, 0, iid, (IUnknown **)ppEmit)); - - RETURN; -} // PEFile::DefineEmitScope - // ------------------------------------------------------------ // Identity // ------------------------------------------------------------ -BOOL PEFile::Equals(PEFile *pFile) +BOOL PEAssembly::Equals(PEAssembly *pPEAssembly) { CONTRACTL { INSTANCE_CHECK; - PRECONDITION(CheckPointer(pFile)); + PRECONDITION(CheckPointer(pPEAssembly)); GC_NOTRIGGER; NOTHROW; CANNOT_TAKE_LOCK; @@ -335,36 +146,31 @@ BOOL PEFile::Equals(PEFile *pFile) CONTRACTL_END; // Same object is equal - if (pFile == this) + if (pPEAssembly == this) return TRUE; // Different host assemblies cannot be equal unless they are associated with the same host binder // It's ok if only one has a host binder because multiple threads can race to load the same assembly // and that may cause temporary candidate PEAssembly objects that never get bound to a host assembly // because another thread beats it; the losing thread will pick up the PEAssembly in the cache. - if (pFile->HasHostAssembly() && this->HasHostAssembly()) + if (pPEAssembly->HasHostAssembly() && this->HasHostAssembly()) { - AssemblyBinder* fileBinder = pFile->GetHostAssembly()->GetBinder(); + AssemblyBinder* otherBinder = pPEAssembly->GetHostAssembly()->GetBinder(); AssemblyBinder* thisBinder = this->GetHostAssembly()->GetBinder(); - if (fileBinder != thisBinder || fileBinder == NULL) + if (otherBinder != thisBinder || otherBinder == NULL) return FALSE; } - // Same identity is equal - if (m_identity != NULL && pFile->m_identity != NULL - && m_identity->Equals(pFile->m_identity)) - return TRUE; - // Same image is equal - if (m_openedILimage != NULL && pFile->m_openedILimage != NULL - && m_openedILimage->Equals(pFile->m_openedILimage)) + if (m_PEImage != NULL && pPEAssembly->m_PEImage != NULL + && m_PEImage->Equals(pPEAssembly->m_PEImage)) return TRUE; return FALSE; } -BOOL PEFile::Equals(PEImage *pImage) +BOOL PEAssembly::Equals(PEImage *pImage) { CONTRACTL { @@ -376,21 +182,15 @@ BOOL PEFile::Equals(PEImage *pImage) } CONTRACTL_END; - // Same object is equal - if (pImage == m_identity || pImage == m_openedILimage) + // Same image ==> equal + if (pImage == m_PEImage) return TRUE; - // Same identity is equal - if (m_identity != NULL - && m_identity->Equals(pImage)) + // Equal image ==> equal + if (m_PEImage != NULL + && m_PEImage->Equals(pImage)) return TRUE; - // Same image is equal - if (m_openedILimage != NULL - && m_openedILimage->Equals(pImage)) - return TRUE; - - return FALSE; } @@ -398,7 +198,7 @@ BOOL PEFile::Equals(PEImage *pImage) // Descriptive strings // ------------------------------------------------------------ -void PEFile::GetCodeBaseOrName(SString &result) +void PEAssembly::GetPathOrCodeBase(SString &result) { CONTRACTL { @@ -410,47 +210,21 @@ void PEFile::GetCodeBaseOrName(SString &result) } CONTRACTL_END; - if (m_identity != NULL && !m_identity->GetPath().IsEmpty()) - { - result.Set(m_identity->GetPath()); - } - else if (IsAssembly()) + if (m_PEImage != NULL && !m_PEImage->GetPath().IsEmpty()) { - ((PEAssembly*)this)->GetCodeBase(result); + result.Set(m_PEImage->GetPath()); } else - result.SetUTF8(GetSimpleName()); -} - - -// ------------------------------------------------------------ -// Checks -// ------------------------------------------------------------ - - - -CHECK PEFile::CheckLoaded(BOOL bAllowNativeSkip/*=TRUE*/) -{ - CONTRACT_CHECK { - INSTANCE_CHECK; - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; + GetCodeBase(result); } - CONTRACT_CHECK_END; - - CHECK(IsLoaded(bAllowNativeSkip)); - - CHECK_OK; } - // ------------------------------------------------------------ // Metadata access // ------------------------------------------------------------ -PTR_CVOID PEFile::GetMetadata(COUNT_T *pSize) +PTR_CVOID PEAssembly::GetMetadata(COUNT_T *pSize) { CONTRACT(PTR_CVOID) { @@ -465,8 +239,8 @@ PTR_CVOID PEFile::GetMetadata(COUNT_T *pSize) CONTRACT_END; if (IsDynamic() - || !GetILimage()->HasNTHeaders() - || !GetILimage()->HasCorHeader()) + || !GetPEImage()->HasNTHeaders() + || !GetPEImage()->HasCorHeader()) { if (pSize != NULL) *pSize = 0; @@ -474,12 +248,12 @@ PTR_CVOID PEFile::GetMetadata(COUNT_T *pSize) } else { - RETURN GetILimage()->GetMetadata(pSize); + RETURN GetPEImage()->GetMetadata(pSize); } } #endif // #ifndef DACCESS_COMPILE -PTR_CVOID PEFile::GetLoadedMetadata(COUNT_T *pSize) +PTR_CVOID PEAssembly::GetLoadedMetadata(COUNT_T *pSize) { CONTRACT(PTR_CVOID) { @@ -493,9 +267,9 @@ PTR_CVOID PEFile::GetLoadedMetadata(COUNT_T *pSize) } CONTRACT_END; - if (!HasLoadedIL() - || !GetLoadedIL()->HasNTHeaders() - || !GetLoadedIL()->HasCorHeader()) + if (!HasLoadedPEImage() + || !GetLoadedLayout()->HasNTHeaders() + || !GetLoadedLayout()->HasCorHeader()) { if (pSize != NULL) *pSize = 0; @@ -503,20 +277,19 @@ PTR_CVOID PEFile::GetLoadedMetadata(COUNT_T *pSize) } else { - RETURN GetLoadedIL()->GetMetadata(pSize); + RETURN GetLoadedLayout()->GetMetadata(pSize); } } -TADDR PEFile::GetIL(RVA il) +TADDR PEAssembly::GetIL(RVA il) { CONTRACT(TADDR) { INSTANCE_CHECK; PRECONDITION(il != 0); PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); #ifndef DACCESS_COMPILE - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); #endif POSTCONDITION(RETVAL != NULL); THROWS; @@ -527,8 +300,7 @@ TADDR PEFile::GetIL(RVA il) CONTRACT_END; PEImageLayout *image = NULL; - - image = GetLoadedIL(); + image = GetLoadedLayout(); #ifndef DACCESS_COMPILE // Verify that the IL blob is valid before giving it out @@ -541,7 +313,7 @@ TADDR PEFile::GetIL(RVA il) #ifndef DACCESS_COMPILE -void PEFile::OpenImporter() +void PEAssembly::OpenImporter() { CONTRACTL { @@ -557,7 +329,7 @@ void PEFile::OpenImporter() ConvertMDInternalToReadWrite(); IMetaDataImport2 *pIMDImport = NULL; - IfFailThrow(GetMetaDataPublicInterfaceFromInternal((void*)GetPersistentMDImport(), + IfFailThrow(GetMetaDataPublicInterfaceFromInternal((void*)GetMDImport(), IID_IMetaDataImport2, (void **)&pIMDImport)); @@ -566,7 +338,7 @@ void PEFile::OpenImporter() pIMDImport->Release(); } -void PEFile::ConvertMDInternalToReadWrite() +void PEAssembly::ConvertMDInternalToReadWrite() { CONTRACTL { @@ -617,7 +389,6 @@ void PEFile::ConvertMDInternalToReadWrite() // Swap the pointers in a thread safe manner. If the contents of *ppImport // equals pOld then no other thread got here first, and the old contents are // replaced with pNew. The old contents are returned. - _ASSERTE(m_bHasPersistentMDImport); if (FastInterlockCompareExchangePointer(&m_pMDImport, pNew, pOld) == pOld) { //if the debugger queries, it will now see that we have RW metadata @@ -634,7 +405,7 @@ void PEFile::ConvertMDInternalToReadWrite() } } -void PEFile::OpenMDImport_Unsafe() +void PEAssembly::OpenMDImport() { CONTRACTL { @@ -649,23 +420,21 @@ void PEFile::OpenMDImport_Unsafe() if (m_pMDImport != NULL) return; if (!IsDynamic() - && GetILimage()->HasNTHeaders() - && GetILimage()->HasCorHeader()) + && GetPEImage()->HasNTHeaders() + && GetPEImage()->HasCorHeader()) { - m_pMDImport=GetILimage()->GetMDImport(); + m_pMDImport=GetPEImage()->GetMDImport(); } else { ThrowHR(COR_E_BADIMAGEFORMAT); } - m_bHasPersistentMDImport=TRUE; - _ASSERTE(m_pMDImport); m_pMDImport->AddRef(); } -void PEFile::OpenEmitter() +void PEAssembly::OpenEmitter() { CONTRACTL { @@ -681,7 +450,7 @@ void PEFile::OpenEmitter() ConvertMDInternalToReadWrite(); IMetaDataEmit *pIMDEmit = NULL; - IfFailThrow(GetMetaDataPublicInterfaceFromInternal((void*)GetPersistentMDImport(), + IfFailThrow(GetMetaDataPublicInterfaceFromInternal((void*)GetMDImport(), IID_IMetaDataEmit, (void **)&pIMDEmit)); @@ -690,39 +459,6 @@ void PEFile::OpenEmitter() pIMDEmit->Release(); } - -void PEFile::ReleaseMetadataInterfaces(BOOL bDestructor) -{ - CONTRACTL - { - INSTANCE_CHECK; - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - PRECONDITION(bDestructor||m_pMetadataLock->IsWriterLock()); - } - CONTRACTL_END; - _ASSERTE(bDestructor || !m_bHasPersistentMDImport); - - if (m_pImporter != NULL) - { - m_pImporter->Release(); - m_pImporter = NULL; - } - if (m_pEmitter != NULL) - { - m_pEmitter->Release(); - m_pEmitter = NULL; - } - - if (m_pMDImport != NULL) - { - m_pMDImport->Release(); - m_pMDImport=NULL; - } -} - - // ------------------------------------------------------------ // PE file access // ------------------------------------------------------------ @@ -740,7 +476,7 @@ void PEFile::ReleaseMetadataInterfaces(BOOL bDestructor) // Resource access // ------------------------------------------------------------ -void PEFile::GetEmbeddedResource(DWORD dwOffset, DWORD *cbResource, PBYTE *pbInMemoryResource) +void PEAssembly::GetEmbeddedResource(DWORD dwOffset, DWORD *cbResource, PBYTE *pbInMemoryResource) { CONTRACTL { @@ -756,10 +492,9 @@ void PEFile::GetEmbeddedResource(DWORD dwOffset, DWORD *cbResource, PBYTE *pbInM // m_loadedImage is probably preferable, but this may be called by security // before the image is loaded. - EnsureImageOpened(); - PEImage* image = GetILimage(); + PEImage* image = GetPEImage(); - PEImageLayoutHolder theImage(image->GetLayout(PEImageLayout::LAYOUT_ANY,PEImage::LAYOUT_CREATEIFNEEDED)); + PEImageLayout* theImage = image->GetOrCreateLayout(PEImageLayout::LAYOUT_ANY); if (!theImage->CheckResource(dwOffset)) ThrowHR(COR_E_BADIMAGEFORMAT); @@ -774,10 +509,7 @@ void PEFile::GetEmbeddedResource(DWORD dwOffset, DWORD *cbResource, PBYTE *pbInM // File loading // ------------------------------------------------------------ -PEAssembly * -PEFile::LoadAssembly( - mdAssemblyRef kAssemblyRef, - IMDInternalImport * pImport) +PEAssembly* PEAssembly::LoadAssembly(mdAssemblyRef kAssemblyRef) { CONTRACT(PEAssembly *) { @@ -790,9 +522,7 @@ PEFile::LoadAssembly( } CONTRACT_END; - if (pImport == NULL) - pImport = GetPersistentMDImport(); - + IMDInternalImport* pImport = GetMDImport(); if (((TypeFromToken(kAssemblyRef) != mdtAssembly) && (TypeFromToken(kAssemblyRef) != mdtAssemblyRef)) || (!pImport->IsValidToken(kAssemblyRef))) @@ -802,16 +532,16 @@ PEFile::LoadAssembly( AssemblySpec spec; - spec.InitializeSpec(kAssemblyRef, pImport, GetAppDomain()->FindAssembly(GetAssembly())); + spec.InitializeSpec(kAssemblyRef, pImport, GetAppDomain()->FindAssembly(this)); RETURN GetAppDomain()->BindAssemblySpec(&spec, TRUE); } -BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, - PBYTE *pbInMemoryResource, DomainAssembly** pAssemblyRef, - LPCSTR *szFileName, DWORD *dwLocation, - BOOL fSkipRaiseResolveEvent, DomainAssembly* pDomainAssembly, AppDomain* pAppDomain) +BOOL PEAssembly::GetResource(LPCSTR szName, DWORD *cbResource, + PBYTE *pbInMemoryResource, DomainAssembly** pAssemblyRef, + LPCSTR *szFileName, DWORD *dwLocation, + BOOL fSkipRaiseResolveEvent, DomainAssembly* pDomainAssembly, AppDomain* pAppDomain) { CONTRACTL { @@ -829,11 +559,11 @@ BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, DWORD dwOffset; mdManifestResource mdResource; Assembly* pAssembly = NULL; - PEFile* pPEFile = NULL; - ReleaseHolder pImport (GetMDImportWithRef()); + PEAssembly* pPEAssembly = NULL; + IMDInternalImport* pImport = GetMDImport(); if (SUCCEEDED(pImport->FindManifestResourceByName(szName, &mdResource))) { - pPEFile = this; + pPEAssembly = this; IfFailThrow(pImport->GetManifestResourceProps( mdResource, NULL, //&szName, @@ -846,13 +576,13 @@ BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, if (fSkipRaiseResolveEvent || pAppDomain == NULL) return FALSE; - DomainAssembly* pParentAssembly = GetAppDomain()->FindAssembly(GetAssembly()); + DomainAssembly* pParentAssembly = GetAppDomain()->FindAssembly(this); pAssembly = pAppDomain->RaiseResourceResolveEvent(pParentAssembly, szName); if (pAssembly == NULL) return FALSE; pDomainAssembly = pAssembly->GetDomainAssembly(); - pPEFile = pDomainAssembly->GetFile(); + pPEAssembly = pDomainAssembly->GetPEAssembly(); if (FAILED(pAssembly->GetManifestImport()->FindManifestResourceByName( szName, @@ -868,7 +598,7 @@ BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, *dwLocation = *dwLocation | 2; // ResourceLocation.containedInAnotherAssembly } - IfFailThrow(pPEFile->GetPersistentMDImport()->GetManifestResourceProps( + IfFailThrow(pPEAssembly->GetMDImport()->GetManifestResourceProps( mdResource, NULL, //&szName, &mdLinkRef, @@ -884,7 +614,7 @@ BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, return FALSE; AssemblySpec spec; - spec.InitializeSpec(mdLinkRef, GetPersistentMDImport(), pDomainAssembly); + spec.InitializeSpec(mdLinkRef, GetMDImport(), pDomainAssembly); pDomainAssembly = spec.LoadDomainAssembly(FILE_LOADED); if (dwLocation) { @@ -915,7 +645,7 @@ BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, return TRUE; } - pPEFile->GetEmbeddedResource(dwOffset, cbResource, pbInMemoryResource); + pPEAssembly->GetEmbeddedResource(dwOffset, cbResource, pbInMemoryResource); return TRUE; } @@ -926,24 +656,23 @@ BOOL PEFile::GetResource(LPCSTR szName, DWORD *cbResource, } } -void PEFile::GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine) +void PEAssembly::GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine) { WRAPPER_NO_CONTRACT; - if (IsResource() || IsDynamic()) + _ASSERTE(pdwKind != NULL && pdwMachine != NULL); + if (IsDynamic()) { - if (pdwKind) - *pdwKind = 0; - if (pdwMachine) - *pdwMachine = 0; + *pdwKind = 0; + *pdwMachine = 0; return; } - GetILimage()->GetPEKindAndMachine(pdwKind, pdwMachine); + GetPEImage()->GetPEKindAndMachine(pdwKind, pdwMachine); return; } -ULONG PEFile::GetILImageTimeDateStamp() +ULONG PEAssembly::GetPEImageTimeDateStamp() { CONTRACTL { @@ -953,62 +682,63 @@ ULONG PEFile::GetILImageTimeDateStamp() } CONTRACTL_END; - return GetLoadedIL()->GetTimeDateStamp(); -} - - -// ================================================================================ -// PEAssembly class - a PEFile which represents an assembly -// ================================================================================ - -// Statics initialization. -/* static */ -void PEAssembly::Attach() -{ - STANDARD_VM_CONTRACT; + return GetLoadedLayout()->GetTimeDateStamp(); } #ifndef DACCESS_COMPILE + PEAssembly::PEAssembly( BINDER_SPACE::Assembly* pBindResultInfo, IMetaDataEmit* pEmit, - PEFile *creator, - BOOL system, - PEImage * pPEImageIL /*= NULL*/, + PEAssembly *creator, + BOOL isSystem, + PEImage * pPEImage /*= NULL*/, BINDER_SPACE::Assembly * pHostAssembly /*= NULL*/) - - : PEFile(pBindResultInfo ? pBindResultInfo->GetPEImage() - : pPEImageIL), - m_creator(clr::SafeAddRef(creator)) { CONTRACTL { CONSTRUCTOR_CHECK; PRECONDITION(CheckPointer(pEmit, NULL_OK)); PRECONDITION(CheckPointer(creator, NULL_OK)); - PRECONDITION(pBindResultInfo == NULL || pPEImageIL == NULL); + PRECONDITION(pBindResultInfo == NULL || pPEImage == NULL); STANDARD_VM_CHECK; } CONTRACTL_END; - m_flags |= PEFILE_ASSEMBLY; - if (system) - m_flags |= PEFILE_SYSTEM; + m_creator = clr::SafeAddRef(creator); +#if _DEBUG + m_pDebugName = NULL; +#endif + m_PEImage = NULL; + m_MDImportIsRW_Debugger_Use_Only = FALSE; + m_pMDImport = NULL; + m_pImporter = NULL; + m_pEmitter = NULL; + m_refCount = 1; + m_isSystem = isSystem; + m_pHostAssembly = nullptr; + m_pFallbackBinder = nullptr; - // We require a mapping for the file. - EnsureImageOpened(); + pPEImage = pBindResultInfo ? pBindResultInfo->GetPEImage() : pPEImage; + if (pPEImage) + { + _ASSERTE(pPEImage->CheckUniqueInstance()); + pPEImage->AddRef(); + + // We require a mapping for the file. + pPEImage->GetOrCreateLayout(PEImageLayout::LAYOUT_ANY); + m_PEImage = pPEImage; + } // Open metadata eagerly to minimize failure windows if (pEmit == NULL) - OpenMDImport_Unsafe(); //constructor, cannot race with anything + OpenMDImport(); //constructor, cannot race with anything else { - _ASSERTE(!m_bHasPersistentMDImport); IfFailThrow(GetMetaDataInternalInterfaceFromPublic(pEmit, IID_IMDInternalImport, (void **)&m_pMDImport)); m_pEmitter = pEmit; pEmit->AddRef(); - m_bHasPersistentMDImport=TRUE; m_MDImportIsRW_Debugger_Use_Only = TRUE; } @@ -1040,7 +770,7 @@ PEAssembly::PEAssembly( } #if _DEBUG - GetCodeBaseOrName(m_debugName); + GetPathOrCodeBase(m_debugName); m_debugName.Normalize(); m_pDebugName = m_debugName; #endif @@ -1058,7 +788,7 @@ PEAssembly *PEAssembly::Open( PEAssembly * pPEAssembly = new PEAssembly( nullptr, // BindResult nullptr, // IMetaDataEmit - pParent, // PEFile creator + pParent, // PEAssembly creator FALSE, // isSystem pPEImageIL, pHostAssembly); @@ -1082,6 +812,29 @@ PEAssembly::~PEAssembly() if (m_creator != NULL) m_creator->Release(); + if (m_pImporter != NULL) + { + m_pImporter->Release(); + m_pImporter = NULL; + } + + if (m_pEmitter != NULL) + { + m_pEmitter->Release(); + m_pEmitter = NULL; + } + + if (m_pMDImport != NULL) + { + m_pMDImport->Release(); + m_pMDImport = NULL; + } + + if (m_PEImage != NULL) + m_PEImage->Release(); + + if (m_pHostAssembly != NULL) + m_pHostAssembly->Release(); } /* static */ @@ -1126,12 +879,9 @@ PEAssembly *PEAssembly::DoOpenSystem() RETURN new PEAssembly(pBoundAssembly, NULL, NULL, TRUE); } -PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBindResult, - BOOL isSystem) +PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBindResult) { - - return new PEAssembly(pBindResult,NULL,NULL,isSystem); - + return new PEAssembly(pBindResult,NULL,NULL, /*isSystem*/ false); }; /* static */ @@ -1151,15 +901,12 @@ PEAssembly *PEAssembly::Create(PEAssembly *pParentAssembly, // we have.) SafeComHolder pEmit; pAssemblyEmit->QueryInterface(IID_IMetaDataEmit, (void **)&pEmit); - PEAssemblyHolder pFile(new PEAssembly(NULL, pEmit, pParentAssembly, FALSE)); - RETURN pFile.Extract(); + RETURN new PEAssembly(NULL, pEmit, pParentAssembly, FALSE); } - #endif // #ifndef DACCESS_COMPILE - #ifndef DACCESS_COMPILE // ------------------------------------------------------------ @@ -1179,23 +926,23 @@ const SString &PEAssembly::GetEffectivePath() } CONTRACTL_END; - PEAssembly *pAssembly = this; + PEAssembly* pPEAssembly = this; - while (pAssembly->m_identity == NULL - || pAssembly->m_identity->GetPath().IsEmpty()) + while (pPEAssembly->m_PEImage == NULL + || pPEAssembly->m_PEImage->GetPath().IsEmpty()) { - if (pAssembly->m_creator) - pAssembly = pAssembly->m_creator->GetAssembly(); + if (pPEAssembly->m_creator) + pPEAssembly = pPEAssembly->m_creator; else // Unmanaged exe which loads byte[]/IStream assemblies return SString::Empty(); } - return pAssembly->m_identity->GetPath(); + return pPEAssembly->m_PEImage->GetPath(); } // Codebase is the fusion codebase or path for the assembly. It is in URL format. -// Note this may be obtained from the parent PEFile if we don't have a path or fusion +// Note this may be obtained from the parent PEAssembly if we don't have a path or fusion // assembly. // Returns false if the assembly was loaded from a bundle, true otherwise BOOL PEAssembly::GetCodeBase(SString &result) @@ -1210,13 +957,14 @@ BOOL PEAssembly::GetCodeBase(SString &result) } CONTRACTL_END; - auto ilImage = GetILimage(); - if (ilImage == nullptr || !ilImage->IsInBundle()) + PEImage* ilImage = GetPEImage(); + if (ilImage == NULL || !ilImage->IsInBundle()) { // All other cases use the file path. result.Set(GetEffectivePath()); if (!result.IsEmpty()) PathToUrl(result); + return TRUE; } else @@ -1322,7 +1070,7 @@ BOOL PEAssembly::FindLastPathSeparator(const SString &path, SString::Iterator &i // Metadata access // ------------------------------------------------------------ -HRESULT PEFile::GetVersion(USHORT *pMajor, USHORT *pMinor, USHORT *pBuild, USHORT *pRevision) +HRESULT PEAssembly::GetVersion(USHORT *pMajor, USHORT *pMinor, USHORT *pBuild, USHORT *pRevision) { CONTRACTL { @@ -1337,19 +1085,11 @@ HRESULT PEFile::GetVersion(USHORT *pMajor, USHORT *pMinor, USHORT *pBuild, USHOR } CONTRACTL_END; - AssemblyMetaDataInternal md; + _ASSERTE(GetMDImport()->IsValidToken(TokenFromRid(1, mdtAssembly))); + HRESULT hr = S_OK;; - if (m_bHasPersistentMDImport) - { - _ASSERTE(GetPersistentMDImport()->IsValidToken(TokenFromRid(1, mdtAssembly))); - IfFailRet(GetPersistentMDImport()->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, NULL, &md, NULL)); - } - else - { - ReleaseHolder pImport(GetMDImportWithRef()); - _ASSERTE(pImport->IsValidToken(TokenFromRid(1, mdtAssembly))); - IfFailRet(pImport->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, NULL, &md, NULL)); - } + AssemblyMetaDataInternal md; + IfFailRet(GetMDImport()->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, NULL, &md, NULL)); if (pMajor != NULL) *pMajor = md.usMajorVersion; @@ -1360,55 +1100,30 @@ HRESULT PEFile::GetVersion(USHORT *pMajor, USHORT *pMinor, USHORT *pBuild, USHOR if (pRevision != NULL) *pRevision = md.usRevisionNumber; - return hr; -} - - - -void PEFile::EnsureImageOpened() -{ - WRAPPER_NO_CONTRACT; - if (IsDynamic()) - return; - - GetILimage()->GetLayout(PEImageLayout::LAYOUT_ANY,PEImage::LAYOUT_CREATEIFNEEDED)->Release(); + return S_OK; } #endif // #ifndef DACCESS_COMPILE #ifdef DACCESS_COMPILE -void -PEFile::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) +void PEAssembly::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - // sizeof(PEFile) == 0xb8 DAC_ENUM_VTHIS(); - EMEM_OUT(("MEM: %p PEFile\n", dac_cast(this))); + EMEM_OUT(("MEM: %p PEAssembly\n", dac_cast(this))); #ifdef _DEBUG // Not a big deal if it's NULL or fails. m_debugName.EnumMemoryRegions(flags); #endif - if (m_identity.IsValid()) + if (m_PEImage.IsValid()) { - m_identity->EnumMemoryRegions(flags); + m_PEImage->EnumMemoryRegions(flags); } - if (GetILimage().IsValid()) - { - GetILimage()->EnumMemoryRegions(flags); - } -} - -void -PEAssembly::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) -{ - WRAPPER_NO_CONTRACT; - - PEFile::EnumMemoryRegions(flags); if (m_creator.IsValid()) { @@ -1426,7 +1141,7 @@ PEAssembly::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) // It can return an empty if the name isn't available or the object isn't initialized // enough to get a name, but it mustn't crash. //------------------------------------------------------------------------------- -LPCWSTR PEFile::GetPathForErrorMessages() +LPCWSTR PEAssembly::GetPathForErrorMessages() { CONTRACTL { @@ -1439,7 +1154,7 @@ LPCWSTR PEFile::GetPathForErrorMessages() if (!IsDynamic()) { - return m_identity->GetPathForErrorMessages(); + return m_PEImage->GetPathForErrorMessages(); } else { @@ -1449,7 +1164,7 @@ LPCWSTR PEFile::GetPathForErrorMessages() #ifdef DACCESS_COMPILE -TADDR PEFile::GetMDInternalRWAddress() +TADDR PEAssembly::GetMDInternalRWAddress() { if (!m_MDImportIsRW_Debugger_Use_Only) return 0; @@ -1467,13 +1182,13 @@ TADDR PEFile::GetMDInternalRWAddress() // 3) ASSUMPTION: We are assuming that no pointer adjustment is required to convert between // IMDInternalImport*, IMDInternalImportENC* and MDInternalRW*. Ideally I was hoping to do this with a // static_cast<> but the compiler complains that the ENC<->RW is an unrelated conversion. - return (TADDR) m_pMDImport_UseAccessor; + return (TADDR)m_pMDImport_UseAccessor; } } #endif -// Returns the AssemblyBinder* instance associated with the PEFile -PTR_AssemblyBinder PEFile::GetAssemblyBinder() +// Returns the AssemblyBinder* instance associated with the PEAssembly +PTR_AssemblyBinder PEAssembly::GetAssemblyBinder() { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/pefile.h b/src/coreclr/vm/peassembly.h similarity index 57% rename from src/coreclr/vm/pefile.h rename to src/coreclr/vm/peassembly.h index 317c9c544228f..adc19df11bc9b 100644 --- a/src/coreclr/vm/pefile.h +++ b/src/coreclr/vm/peassembly.h @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // -------------------------------------------------------------------------------- -// PEFile.h +// PEAssembly.h // // -------------------------------------------------------------------------------- -#ifndef PEFILE_H_ -#define PEFILE_H_ +#ifndef PEASSEMBLY_H_ +#define PEASSEMBLY_H_ // -------------------------------------------------------------------------------- // Required headers @@ -41,7 +41,6 @@ class Module; class EditAndContinueModule; -class PEFile; class PEAssembly; class SimpleRWLock; @@ -52,23 +51,25 @@ typedef VPTR(PEAssembly) PTR_PEAssembly; // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- -// A PEFile is an input to the CLR loader. It is produced as a result of +// A PEAssembly is an input to the CLR loader. It is produced as a result of // binding, usually through fusion (although there are a few less common methods to // obtain one which do not go through fusion, e.g. IJW loads) // -// Although a PEFile is usually a disk based PE file (hence the name), it is not +// Although a PEAssembly is usually a disk based PE file, it is not // always the case. Thus it is a conscious decision to not export access to the PE // file directly; rather the specific information required should be provided via // individual query API. // -// There are multiple "flavors" of PEFiles: +// There are multiple "flavors" of PEAssemblies: // // 1. HMODULE - these PE Files are loaded in response to "spontaneous" OS callbacks. // These should only occur for .exe main modules and IJW dlls loaded via LoadLibrary // or static imports in umnanaged code. +// These get their PEImage loaded directly in PEImage::LoadImage(HMODULE hMod) // -// 2. Fusion loads - these are the most common case. A path is obtained from fusion and -// the result is loaded via PEImage. +// 2. Assemblies loaded directly or indirectly by the managed code - these are the most +// common case. A path is obtained from assembly binding and the result is loaded +// via PEImage: // a. Display name loads - these are metadata-based binds // b. Path loads - these are loaded from an explicit path // @@ -78,19 +79,14 @@ typedef VPTR(PEAssembly) PTR_PEAssembly; // for reflection-based modules. // // See also file:..\inc\corhdr.h#ManagedHeader for more on the format of managed images. -// See code:Module for more on modules // -------------------------------------------------------------------------------- -typedef VPTR(class PEFile) PTR_PEFile; - -typedef ReleaseHolder IMDInternalImportHolder; - -class PEFile +class PEAssembly final { // ------------------------------------------------------------ // SOS support // ------------------------------------------------------------ - VPTR_BASE_CONCRETE_VTABLE_CLASS(PEFile) + VPTR_BASE_CONCRETE_VTABLE_CLASS(PEAssembly) public: @@ -109,54 +105,15 @@ class PEFile CHECK Invariant(); #endif -private: - // ------------------------------------------------------------ - // Loader access API - // ------------------------------------------------------------ - - friend class DomainFile; - -public: - void LoadLibrary(BOOL allowNativeSkip = TRUE); - - -private: - // For use inside LoadLibrary callback - void SetLoadedHMODULE(HMODULE hMod); - - // DO NOT USE !!! this is to be removed when we move to new fusion binding API - friend class DomainAssembly; - - // Helper for creating metadata for CreateDynamic - friend class Assembly; - friend class COMDynamicWrite; - friend class AssemblyNative; - static void DefineEmitScope( - GUID iid, - void **ppEmit); - -protected: - IMDInternalImportHolder GetMDImport(); - -public: - // ------------------------------------------------------------ - // Generic PEFile - can be used to access metadata - // ------------------------------------------------------------ - - static PEFile *Open(PEImage *image); - // ------------------------------------------------------------ // Identity // ------------------------------------------------------------ #ifndef DACCESS_COMPILE - BOOL Equals(PEFile *pFile); + BOOL Equals(PEAssembly *pPEAssembly); BOOL Equals(PEImage *pImage); #endif // DACCESS_COMPILE - - void GetMVID(GUID *pMvid); - // ------------------------------------------------------------ // Descriptive strings // ------------------------------------------------------------ @@ -170,8 +127,22 @@ class PEFile const SString &GetModuleFileNameHint(); #endif // DACCESS_COMPILE + LPCWSTR GetPathForErrorMessages(); + + // This returns a non-empty path representing the source of the assembly; it may + // be the parent assembly for dynamic or memory assemblies + const SString& GetEffectivePath(); + + // Codebase is the fusion codebase or path for the assembly. It is in URL format. + // Note this may be obtained from the parent PEAssembly if we don't have a path or fusion + // assembly. + BOOL GetCodeBase(SString& result); + // Full name is the most descriptive name available (path, codebase, or name as appropriate) - void GetCodeBaseOrName(SString &result); + void GetPathOrCodeBase(SString& result); + + // Display name is the fusion binding name for an assembly + void GetDisplayName(SString& result, DWORD flags = 0); #ifdef LOGGING // This is useful for log messages @@ -182,68 +153,49 @@ class PEFile // Checks // ------------------------------------------------------------ - CHECK CheckLoaded(BOOL allowNativeSkip = TRUE); void ValidateForExecution(); BOOL IsMarkedAsNoPlatform(); - // ------------------------------------------------------------ // Classification // ------------------------------------------------------------ - BOOL IsAssembly() const; - PTR_PEAssembly AsAssembly(); BOOL IsSystem() const; BOOL IsDynamic() const; - BOOL IsResource() const; - BOOL IsIStream() const; - // Returns self (if assembly) or containing assembly (if module) - PEAssembly *GetAssembly() const; // ------------------------------------------------------------ // Metadata access // ------------------------------------------------------------ - BOOL HasMetadata(); - - IMDInternalImport *GetPersistentMDImport(); - IMDInternalImport *GetMDImportWithRef(); - void MakeMDImportPersistent() {m_bHasPersistentMDImport=TRUE;}; + IMDInternalImport *GetMDImport(); #ifndef DACCESS_COMPILE IMetaDataEmit *GetEmitter(); - IMetaDataAssemblyEmit *GetAssemblyEmitter(); IMetaDataImport2 *GetRWImporter(); - IMetaDataAssemblyImport *GetAssemblyImporter(); #else TADDR GetMDInternalRWAddress(); #endif // DACCESS_COMPILE + void ConvertMDInternalToReadWrite(); + + void GetMVID(GUID* pMvid); + ULONG GetHashAlgId(); + HRESULT GetVersion(USHORT* pMajor, USHORT* pMinor, USHORT* pBuild, USHORT* pRevision); + BOOL IsStrongNamed(); LPCUTF8 GetSimpleName(); HRESULT GetScopeName(LPCUTF8 * pszName); - BOOL IsStrongNameVerified(); - BOOL IsStrongNamed(); const void *GetPublicKey(DWORD *pcbPK); - ULONG GetHashAlgId(); - HRESULT GetVersion(USHORT *pMajor, USHORT *pMinor, USHORT *pBuild, USHORT *pRevision); LPCSTR GetLocale(); DWORD GetFlags(); - HRESULT GetFlagsNoTrigger(DWORD * pdwFlags); + // ------------------------------------------------------------ // PE file access // ------------------------------------------------------------ - BOOL IsIbcOptimized(); BOOL IsReadyToRun(); - WORD GetSubsystem(); - mdToken GetEntryPointToken( -#ifdef _DEBUG - BOOL bAssumeLoaded = FALSE -#endif //_DEBUG - ); - BOOL IsILOnly(); - BOOL IsDll(); + mdToken GetEntryPointToken(); + BOOL IsILOnly(); TADDR GetIL(RVA il); PTR_VOID GetRvaField(RVA field); @@ -266,15 +218,14 @@ class PEFile LPCSTR *szFileName, DWORD *dwLocation, BOOL fSkipRaiseResolveEvent, DomainAssembly* pDomainAssembly, AppDomain* pAppDomain); + #ifndef DACCESS_COMPILE PTR_CVOID GetMetadata(COUNT_T *pSize); #endif - PTR_CVOID GetLoadedMetadata(COUNT_T *pSize); + PTR_CVOID GetLoadedMetadata(COUNT_T *pSize); void GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine); - - ULONG GetILImageTimeDateStamp(); - + ULONG GetPEImageTimeDateStamp(); // ------------------------------------------------------------ // Image memory access @@ -288,32 +239,54 @@ class PEFile // in the no-IL image case. // ------------------------------------------------------------ + BOOL HasPEImage() + { + LIMITED_METHOD_DAC_CONTRACT; + return m_PEImage != NULL; + } + + PEImage* GetPEImage() + { + LIMITED_METHOD_DAC_CONTRACT; + return m_PEImage; + } + + void EnsureLoaded(); + + BOOL HasLoadedPEImage() + { + LIMITED_METHOD_DAC_CONTRACT; + return HasPEImage() && GetPEImage()->HasLoadedLayout(); + } + + PTR_PEImageLayout GetLoadedLayout() + { + LIMITED_METHOD_CONTRACT; + SUPPORTS_DAC; + + _ASSERTE(HasPEImage()); + return GetPEImage()->GetLoadedLayout(); + }; + + BOOL IsLoaded() + { + return IsDynamic() || HasLoadedPEImage(); + } + + BOOL IsPtrInPEImage(PTR_CVOID data); + // For IJW purposes only - this asserts that we have an IJW image. HMODULE GetIJWBase(); // The debugger can tolerate a null value here for native only loading cases - PTR_VOID GetDebuggerContents(COUNT_T *pSize = NULL); + PTR_VOID GetDebuggerContents(COUNT_T* pSize = NULL); #ifndef DACCESS_COMPILE // Returns the IL image range; may force a LoadLibrary - const void *GetManagedFileContents(COUNT_T *pSize = NULL); + const void* GetManagedFileContents(COUNT_T* pSize = NULL); #endif // DACCESS_COMPILE - PTR_CVOID GetLoadedImageContents(COUNT_T *pSize = NULL); - - // ------------------------------------------------------------ - // Native image access - // ------------------------------------------------------------ - - // Does the loader support using a native image for this file? - // Some implementation restrictions prevent native images from being used - // in some cases. - PTR_PEImageLayout GetLoaded(); - PTR_PEImageLayout GetLoadedIL(); - IStream * GetPdbStream(); - void ClearPdbStream(); - BOOL IsLoaded(BOOL bAllowNativeSkip=TRUE) ; - BOOL IsPtrInILImage(PTR_CVOID data); + PTR_CVOID GetLoadedImageContents(COUNT_T* pSize = NULL); // ------------------------------------------------------------ // Resource access @@ -325,141 +298,18 @@ class PEFile // File loading // ------------------------------------------------------------ - PEAssembly * LoadAssembly( - mdAssemblyRef kAssemblyRef, - IMDInternalImport * pImport = NULL); - -protected: - // ------------------------------------------------------------ - // Internal constants - // ------------------------------------------------------------ - - enum - { - PEFILE_SYSTEM = 0x01, - PEFILE_ASSEMBLY = 0x02, - }; - - // ------------------------------------------------------------ - // Internal routines - // ------------------------------------------------------------ - -#ifndef DACCESS_COMPILE - PEFile(PEImage *image); - virtual ~PEFile(); -#else - virtual ~PEFile() {} -#endif - - void OpenMDImport(); - void OpenMDImport_Unsafe(); - void OpenImporter(); - void OpenEmitter(); - - void ReleaseMetadataInterfaces(BOOL bDestructor); - - - friend class Module; - -#ifndef DACCESS_COMPILE - void EnsureImageOpened(); -#endif // DACCESS_COMPILE - - friend class ClrDataAccess; + PEAssembly * LoadAssembly(mdAssemblyRef kAssemblyRef); // ------------------------------------------------------------ - // Instance fields + // Assembly Binder and host assembly (BINDER_SPACE::Assembly) // ------------------------------------------------------------ -#ifdef _DEBUG - LPCWSTR m_pDebugName; - SString m_debugName; -#endif - - // Identity image - PTR_PEImage m_identity; - // IL image, NULL if we didn't need to open the file - PTR_PEImage m_openedILimage; - // This flag is not updated atomically with m_pMDImport. Its fine for debugger usage - // but don't rely on it in the runtime. In runtime try QI'ing the m_pMDImport for - // IID_IMDInternalImportENC - BOOL m_MDImportIsRW_Debugger_Use_Only; - Volatile m_bHasPersistentMDImport; - -#ifndef DACCESS_COMPILE - IMDInternalImport *m_pMDImport; -#else - IMDInternalImport *m_pMDImport_UseAccessor; -#endif - IMetaDataImport2 *m_pImporter; - IMetaDataEmit *m_pEmitter; - SimpleRWLock *m_pMetadataLock; - Volatile m_refCount; - int m_flags; - -public: - - PTR_PEImage GetILimage() - { - CONTRACTL - { - THROWS; - MODE_ANY; - GC_TRIGGERS; - } - CONTRACTL_END; -#ifndef DACCESS_COMPILE - if (m_openedILimage == NULL && m_identity != NULL) - { - PEImage* pOpenedILimage; - m_identity->Clone(MDInternalImport_Default,&pOpenedILimage); - if (InterlockedCompareExchangeT(&m_openedILimage,pOpenedILimage,NULL) != NULL) - pOpenedILimage->Release(); - } -#endif - return m_openedILimage; - } - - PEImage *GetOpenedILimage() - { - LIMITED_METHOD_DAC_CONTRACT; - _ASSERTE(HasOpenedILimage()); - return m_openedILimage; - } - - - BOOL HasOpenedILimage() - { - LIMITED_METHOD_DAC_CONTRACT; - return m_openedILimage != NULL; - - } - - BOOL HasLoadedIL() + bool HasHostAssembly() { - LIMITED_METHOD_DAC_CONTRACT; - return HasOpenedILimage() && GetOpenedILimage()->HasLoadedLayout(); + STATIC_CONTRACT_WRAPPER; + return GetHostAssembly() != NULL; } - LPCWSTR GetPathForErrorMessages(); - - static PEFile* Dummy(); - - void ConvertMDInternalToReadWrite(); - -protected: - PTR_BINDER_SPACE_Assembly m_pHostAssembly; - - // For certain assemblies, we do not have m_pHostAssembly since they are not bound using an actual binder. - // An example is Ref-Emitted assemblies. Thus, when such assemblies trigger load of their dependencies, - // we need to ensure they are loaded in appropriate load context. - // - // To enable this, we maintain a concept of "FallbackBinder", which will be set to the Binder of the - // assembly that created the dynamic assembly. If the creator assembly is dynamic itself, then its fallback - // load context would be propagated to the assembly being dynamically generated. - PTR_AssemblyBinder m_pFallbackBinder; - -public: // Returns a non-AddRef'ed BINDER_SPACE::Assembly* PTR_BINDER_SPACE_Assembly GetHostAssembly() { @@ -467,8 +317,9 @@ class PEFile return m_pHostAssembly; } - // Returns the AssemblyBinder* instance associated with the PEFile - // which owns the context into which the current PEFile was loaded. + // Returns the AssemblyBinder* instance associated with the PEAssembly + // which owns the context into which the current PEAssembly was loaded. + // For Dynamic assemblies this is the fallback binder. PTR_AssemblyBinder GetAssemblyBinder(); #ifndef DACCESS_COMPILE @@ -480,8 +331,7 @@ class PEFile #endif //!DACCESS_COMPILE - bool HasHostAssembly() - { STATIC_CONTRACT_WRAPPER; return GetHostAssembly() != nullptr; } + ULONG HashIdentity(); PTR_AssemblyBinder GetFallbackBinder() { @@ -489,111 +339,122 @@ class PEFile return m_pFallbackBinder; } -}; // class PEFile - - -class PEAssembly : public PEFile -{ - VPTR_VTABLE_CLASS(PEAssembly, PEFile) - public: // ------------------------------------------------------------ - // Statics initialization. - // ------------------------------------------------------------ - static - void Attach(); - - // ------------------------------------------------------------ - // Public API + // Creation entry points // ------------------------------------------------------------ // CoreCLR's PrivBinder PEAssembly creation entrypoint - static PEAssembly * Open( - PEAssembly * pParent, - PEImage * pPEImageIL, - BINDER_SPACE::Assembly * pHostAssembly); + static PEAssembly* Open( + PEAssembly* pParent, + PEImage* pPEImageIL, + BINDER_SPACE::Assembly* pHostAssembly); // This opens the canonical System.Private.CoreLib.dll - static PEAssembly *OpenSystem(); -#ifdef DACCESS_COMPILE - virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags); -#endif + static PEAssembly* OpenSystem(); - static PEAssembly *Open( - BINDER_SPACE::Assembly* pBindResult, - BOOL isSystem); + static PEAssembly* Open(BINDER_SPACE::Assembly* pBindResult); - static PEAssembly *Create( - PEAssembly *pParentAssembly, - IMetaDataAssemblyEmit *pEmit); + static PEAssembly* Create( + PEAssembly* pParentAssembly, + IMetaDataAssemblyEmit* pEmit); - private: - // Private helpers for crufty exception handling reasons - static PEAssembly *DoOpenSystem(); + // ------------------------------------------------------------ + // Utility functions + // ------------------------------------------------------------ - public: + static void PathToUrl(SString& string); + static void UrlToPath(SString& string); + static BOOL FindLastPathSeparator(const SString& path, SString::Iterator& i); +private: // ------------------------------------------------------------ - // binding & source + // Loader access API // ------------------------------------------------------------ - ULONG HashIdentity(); + // Private helper for crufty exception handling reasons + static PEAssembly* DoOpenSystem(); // ------------------------------------------------------------ - // Descriptive strings + // Internal routines // ------------------------------------------------------------ - // This returns a non-empty path representing the source of the assembly; it may - // be the parent assembly for dynamic or memory assemblies - const SString &GetEffectivePath(); +#ifdef DACCESS_COMPILE + // just to make the DAC and GCC happy. + virtual ~PEAssembly() {}; + PEAssembly() = default; +#else + PEAssembly( + BINDER_SPACE::Assembly* pBindResultInfo, + IMetaDataEmit* pEmit, + PEAssembly* creator, + BOOL isSystem, + PEImage* pPEImageIL = NULL, + BINDER_SPACE::Assembly* pHostAssembly = NULL + ); - // Codebase is the fusion codebase or path for the assembly. It is in URL format. - // Note this may be obtained from the parent PEFile if we don't have a path or fusion - // assembly. - BOOL GetCodeBase(SString &result); + virtual ~PEAssembly(); +#endif - // Display name is the fusion binding name for an assembly - void GetDisplayName(SString &result, DWORD flags = 0); + void OpenMDImport(); + void OpenImporter(); + void OpenEmitter(); - // ------------------------------------------------------------ - // Metadata access - // ------------------------------------------------------------ +private: - LPCUTF8 GetSimpleName(); + // ------------------------------------------------------------ + // Instance fields + // ------------------------------------------------------------ - // ------------------------------------------------------------ - // Utility functions - // ------------------------------------------------------------ +#ifdef _DEBUG + LPCWSTR m_pDebugName; + SString m_debugName; +#endif - static void PathToUrl(SString &string); - static void UrlToPath(SString &string); - static BOOL FindLastPathSeparator(const SString &path, SString::Iterator &i); + // IL image, NULL if dynamic + PTR_PEImage m_PEImage; - protected: + PTR_PEAssembly m_creator; + // This flag is not updated atomically with m_pMDImport. Its fine for debugger usage + // but don't rely on it in the runtime. In runtime try QI'ing the m_pMDImport for + // IID_IMDInternalImportENC + BOOL m_MDImportIsRW_Debugger_Use_Only; + union + { #ifndef DACCESS_COMPILE - PEAssembly( - BINDER_SPACE::Assembly* pBindResultInfo, - IMetaDataEmit *pEmit, - PEFile *creator, - BOOL system, - PEImage * pPEImageIL = NULL, - BINDER_SPACE::Assembly * pHostAssembly = NULL - ); - virtual ~PEAssembly(); + IMDInternalImport* m_pMDImport; +#else + // NB: m_pMDImport_UseAccessor appears to be never assigned a value, but its purpose is just + // to be a placeholder that has the same type and offset as m_pMDImport. + // + // The field has a different name so it would be an error to use directly. + // Only GetMDInternalRWAddress is supposed to use it via (TADDR)m_pMDImport_UseAccessor, + // which at that point will match the m_pMDImport on the debuggee side. + // See more scary comments in GetMDInternalRWAddress. + IMDInternalImport* m_pMDImport_UseAccessor; #endif + }; - private: - // ------------------------------------------------------------ - // Instance fields - // ------------------------------------------------------------ + IMetaDataImport2* m_pImporter; + IMetaDataEmit* m_pEmitter; - PTR_PEFile m_creator; -}; + Volatile m_refCount; + bool m_isSystem; + PTR_BINDER_SPACE_Assembly m_pHostAssembly; + + // For certain assemblies, we do not have m_pHostAssembly since they are not bound using an actual binder. + // An example is Ref-Emitted assemblies. Thus, when such assemblies trigger load of their dependencies, + // we need to ensure they are loaded in appropriate load context. + // + // To enable this, we maintain a concept of "FallbackBinder", which will be set to the Binder of the + // assembly that created the dynamic assembly. If the creator assembly is dynamic itself, then its fallback + // load context would be propagated to the assembly being dynamically generated. + PTR_AssemblyBinder m_pFallbackBinder; -typedef ReleaseHolder PEFileHolder; +}; // class PEAssembly typedef ReleaseHolder PEAssemblyHolder; -#endif // PEFILE_H_ +#endif // PEASSEMBLY_H_ diff --git a/src/coreclr/vm/pefile.inl b/src/coreclr/vm/peassembly.inl similarity index 56% rename from src/coreclr/vm/pefile.inl rename to src/coreclr/vm/peassembly.inl index e00136064bc1e..42102f13a05da 100644 --- a/src/coreclr/vm/pefile.inl +++ b/src/coreclr/vm/peassembly.inl @@ -1,13 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // -------------------------------------------------------------------------------- -// PEFile.inl +// PEAssembly.inl // // -------------------------------------------------------------------------------- -#ifndef PEFILE_INL_ -#define PEFILE_INL_ +#ifndef PEASSEMBLY_INL_ +#define PEASSEMBLY_INL_ #include "check.h" #include "simplerwlock.hpp" @@ -15,7 +15,7 @@ #include "peimagelayout.inl" #if CHECK_INVARIANTS -inline CHECK PEFile::Invariant() +inline CHECK PEAssembly::Invariant() { CONTRACT_CHECK { @@ -29,14 +29,12 @@ inline CHECK PEFile::Invariant() if (IsDynamic()) { // dynamic module case - CHECK(m_openedILimage == NULL); + CHECK(m_PEImage == NULL); CHECK(CheckPointer(m_pEmitter)); } else { - // If m_image is null, then we should have a native image. However, this is not valid initially - // during construction. We should find a way to assert this. - CHECK(CheckPointer((PEImage*) m_openedILimage, NULL_OK)); + CHECK(CheckPointer((PEImage*)m_PEImage)); } CHECK_OK; } @@ -46,7 +44,7 @@ inline CHECK PEFile::Invariant() // AddRef/Release // ------------------------------------------------------------ -inline ULONG PEFile::AddRef() +inline ULONG PEAssembly::AddRef() { CONTRACTL { @@ -61,7 +59,7 @@ inline ULONG PEFile::AddRef() return FastInterlockIncrement(&m_refCount); } -inline ULONG PEFile::Release() +inline ULONG PEAssembly::Release() { CONTRACT(COUNT_T) { @@ -88,7 +86,7 @@ inline ULONG PEAssembly::HashIdentity() { CONTRACTL { - PRECONDITION(CheckPointer(m_identity)); + PRECONDITION(CheckPointer(m_PEImage)); MODE_ANY; THROWS; GC_TRIGGERS; @@ -97,7 +95,7 @@ inline ULONG PEAssembly::HashIdentity() return m_pHostAssembly->GetAssemblyName()->Hash(BINDER_SPACE::AssemblyName::INCLUDE_VERSION); } -inline void PEFile::ValidateForExecution() +inline void PEAssembly::ValidateForExecution() { CONTRACTL { @@ -110,7 +108,7 @@ inline void PEFile::ValidateForExecution() // // Ensure reference assemblies are not loaded for execution // - ReleaseHolder mdImport(this->GetMDImportWithRef()); + IMDInternalImport* mdImport = GetMDImport(); if (mdImport->GetCustomAttributeByName(TokenFromRid(1, mdtAssembly), g_ReferenceAssemblyAttribute, NULL, @@ -121,7 +119,7 @@ inline void PEFile::ValidateForExecution() // // Ensure platform is valid for execution // - if (!IsDynamic() && !IsResource()) + if (!IsDynamic()) { if (IsMarkedAsNoPlatform()) { @@ -131,14 +129,14 @@ inline void PEFile::ValidateForExecution() } -inline BOOL PEFile::IsMarkedAsNoPlatform() +inline BOOL PEAssembly::IsMarkedAsNoPlatform() { WRAPPER_NO_CONTRACT; return (IsAfPA_NoPlatform(GetFlags())); } -inline void PEFile::GetMVID(GUID *pMvid) +inline void PEAssembly::GetMVID(GUID *pMvid) { CONTRACTL { @@ -149,14 +147,14 @@ inline void PEFile::GetMVID(GUID *pMvid) } CONTRACTL_END; - IfFailThrow(GetPersistentMDImport()->GetScopeProps(NULL, pMvid)); + IfFailThrow(GetMDImport()->GetScopeProps(NULL, pMvid)); } // ------------------------------------------------------------ // Descriptive strings // ------------------------------------------------------------ -inline const SString& PEFile::GetPath() +inline const SString& PEAssembly::GetPath() { CONTRACTL { @@ -169,17 +167,18 @@ inline const SString& PEFile::GetPath() } CONTRACTL_END; - if (IsDynamic() || m_identity->IsInBundle ()) + if (IsDynamic() || m_PEImage->IsInBundle ()) { return SString::Empty(); } - return m_identity->GetPath(); + + return m_PEImage->GetPath(); } // // Returns the identity path even for single-file/bundled apps. // -inline const SString& PEFile::GetIdentityPath() +inline const SString& PEAssembly::GetIdentityPath() { CONTRACTL { @@ -192,15 +191,16 @@ inline const SString& PEFile::GetIdentityPath() } CONTRACTL_END; - if (m_identity == nullptr) + if (m_PEImage == nullptr) { return SString::Empty(); } - return m_identity->GetPath(); + + return m_PEImage->GetPath(); } #ifdef DACCESS_COMPILE -inline const SString &PEFile::GetModuleFileNameHint() +inline const SString &PEAssembly::GetModuleFileNameHint() { CONTRACTL { @@ -216,12 +216,12 @@ inline const SString &PEFile::GetModuleFileNameHint() return SString::Empty(); } else - return m_identity->GetModuleFileNameHintForDAC(); + return m_PEImage->GetModuleFileNameHintForDAC(); } #endif // DACCESS_COMPILE #ifdef LOGGING -inline LPCWSTR PEFile::GetDebugName() +inline LPCWSTR PEAssembly::GetDebugName() { CONTRACTL { @@ -245,108 +245,29 @@ inline LPCWSTR PEFile::GetDebugName() // Classification // ------------------------------------------------------------ -inline BOOL PEFile::IsAssembly() const -{ - LIMITED_METHOD_DAC_CONTRACT; - - return (m_flags & PEFILE_ASSEMBLY) != 0; -} - -inline PTR_PEAssembly PEFile::AsAssembly() -{ - LIMITED_METHOD_DAC_CONTRACT; - - if (IsAssembly()) - return dac_cast(this); - else - return dac_cast(nullptr); -} - -inline BOOL PEFile::IsSystem() const +inline BOOL PEAssembly::IsSystem() const { LIMITED_METHOD_CONTRACT; SUPPORTS_DAC; - return (m_flags & PEFILE_SYSTEM) != 0; + return m_isSystem; } -inline BOOL PEFile::IsDynamic() const +inline BOOL PEAssembly::IsDynamic() const { LIMITED_METHOD_CONTRACT; SUPPORTS_DAC; - return m_identity == NULL; -} - -inline BOOL PEFile::IsResource() const -{ - WRAPPER_NO_CONTRACT; - SUPPORTS_DAC; - - return FALSE; -} - -inline BOOL PEFile::IsIStream() const -{ - LIMITED_METHOD_CONTRACT; - - return FALSE; -} - -inline PEAssembly *PEFile::GetAssembly() const -{ - WRAPPER_NO_CONTRACT; - _ASSERTE(IsAssembly()); - return dac_cast(this); + return m_PEImage == NULL; } // ------------------------------------------------------------ // Metadata access // ------------------------------------------------------------ - -inline BOOL PEFile::HasMetadata() -{ - CONTRACTL - { - INSTANCE_CHECK; - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - SUPPORTS_DAC; - } - CONTRACTL_END; - - return !IsResource(); -} - -inline IMDInternalImportHolder PEFile::GetMDImport() +inline IMDInternalImport* PEAssembly::GetMDImport() { WRAPPER_NO_CONTRACT; - if (m_bHasPersistentMDImport) - return IMDInternalImportHolder(GetPersistentMDImport(),FALSE); - else - return IMDInternalImportHolder(GetMDImportWithRef(),TRUE); -}; -inline IMDInternalImport* PEFile::GetPersistentMDImport() -{ -/* - CONTRACT(IMDInternalImport *) - { - INSTANCE_CHECK; - PRECONDITION(!IsResource()); - POSTCONDITION(CheckPointer(RETVAL)); - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACT_END; -*/ - SUPPORTS_DAC; -#if !defined(__GNUC__) - - _ASSERTE(!IsResource()); -#endif #ifdef DACCESS_COMPILE WRAPPER_NO_CONTRACT; return DacGetMDImport(this, true); @@ -355,56 +276,16 @@ inline IMDInternalImport* PEFile::GetPersistentMDImport() return m_pMDImport; #endif -} - -inline IMDInternalImport *PEFile::GetMDImportWithRef() -{ -/* - CONTRACT(IMDInternalImport *) - { - INSTANCE_CHECK; - PRECONDITION(!IsResource()); - POSTCONDITION(CheckPointer(RETVAL)); - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACT_END; -*/ -#if !defined(__GNUC__) - _ASSERTE(!IsResource()); -#endif -#ifdef DACCESS_COMPILE - WRAPPER_NO_CONTRACT; - return DacGetMDImport(this, true); -#else - CONTRACTL - { - NOTHROW; - WRAPPER(GC_TRIGGERS); - MODE_ANY; - CAN_TAKE_LOCK; - } - CONTRACTL_END; - - GCX_PREEMP(); - SimpleReadLockHolder lock(m_pMetadataLock); - if(m_pMDImport) - m_pMDImport->AddRef(); - return m_pMDImport; -#endif -} +}; #ifndef DACCESS_COMPILE -inline IMetaDataImport2 *PEFile::GetRWImporter() +inline IMetaDataImport2 *PEAssembly::GetRWImporter() { CONTRACT(IMetaDataImport2 *) { INSTANCE_CHECK; - PRECONDITION(!IsResource()); POSTCONDITION(CheckPointer(RETVAL)); - PRECONDITION(m_bHasPersistentMDImport); GC_NOTRIGGER; THROWS; MODE_ANY; @@ -417,16 +298,14 @@ inline IMetaDataImport2 *PEFile::GetRWImporter() RETURN m_pImporter; } -inline IMetaDataEmit *PEFile::GetEmitter() +inline IMetaDataEmit *PEAssembly::GetEmitter() { CONTRACT(IMetaDataEmit *) { INSTANCE_CHECK; MODE_ANY; GC_NOTRIGGER; - PRECONDITION(!IsResource()); POSTCONDITION(CheckPointer(RETVAL)); - PRECONDITION(m_bHasPersistentMDImport); THROWS; } CONTRACT_END; @@ -440,40 +319,10 @@ inline IMetaDataEmit *PEFile::GetEmitter() #endif // DACCESS_COMPILE -// The simple name is not actually very simple. The name returned comes from one of -// various metadata tables, depending on whether this is a manifest module, -// non-manifest module, or something else -inline LPCUTF8 PEFile::GetSimpleName() -{ - CONTRACT(LPCUTF8) - { - INSTANCE_CHECK; - MODE_ANY; - POSTCONDITION(CheckPointer(RETVAL)); - NOTHROW; - SUPPORTS_DAC; - WRAPPER(GC_TRIGGERS); - } - CONTRACT_END; - - if (IsAssembly()) - RETURN dac_cast(this)->GetSimpleName(); - else - { - LPCUTF8 szScopeName; - if (FAILED(GetScopeName(&szScopeName))) - { - szScopeName = ""; - } - RETURN szScopeName; - } -} - - // Same as the managed Module.ScopeName property, this unconditionally looks in the // metadata Module table to get the name. Useful for profilers and others who don't // like sugar coating on their names. -inline HRESULT PEFile::GetScopeName(LPCUTF8 * pszName) +inline HRESULT PEAssembly::GetScopeName(LPCUTF8 * pszName) { CONTRACTL { @@ -493,14 +342,7 @@ inline HRESULT PEFile::GetScopeName(LPCUTF8 * pszName) // PE file access // ------------------------------------------------------------ -inline BOOL PEFile::IsIbcOptimized() -{ - WRAPPER_NO_CONTRACT; - - return FALSE; -} - -inline BOOL PEFile::IsReadyToRun() +inline BOOL PEAssembly::IsReadyToRun() { CONTRACTL { @@ -511,9 +353,9 @@ inline BOOL PEFile::IsReadyToRun() } CONTRACTL_END; - if (HasOpenedILimage()) + if (HasPEImage()) { - return GetLoadedIL()->HasReadyToRunHeader(); + return GetLoadedLayout()->HasReadyToRunHeader(); } else { @@ -521,63 +363,37 @@ inline BOOL PEFile::IsReadyToRun() } } -inline WORD PEFile::GetSubsystem() -{ - WRAPPER_NO_CONTRACT; - - if (IsResource() || IsDynamic()) - return 0; - - return GetLoadedIL()->GetSubsystem(); -} - -inline mdToken PEFile::GetEntryPointToken( -#ifdef _DEBUG - BOOL bAssumeLoaded -#endif //_DEBUG - ) +inline mdToken PEAssembly::GetEntryPointToken() { WRAPPER_NO_CONTRACT; - if (IsResource() || IsDynamic()) + if (IsDynamic()) return mdTokenNil; - _ASSERTE (!bAssumeLoaded || HasLoadedIL ()); - return GetOpenedILimage()->GetEntryPointToken(); + return GetPEImage()->GetEntryPointToken(); } -inline BOOL PEFile::IsILOnly() +inline BOOL PEAssembly::IsILOnly() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; CONTRACT_VIOLATION(ThrowsViolation|GCViolation|FaultViolation); - if (IsResource() || IsDynamic()) + if (IsDynamic()) return FALSE; - return GetOpenedILimage()->IsILOnly(); -} - -inline BOOL PEFile::IsDll() -{ - WRAPPER_NO_CONTRACT; - - if (IsResource() || IsDynamic()) - return TRUE; - - return GetOpenedILimage()->IsDll(); + return GetPEImage()->IsILOnly(); } -inline PTR_VOID PEFile::GetRvaField(RVA field) +inline PTR_VOID PEAssembly::GetRvaField(RVA field) { CONTRACT(void *) { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); PRECONDITION(CheckRvaField(field)); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -589,17 +405,16 @@ inline PTR_VOID PEFile::GetRvaField(RVA field) // Note that the native image Rva fields are currently cut off before // this point. We should not get here for an IL only native image. - RETURN dac_cast(GetLoadedIL()->GetRvaData(field,NULL_OK)); + RETURN dac_cast(GetLoadedLayout()->GetRvaData(field,NULL_OK)); } -inline CHECK PEFile::CheckRvaField(RVA field) +inline CHECK PEAssembly::CheckRvaField(RVA field) { CONTRACT_CHECK { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -609,18 +424,17 @@ inline CHECK PEFile::CheckRvaField(RVA field) // Note that the native image Rva fields are currently cut off before // this point. We should not get here for an IL only native image. - CHECK(GetLoadedIL()->CheckRva(field,NULL_OK)); + CHECK(GetLoadedLayout()->CheckRva(field,NULL_OK)); CHECK_OK; } -inline CHECK PEFile::CheckRvaField(RVA field, COUNT_T size) +inline CHECK PEAssembly::CheckRvaField(RVA field, COUNT_T size) { CONTRACT_CHECK { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -630,11 +444,11 @@ inline CHECK PEFile::CheckRvaField(RVA field, COUNT_T size) // Note that the native image Rva fields are currently cut off before // this point. We should not get here for an IL only native image. - CHECK(GetLoadedIL()->CheckRva(field, size,0,NULL_OK)); + CHECK(GetLoadedLayout()->CheckRva(field, size,0,NULL_OK)); CHECK_OK; } -inline BOOL PEFile::HasTls() +inline BOOL PEAssembly::HasTls() { CONTRACTL { @@ -642,24 +456,21 @@ inline BOOL PEFile::HasTls() NOTHROW; GC_NOTRIGGER; MODE_ANY; - PRECONDITION(CheckLoaded()); + PRECONDITION(IsLoaded()); } CONTRACTL_END; - // Resource modules do not contain TLS data. - if (IsResource()) - return FALSE; // Dynamic modules do not contain TLS data. - else if (IsDynamic()) + if (IsDynamic()) return FALSE; // ILOnly modules do not contain TLS data. else if (IsILOnly()) return FALSE; else - return GetLoadedIL()->HasTls(); + return GetLoadedLayout()->HasTls(); } -inline BOOL PEFile::IsRvaFieldTls(RVA field) +inline BOOL PEAssembly::IsRvaFieldTls(RVA field) { CONTRACTL { @@ -667,30 +478,30 @@ inline BOOL PEFile::IsRvaFieldTls(RVA field) NOTHROW; GC_NOTRIGGER; MODE_ANY; - PRECONDITION(CheckLoaded()); + PRECONDITION(IsLoaded()); } CONTRACTL_END; if (!HasTls()) return FALSE; - PTR_VOID address = PTR_VOID(GetLoadedIL()->GetRvaData(field)); + PTR_VOID address = PTR_VOID(GetLoadedLayout()->GetRvaData(field)); COUNT_T tlsSize; - PTR_VOID tlsRange = GetLoadedIL()->GetTlsRange(&tlsSize); + PTR_VOID tlsRange = GetLoadedLayout()->GetTlsRange(&tlsSize); return (address >= tlsRange && address < (dac_cast(tlsRange)+tlsSize)); } -inline UINT32 PEFile::GetFieldTlsOffset(RVA field) +inline UINT32 PEAssembly::GetFieldTlsOffset(RVA field) { CONTRACTL { INSTANCE_CHECK; PRECONDITION(CheckRvaField(field)); PRECONDITION(IsRvaFieldTls(field)); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -698,14 +509,14 @@ inline UINT32 PEFile::GetFieldTlsOffset(RVA field) CONTRACTL_END; return (UINT32)(dac_cast(GetRvaField(field)) - - dac_cast(GetLoadedIL()->GetTlsRange())); + dac_cast(GetLoadedLayout()->GetTlsRange())); } -inline UINT32 PEFile::GetTlsIndex() +inline UINT32 PEAssembly::GetTlsIndex() { CONTRACTL { - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); INSTANCE_CHECK; PRECONDITION(HasTls()); NOTHROW; @@ -714,18 +525,17 @@ inline UINT32 PEFile::GetTlsIndex() } CONTRACTL_END; - return GetLoadedIL()->GetTlsIndex(); + return GetLoadedLayout()->GetTlsIndex(); } -inline const void *PEFile::GetInternalPInvokeTarget(RVA target) +inline const void *PEAssembly::GetInternalPInvokeTarget(RVA target) { CONTRACT(void *) { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); PRECONDITION(CheckInternalPInvokeTarget(target)); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -733,17 +543,16 @@ inline const void *PEFile::GetInternalPInvokeTarget(RVA target) } CONTRACT_END; - RETURN (void*)GetLoadedIL()->GetRvaData(target); + RETURN (void*)GetLoadedLayout()->GetRvaData(target); } -inline CHECK PEFile::CheckInternalPInvokeTarget(RVA target) +inline CHECK PEAssembly::CheckInternalPInvokeTarget(RVA target) { CONTRACT_CHECK { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -751,16 +560,16 @@ inline CHECK PEFile::CheckInternalPInvokeTarget(RVA target) CONTRACT_CHECK_END; CHECK(!IsILOnly()); - CHECK(GetLoadedIL()->CheckRva(target)); + CHECK(GetLoadedLayout()->CheckRva(target)); CHECK_OK; } -inline IMAGE_COR_VTABLEFIXUP *PEFile::GetVTableFixups(COUNT_T *pCount/*=NULL*/) +inline IMAGE_COR_VTABLEFIXUP *PEAssembly::GetVTableFixups(COUNT_T *pCount/*=NULL*/) { CONTRACT(IMAGE_COR_VTABLEFIXUP *) { - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); INSTANCE_CHECK; NOTHROW; GC_NOTRIGGER; @@ -769,26 +578,25 @@ inline IMAGE_COR_VTABLEFIXUP *PEFile::GetVTableFixups(COUNT_T *pCount/*=NULL*/) } CONTRACT_END; - if (IsResource() || IsDynamic() || IsILOnly()) + if (IsDynamic() || IsILOnly()) { if (pCount != NULL) *pCount = 0; RETURN NULL; } else - RETURN GetLoadedIL()->GetVTableFixups(pCount); + RETURN GetLoadedLayout()->GetVTableFixups(pCount); } -inline void *PEFile::GetVTable(RVA rva) +inline void *PEAssembly::GetVTable(RVA rva) { CONTRACT(void *) { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); PRECONDITION(!IsILOnly()); - PRECONDITION(GetLoadedIL()->CheckRva(rva)); + PRECONDITION(GetLoadedLayout()->CheckRva(rva)); NOTHROW; GC_NOTRIGGER; MODE_ANY; @@ -796,18 +604,17 @@ inline void *PEFile::GetVTable(RVA rva) } CONTRACT_END; - RETURN (void *)GetLoadedIL()->GetRvaData(rva); + RETURN (void *)GetLoadedLayout()->GetRvaData(rva); } // @todo: this is bad to expose. But it is needed to support current IJW thunks -inline HMODULE PEFile::GetIJWBase() +inline HMODULE PEAssembly::GetIJWBase() { CONTRACTL { INSTANCE_CHECK; PRECONDITION(!IsDynamic()); - PRECONDITION(!IsResource()); - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); PRECONDITION(!IsILOnly()); NOTHROW; GC_NOTRIGGER; @@ -815,10 +622,10 @@ inline HMODULE PEFile::GetIJWBase() } CONTRACTL_END; - return (HMODULE) dac_cast(GetLoadedIL()->GetBase()); + return (HMODULE) dac_cast(GetLoadedLayout()->GetBase()); } -inline PTR_VOID PEFile::GetDebuggerContents(COUNT_T *pSize/*=NULL*/) +inline PTR_VOID PEAssembly::GetDebuggerContents(COUNT_T *pSize/*=NULL*/) { CONTRACT(PTR_VOID) { @@ -835,12 +642,12 @@ inline PTR_VOID PEFile::GetDebuggerContents(COUNT_T *pSize/*=NULL*/) // helper thread. The debugger will have to expect a zero base // in some circumstances. - if (IsLoaded()) + if (HasLoadedPEImage()) { if (pSize != NULL) - *pSize = GetLoaded()->GetSize(); + *pSize = GetLoadedLayout()->GetSize(); - RETURN GetLoaded()->GetBase(); + RETURN GetLoadedLayout()->GetBase(); } else { @@ -851,7 +658,7 @@ inline PTR_VOID PEFile::GetDebuggerContents(COUNT_T *pSize/*=NULL*/) } } -inline PTR_CVOID PEFile::GetLoadedImageContents(COUNT_T *pSize/*=NULL*/) +inline PTR_CVOID PEAssembly::GetLoadedImageContents(COUNT_T *pSize/*=NULL*/) { CONTRACTL { @@ -863,13 +670,13 @@ inline PTR_CVOID PEFile::GetLoadedImageContents(COUNT_T *pSize/*=NULL*/) } CONTRACTL_END; - if (IsLoaded() && !IsDynamic()) + if (HasLoadedPEImage()) { if (pSize != NULL) { - *pSize = GetLoaded()->GetSize(); + *pSize = GetLoadedLayout()->GetSize(); } - return GetLoaded()->GetBase(); + return GetLoadedLayout()->GetBase(); } else { @@ -882,32 +689,32 @@ inline PTR_CVOID PEFile::GetLoadedImageContents(COUNT_T *pSize/*=NULL*/) } #ifndef DACCESS_COMPILE -inline const void *PEFile::GetManagedFileContents(COUNT_T *pSize/*=NULL*/) +inline const void *PEAssembly::GetManagedFileContents(COUNT_T *pSize/*=NULL*/) { CONTRACT(const void *) { INSTANCE_CHECK; - PRECONDITION(CheckLoaded()); + PRECONDITION(HasLoadedPEImage()); WRAPPER(THROWS); WRAPPER(GC_TRIGGERS); MODE_ANY; - POSTCONDITION((!GetLoaded()->GetSize()) || CheckPointer(RETVAL)); + POSTCONDITION((!GetLoadedLayout()->GetSize()) || CheckPointer(RETVAL)); } CONTRACT_END; // Right now, we will trigger a LoadLibrary for the caller's sake, // even if we are in a scenario where we could normally avoid it. - LoadLibrary(FALSE); + EnsureLoaded(); if (pSize != NULL) - *pSize = GetLoadedIL()->GetSize(); + *pSize = GetLoadedLayout()->GetSize(); - RETURN GetLoadedIL()->GetBase(); + RETURN GetLoadedLayout()->GetBase(); } #endif // DACCESS_COMPILE -inline BOOL PEFile::IsPtrInILImage(PTR_CVOID data) +inline BOOL PEAssembly::IsPtrInPEImage(PTR_CVOID data) { CONTRACTL { @@ -919,49 +726,13 @@ inline BOOL PEFile::IsPtrInILImage(PTR_CVOID data) } CONTRACTL_END; - if (HasOpenedILimage()) + if (HasPEImage()) { - return GetOpenedILimage()->IsPtrInImage(data); + return GetPEImage()->IsPtrInImage(data); } else return FALSE; } -// ------------------------------------------------------------ -// Native image access -// ------------------------------------------------------------ - -inline PTR_PEImageLayout PEFile::GetLoadedIL() -{ - LIMITED_METHOD_CONTRACT; - SUPPORTS_DAC; - - _ASSERTE(HasOpenedILimage()); - - return GetOpenedILimage()->GetLoadedLayout(); -}; - -inline BOOL PEFile::IsLoaded(BOOL bAllowNative/*=TRUE*/) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACTL_END; - if(IsDynamic()) - return TRUE; - return HasLoadedIL(); -}; - - -inline PTR_PEImageLayout PEFile::GetLoaded() -{ - WRAPPER_NO_CONTRACT; - SUPPORTS_DAC; - return GetLoadedIL(); -}; - // ------------------------------------------------------------ // Descriptive strings @@ -995,14 +766,14 @@ inline LPCSTR PEAssembly::GetSimpleName() CONTRACTL { NOTHROW; - if (!m_bHasPersistentMDImport) { GC_TRIGGERS;} else {DISABLED(GC_TRIGGERS);}; + DISABLED(GC_TRIGGERS); MODE_ANY; SUPPORTS_DAC; } CONTRACTL_END; LPCSTR name = ""; - IMDInternalImportHolder pImport = GetMDImport(); + IMDInternalImport* pImport = GetMDImport(); if (pImport != NULL) { if (FAILED(pImport->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, &name, NULL, NULL))) @@ -1014,7 +785,7 @@ inline LPCSTR PEAssembly::GetSimpleName() return name; } -inline BOOL PEFile::IsStrongNamed() +inline BOOL PEAssembly::IsStrongNamed() { CONTRACTL { @@ -1035,7 +806,7 @@ inline BOOL PEFile::IsStrongNamed() // Check to see if this assembly has had its strong name signature verified yet. // -inline const void *PEFile::GetPublicKey(DWORD *pcbPK) +inline const void *PEAssembly::GetPublicKey(DWORD *pcbPK) { CONTRACTL { @@ -1051,7 +822,7 @@ inline const void *PEFile::GetPublicKey(DWORD *pcbPK) return pPK; } -inline ULONG PEFile::GetHashAlgId() +inline ULONG PEAssembly::GetHashAlgId() { CONTRACTL { @@ -1066,7 +837,7 @@ inline ULONG PEFile::GetHashAlgId() return hashAlgId; } -inline LPCSTR PEFile::GetLocale() +inline LPCSTR PEAssembly::GetLocale() { CONTRACTL { @@ -1081,11 +852,10 @@ inline LPCSTR PEFile::GetLocale() return md.szLocale; } -inline DWORD PEFile::GetFlags() +inline DWORD PEAssembly::GetFlags() { CONTRACTL { - PRECONDITION(IsAssembly()); INSTANCE_CHECK; if (FORBIDGC_LOADER_USE_ENABLED()) NOTHROW; else THROWS; if (FORBIDGC_LOADER_USE_ENABLED()) GC_NOTRIGGER; else GC_TRIGGERS; @@ -1099,43 +869,4 @@ inline DWORD PEFile::GetFlags() return flags; } -// In the cases where you know the module is loaded, and cannot tolerate triggering and -// loading, this alternative to PEFile::GetFlags is useful. Profiling API uses this. -inline HRESULT PEFile::GetFlagsNoTrigger(DWORD * pdwFlags) -{ - CONTRACTL - { - PRECONDITION(IsAssembly()); - INSTANCE_CHECK; - NOTHROW; - GC_NOTRIGGER; - FORBID_FAULT; - MODE_ANY; - } - CONTRACTL_END; - - _ASSERTE (pdwFlags != NULL); - - if (!m_bHasPersistentMDImport) - return E_FAIL; - - return GetPersistentMDImport()->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, NULL, NULL, pdwFlags); -} - -// ------------------------------------------------------------ -// Metadata access -// ------------------------------------------------------------ - -inline void PEFile::OpenMDImport() -{ - WRAPPER_NO_CONTRACT; - //need synchronization - _ASSERTE(m_pMetadataLock->LockTaken() && m_pMetadataLock->IsWriterLock()); - OpenMDImport_Unsafe(); -} - -inline PEFile* PEFile::Dummy() -{ - return (PEFile*)(-1); -} -#endif // PEFILE_INL_ +#endif // PEASSEMBLY_INL_ diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 412d67c938f5e..584797e16279b 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -61,44 +61,20 @@ CHECK PEImage::CheckStartup() CHECK_OK; } -/* static */ -CHECK PEImage::CheckLayoutFormat(PEDecoder *pe) -{ - CONTRACT_CHECK - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACT_CHECK_END; - - CHECK(pe->IsILOnly()); - CHECK_OK; -} - CHECK PEImage::CheckILFormat() { WRAPPER_NO_CONTRACT; - - PTR_PEImageLayout pLayoutToCheck; - PEImageLayoutHolder pLayoutHolder; - - if (HasLoadedLayout()) - { - pLayoutToCheck = GetLoadedLayout(); - } - else - { - pLayoutHolder = GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED); - pLayoutToCheck = pLayoutHolder; - } - - CHECK(pLayoutToCheck->CheckILFormat()); - + CHECK(GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->CheckILFormat()); CHECK_OK; }; +// PEImage is always unique on CoreCLR so a simple pointer check is sufficient in PEImage::Equals +CHECK PEImage::CheckUniqueInstance() +{ + CHECK(GetPath().IsEmpty() || m_bInHashMap); + CHECK_OK; +} + PEImage::~PEImage() { CONTRACTL @@ -116,7 +92,7 @@ PEImage::~PEImage() if (m_pLayoutLock) delete m_pLayoutLock; - if(m_hFile!=INVALID_HANDLE_VALUE && m_bOwnHandle) + if(m_hFile!=INVALID_HANDLE_VALUE) CloseHandle(m_hFile); for (unsigned int i=0;iDeleteValue(GetIDHash(), &locator); + PEImage* deleted = (PEImage *)s_Images->DeleteValue(GetPathHash(), &locator); _ASSERTE(deleted == this); } } @@ -252,44 +228,6 @@ CHECK PEImage::CheckCanonicalFullPath(const SString &path) CHECK_OK; } -BOOL PEImage::PathEquals(const SString &p1, const SString &p2) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACTL_END; - -#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM - return p1.Equals(p2); -#else - return p1.EqualsCaseInsensitive(p2); -#endif -} - -#ifndef TARGET_UNIX -/* static */ -void PEImage::GetPathFromDll(HINSTANCE hMod, SString &result) -{ - CONTRACTL - { - PRECONDITION(CheckStartup()); - PRECONDITION(CheckPointer(hMod)); - PRECONDITION(CheckValue(result)); - THROWS; - GC_NOTRIGGER; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - WszGetModuleFileName(hMod, result); - -} -#endif // !TARGET_UNIX - /* static */ BOOL PEImage::CompareImage(UPTR u1, UPTR u2) { @@ -307,16 +245,25 @@ BOOL PEImage::CompareImage(UPTR u1, UPTR u2) // This is the value stored in the table PEImage *pImage = (PEImage *) u2; + if (pLocator->m_bIsInBundle != pImage->IsInBundle()) + { + return FALSE; + } BOOL ret = FALSE; HRESULT hr; EX_TRY { SString path(SString::Literal, pLocator->m_pPath); - BOOL isInBundle = pLocator->m_bIsInBundle; - if (PathEquals(path, pImage->GetPath()) && - (!isInBundle == !pImage->IsInBundle())) + +#ifdef FEATURE_CASE_SENSITIVE_FILESYSTEM + if (pImage->GetPath().Equals(path)) +#else + if (pImage->GetPath().EqualsCaseInsensitive(path)) +#endif + { ret = TRUE; + } } EX_CATCH_HRESULT(hr); //ignores failure! return ret; @@ -335,8 +282,8 @@ BOOL PEImage::Equals(PEImage *pImage) CONTRACTL_END; // PEImage is always unique on CoreCLR so a simple pointer check is sufficient - _ASSERTE(m_bInHashMap || GetPath().IsEmpty()); - _ASSERTE(pImage->m_bInHashMap || pImage->GetPath().IsEmpty()); + _ASSERTE(CheckUniqueInstance()); + _ASSERTE(pImage->CheckUniqueInstance()); return dac_cast(pImage) == dac_cast(this); } @@ -791,18 +738,16 @@ void PEImage::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) PEImage::PEImage(): m_path(), m_refCount(1), - m_bundleFileLocation(), m_bInHashMap(FALSE), + m_bundleFileLocation(), + m_hFile(INVALID_HANDLE_VALUE), + m_dwPEKind(0), + m_dwMachine(0), #ifdef METADATATRACKER_DATA m_pMDTracker(NULL), #endif // METADATATRACKER_DATA m_pMDImport(NULL), - m_pNativeMDImport(NULL), - m_hFile(INVALID_HANDLE_VALUE), - m_bOwnHandle(true), - m_dwPEKind(0), - m_dwMachine(0), - m_fCachedKindAndMachine(FALSE) + m_pNativeMDImport(NULL) { CONTRACTL { @@ -816,48 +761,46 @@ PEImage::PEImage(): m_pLayoutLock=new SimpleRWLock(PREEMPTIVE,LOCK_TYPE_DEFAULT); } -PTR_PEImageLayout PEImage::GetLayout(DWORD imageLayoutMask,DWORD flags) +PTR_PEImageLayout PEImage::GetOrCreateLayout(DWORD imageLayoutMask) { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - PTR_PEImageLayout pRetVal; + // First attempt to find an existing layout matching imageLayoutMask. + // If that fails, try again with auto-creating helper. + // Note: we use reader-writer lock, but only writes are synchronized. + PTR_PEImageLayout pRetVal = GetExistingLayoutInternal(imageLayoutMask); #ifndef DACCESS_COMPILE - // First attempt to find an existing layout matching imageLayoutMask. If that fails, - // and the caller has asked us to create layouts if needed, then try again passing - // the create flag to GetLayoutInternal. We need this to be synchronized, but the common - // case is that the layout already exists, so use a reader-writer lock. - GCX_PREEMP(); - { - SimpleReadLockHolder lock(m_pLayoutLock); - pRetVal=GetLayoutInternal(imageLayoutMask,flags&(~LAYOUT_CREATEIFNEEDED)); - } - - if (!(pRetVal || (flags&LAYOUT_CREATEIFNEEDED)==0)) + if (pRetVal == NULL) { + GCX_PREEMP(); SimpleWriteLockHolder lock(m_pLayoutLock); - pRetVal = GetLayoutInternal(imageLayoutMask,flags); + pRetVal = GetOrCreateLayoutInternal(imageLayoutMask); } - - return pRetVal; - #else // In DAC builds, we can't create any layouts - we must require that they already exist. // We also don't take any AddRefs or locks in DAC builds - it's inspection-only. - pRetVal = GetExistingLayoutInternal(imageLayoutMask); - if ((pRetVal==NULL) && (flags & LAYOUT_CREATEIFNEEDED)) - { - _ASSERTE_MSG(false, "DACization error - caller expects PEImage layout to exist and it doesn't"); - DacError(E_UNEXPECTED); - } - return pRetVal; + _ASSERTE_MSG(false, "DACization error - caller expects PEImage layout to exist and it doesn't"); + DacError(E_UNEXPECTED); #endif + + return pRetVal; } #ifndef DACCESS_COMPILE -PTR_PEImageLayout PEImage::GetLayoutInternal(DWORD imageLayoutMask,DWORD flags) +void PEImage::SetLayout(DWORD dwLayout, PEImageLayout* pLayout) +{ + LIMITED_METHOD_CONTRACT; + _ASSERTE(dwLayout < IMAGE_COUNT); + _ASSERTE(m_pLayoutLock->IsWriterLock()); + _ASSERTE(m_pLayouts[dwLayout] == NULL); + + m_pLayouts[dwLayout] = pLayout; +} + +PTR_PEImageLayout PEImage::GetOrCreateLayoutInternal(DWORD imageLayoutMask) { CONTRACTL { @@ -869,9 +812,9 @@ PTR_PEImageLayout PEImage::GetLayoutInternal(DWORD imageLayoutMask,DWORD flags) PTR_PEImageLayout pRetVal=GetExistingLayoutInternal(imageLayoutMask); - if (pRetVal==NULL && (flags&LAYOUT_CREATEIFNEEDED)) + if (pRetVal==NULL) { - _ASSERTE(HasID()); + _ASSERTE(HasPath()); BOOL bIsMappedLayoutSuitable = ((imageLayoutMask & PEImageLayout::LAYOUT_MAPPED) != 0); BOOL bIsFlatLayoutSuitable = ((imageLayoutMask & PEImageLayout::LAYOUT_FLAT) != 0); @@ -906,11 +849,8 @@ PTR_PEImageLayout PEImage::GetLayoutInternal(DWORD imageLayoutMask,DWORD flags) } } - if (pRetVal != NULL) - { - pRetVal->AddRef(); - } - + _ASSERTE(pRetVal != NULL); + _ASSERTE(this->IsOpened()); return pRetVal; } @@ -982,9 +922,10 @@ PTR_PEImageLayout PEImage::CreateLayoutMapped() } else { - PEImageLayoutHolder flatPE(GetLayoutInternal(PEImageLayout::LAYOUT_FLAT,LAYOUT_CREATEIFNEEDED)); + PEImageLayout* flatPE = GetOrCreateLayout(PEImageLayout::LAYOUT_FLAT); if (!flatPE->CheckFormat() || !flatPE->IsILOnly()) ThrowHR(COR_E_BADIMAGEFORMAT); + pRetVal=PEImageLayout::LoadFromFlat(flatPE); SetLayout(IMAGE_MAPPED,pRetVal); } @@ -1034,6 +975,10 @@ PTR_PEImage PEImage::LoadFlat(const void *flat, COUNT_T size) PEImageHolder pImage(new PEImage()); PTR_PEImageLayout pLayout = PEImageLayout::CreateFlat(flat,size,pImage); _ASSERTE(!pLayout->IsMapped()); + + //Not taking a lock here since we have just created pImage + //SimpleWriteLockHolder lock(pImage->m_pLayoutLock); + pImage->SetLayout(IMAGE_FLAT,pLayout); RETURN dac_cast(pImage.Extract()); } @@ -1051,12 +996,13 @@ PTR_PEImage PEImage::LoadImage(HMODULE hMod) CONTRACT_END; StackSString path; - GetPathFromDll(hMod, path); - PEImageHolder pImage(PEImage::OpenImage(path,(MDInternalImportFlags)(0))); + WszGetModuleFileName(hMod, path); + PEImageHolder pImage(PEImage::OpenImage(path, MDInternalImport_Default)); if (pImage->HasLoadedLayout()) RETURN dac_cast(pImage.Extract()); - SimpleWriteLockHolder lock(pImage->m_pLayoutLock); + //Not taking a lock here since we have just created pImage + // SimpleWriteLockHolder lock(pImage->m_pLayoutLock); if(pImage->m_pLayouts[IMAGE_LOADED]==NULL) pImage->SetLayout(IMAGE_LOADED,PEImageLayout::CreateFromHMODULE(hMod,pImage,WszGetModuleHandle(NULL)!=hMod)); @@ -1134,18 +1080,6 @@ void PEImage::Load() } } -void PEImage::SetLoadedHMODULE(HMODULE hMod) -{ - WRAPPER_NO_CONTRACT; - SimpleWriteLockHolder lock(m_pLayoutLock); - if(m_pLayouts[IMAGE_LOADED]) - { - _ASSERTE(m_pLayouts[IMAGE_LOADED]->GetBase()==hMod); - return; - } - SetLayout(IMAGE_LOADED,PEImageLayout::CreateFromHMODULE(hMod,this,TRUE)); -} - void PEImage::LoadFromMapped() { STANDARD_VM_CONTRACT; @@ -1156,10 +1090,13 @@ void PEImage::LoadFromMapped() return; } - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_MAPPED,LAYOUT_CREATEIFNEEDED)); + PEImageLayout* pLayout = GetOrCreateLayout(PEImageLayout::LAYOUT_MAPPED); SimpleWriteLockHolder lock(m_pLayoutLock); - if(m_pLayouts[IMAGE_LOADED]==NULL) - SetLayout(IMAGE_LOADED,pLayout.Extract()); + if (m_pLayouts[IMAGE_LOADED] == NULL) + { + pLayout->AddRef(); + SetLayout(IMAGE_LOADED, pLayout); + } } void PEImage::LoadNoFile() @@ -1173,38 +1110,18 @@ void PEImage::LoadNoFile() if (HasLoadedLayout()) return; - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,0)); + PEImageLayout* pLayout = GetExistingLayoutInternal(PEImageLayout::LAYOUT_ANY); if (!pLayout->CheckILOnly()) ThrowHR(COR_E_BADIMAGEFORMAT); - SimpleWriteLockHolder lock(m_pLayoutLock); - if(m_pLayouts[IMAGE_LOADED]==NULL) - SetLayout(IMAGE_LOADED,pLayout.Extract()); -} - - -void PEImage::LoadNoMetaData() -{ - STANDARD_VM_CONTRACT; - - if (HasLoadedLayout()) - return; SimpleWriteLockHolder lock(m_pLayoutLock); - if (m_pLayouts[IMAGE_LOADED]!=NULL) - return; - if (m_pLayouts[IMAGE_FLAT]!=NULL) - { - m_pLayouts[IMAGE_FLAT]->AddRef(); - SetLayout(IMAGE_LOADED,m_pLayouts[IMAGE_FLAT]); - } - else + if (m_pLayouts[IMAGE_LOADED] == NULL) { - _ASSERTE(!m_path.IsEmpty()); - SetLayout(IMAGE_LOADED,PEImageLayout::LoadFlat(this)); + pLayout->AddRef(); + SetLayout(IMAGE_LOADED, pLayout); } } - #endif //DACCESS_COMPILE //------------------------------------------------------------------------------- @@ -1264,22 +1181,6 @@ HANDLE PEImage::GetFileHandle() return m_hFile; } -void PEImage::SetFileHandle(HANDLE hFile) -{ - CONTRACTL - { - STANDARD_VM_CHECK; - } - CONTRACTL_END; - - SimpleWriteLockHolder lock(m_pLayoutLock); - if (m_hFile == INVALID_HANDLE_VALUE) - { - m_hFile = hFile; - m_bOwnHandle = false; - } -} - HRESULT PEImage::TryOpenFile() { STANDARD_VM_CONTRACT; diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index af86e35ccaec4..679b3e024d337 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -26,9 +26,6 @@ class SimpleRWLock; // -------------------------------------------------------------------------------- class Crst; -class Thread; - -Thread* GetThreadNULLOk(); // -------------------------------------------------------------------------------- // PEImage is a PE file loaded by our "simulated LoadLibrary" mechanism. A PEImage @@ -56,92 +53,54 @@ struct CV_INFO_PDB70 typedef DPTR(class PEImage) PTR_PEImage; -class PEImage +class PEImage final { -public: - // ------------------------------------------------------------ - // Public constants - // ------------------------------------------------------------ - - enum - { - LAYOUT_CREATEIFNEEDED=1 - }; - PTR_PEImageLayout GetLayout(DWORD imageLayoutMask,DWORD flags); //with ref - PTR_PEImageLayout GetLoadedLayout(); //no ref - BOOL IsOpened(); - BOOL HasLoadedLayout(); public: // ------------------------------------------------------------ // Public API // ------------------------------------------------------------ + // initialize static data (i.e. locks, unique instance cache, etc..) static void Startup(); - // Normal constructed PEImages do NOT share images between calls and - // cannot be accessed by Get methods. - // - // DO NOT USE these unless you want a private copy-on-write mapping of - // the file. - - - -public: ~PEImage(); PEImage(); + BOOL Equals(PEImage* pImage); + + ULONG AddRef(); + ULONG Release(); + #ifndef DACCESS_COMPILE - static PTR_PEImage LoadFlat( - const void *flat, - COUNT_T size); + static PTR_PEImage LoadFlat(const void *flat, COUNT_T size); #ifndef TARGET_UNIX - static PTR_PEImage LoadImage( - HMODULE hMod); + static PTR_PEImage LoadImage(HMODULE hMod); #endif // !TARGET_UNIX static PTR_PEImage OpenImage( LPCWSTR pPath, MDInternalImportFlags flags = MDInternalImport_Default, BundleFileLocation bundleFileLocation = BundleFileLocation::Invalid()); - - // clones the image with new flags (this is pretty much about cached / noncached difference) - void Clone(MDInternalImportFlags flags, PTR_PEImage* ppImage) - { - if (GetPath().IsEmpty()) - { - AddRef(); - *ppImage = this; - } - else - *ppImage = PEImage::OpenImage(GetPath(), flags); - - }; - - static PTR_PEImage FindById(UINT64 uStreamAsmId, DWORD dwModuleId); - static PTR_PEImage FindByPath(LPCWSTR pPath, - BOOL isInBundle = TRUE); - static PTR_PEImage FindByShortPath(LPCWSTR pPath); - static PTR_PEImage FindByLongPath(LPCWSTR pPath); + static PTR_PEImage FindByPath(LPCWSTR pPath, BOOL isInBundle = TRUE); void AddToHashMap(); void Load(); - void SetLoadedHMODULE(HMODULE hMod); - void LoadNoMetaData(); void LoadNoFile(); void LoadFromMapped(); #endif - BOOL HasID(); - ULONG GetIDHash(); + BOOL IsOpened(); + PTR_PEImageLayout GetOrCreateLayout(DWORD imageLayoutMask); - // Refcount above images. - ULONG AddRef(); - ULONG Release(); + BOOL HasLoadedLayout(); + PTR_PEImageLayout GetLoadedLayout(); - // Accessors - const SString &GetPath(); + BOOL HasPath(); + ULONG GetPathHash(); + const SString& GetPath(); const SString& GetPathToLoad(); + BOOL IsFile(); BOOL IsInBundle() const; HANDLE GetFileHandle(); @@ -149,14 +108,10 @@ class PEImage INT64 GetSize() const; INT64 GetUncompressedSize() const; - void SetFileHandle(HANDLE hFile); HRESULT TryOpenFile(); LPCWSTR GetPathForErrorMessages(); - // Equality - BOOL Equals(PEImage *pImage); - void GetMVID(GUID *pMvid); BOOL HasV1Metadata(); IMDInternalImport* GetMDImport(); @@ -165,54 +120,53 @@ class PEImage BOOL HasContents() ; BOOL IsPtrInImage(PTR_CVOID data); - CHECK CheckFormat(); - - // Check utilites - CHECK CheckILFormat(); - static CHECK CheckCanonicalFullPath(const SString &path); - static CHECK CheckStartup(); - PTR_CVOID GetMetadata(COUNT_T *pSize = NULL); - -#ifndef TARGET_UNIX - static void GetPathFromDll(HINSTANCE hMod, SString &result); -#endif // !TARGET_UNIX - static BOOL PathEquals(const SString &p1, const SString &p2); - - void SetModuleFileNameHintForDAC(); -#ifdef DACCESS_COMPILE - void EnumMemoryRegions(CLRDataEnumMemoryFlags flags); - const SString &GetModuleFileNameHintForDAC(); -#endif BOOL HasNTHeaders(); BOOL HasCorHeader(); BOOL HasReadyToRunHeader(); + BOOL HasDirectoryEntry(int entry); + BOOL Has32BitNTHeaders(); + + void GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine); + + BOOL IsILOnly(); BOOL IsReferenceAssembly(); BOOL IsComponentAssembly(); - PTR_CVOID GetNativeManifestMetadata(COUNT_T *pSize = NULL); - BOOL HasDirectoryEntry(int entry); + + PTR_CVOID GetNativeManifestMetadata(COUNT_T* pSize = NULL); mdToken GetEntryPointToken(); DWORD GetCorHeaderFlags(); - BOOL IsILOnly(); - BOOL IsDll(); - WORD GetSubsystem(); - BOOL IsFileLocked(); - BOOL IsIbcOptimized(); - BOOL Has32BitNTHeaders(); + PTR_CVOID GetMetadata(COUNT_T* pSize = NULL); + + // Check utilites + static CHECK CheckStartup(); + static CHECK CheckCanonicalFullPath(const SString& path); + + CHECK CheckFormat(); + CHECK CheckILFormat(); + CHECK CheckUniqueInstance(); void VerifyIsAssembly(); + void SetModuleFileNameHintForDAC(); +#ifdef DACCESS_COMPILE + void EnumMemoryRegions(CLRDataEnumMemoryFlags flags); + const SString &GetModuleFileNameHintForDAC(); +#endif + private: #ifndef DACCESS_COMPILE // Get or create the layout corresponding to the mask, with an AddRef - PTR_PEImageLayout GetLayoutInternal(DWORD imageLayoutMask, DWORD flags); + PTR_PEImageLayout GetOrCreateLayoutInternal(DWORD imageLayoutMask); // Create the mapped layout PTR_PEImageLayout CreateLayoutMapped(); // Create the flat layout PTR_PEImageLayout CreateLayoutFlat(BOOL bPermitWriteableSections); + + void SetLayout(DWORD dwLayout, PTR_PEImageLayout pLayout); #endif // Get an existing layout corresponding to the mask, no AddRef PTR_PEImageLayout GetExistingLayoutInternal(DWORD imageLayoutMask); @@ -249,28 +203,83 @@ class PEImage void DECLSPEC_NORETURN ThrowFormat(HRESULT hr); - static CHECK CheckLayoutFormat(PEDecoder *pe); +public: + class IJWFixupData + { + private: + Crst m_lock; + void* m_base; + DWORD m_flags; + PTR_LoaderHeap m_DllThunkHeap; + + // the fixup for the next iteration in FixupVTables + // we use it to make sure that we do not try to fix up the same entry twice + // if there was a pass that was aborted in the middle + COUNT_T m_iNextFixup; + COUNT_T m_iNextMethod; + + enum { + e_FIXED_UP = 0x1 + }; + + public: + IJWFixupData(void* pBase); + ~IJWFixupData(); + void* GetBase() { LIMITED_METHOD_CONTRACT; return m_base; } + Crst* GetLock() { LIMITED_METHOD_CONTRACT; return &m_lock; } + BOOL IsFixedUp() { LIMITED_METHOD_CONTRACT; return m_flags & e_FIXED_UP; } + void SetIsFixedUp() { LIMITED_METHOD_CONTRACT; m_flags |= e_FIXED_UP; } + PTR_LoaderHeap GetThunkHeap(); + void MarkMethodFixedUp(COUNT_T iFixup, COUNT_T iMethod); + BOOL IsMethodFixedUp(COUNT_T iFixup, COUNT_T iMethod); + }; + + static IJWFixupData* GetIJWData(void* pBase); + static PTR_LoaderHeap GetDllThunkHeap(void* pBase); + static void UnloadIJWModule(void* pBase); + +private: // ------------------------------------------------------------ - // Instance members + // Static fields // ------------------------------------------------------------ - SString m_path; - LONG m_refCount; + static CrstStatic s_hashLock; + static PtrHashMap* s_Images; - BundleFileLocation m_bundleFileLocation; // If this image is located within a single-file bundle, - // the location within the bundle. If m_bundleFileLocation is valid, - // it takes precedence over m_path for loading. +//@TODO:workaround: Remove this when we have one PEImage per mapped image, +//@TODO:workaround: and move the lock there +// This is for IJW thunk initialization, as it is no longer guaranteed +// that the initialization will occur under the loader lock. + static CrstStatic s_ijwHashLock; + static PtrHashMap* s_ijwFixupDataHash; + + // ------------------------------------------------------------ + // Instance fields + // ------------------------------------------------------------ + + SString m_path; + LONG m_refCount; + + // means this is a unique (deduped) instance. + BOOL m_bInHashMap; + + // If this image is located within a single-file bundle, the location within the bundle. + // If m_bundleFileLocation is valid, it takes precedence over m_path for loading. + BundleFileLocation m_bundleFileLocation; + + // valid handle if we tried to open the file/path and succeeded. + HANDLE m_hFile; + + DWORD m_dwPEKind; + DWORD m_dwMachine; // This variable will have the data of module name. // It is only used by DAC to remap fusion loaded modules back to // disk IL. This really is a workaround. The real fix is for fusion loader // hook (public API on hosting) to take an additional file name hint. // We are piggy backing on the fact that module name is the same as file name!!! - // - SString m_sModuleFileNameHintUsedByDac; // This is only used by DAC - -protected: + SString m_sModuleFileNameHintUsedByDac; // This is only used by DAC enum { @@ -282,11 +291,6 @@ class PEImage SimpleRWLock *m_pLayoutLock; PTR_PEImageLayout m_pLayouts[IMAGE_COUNT] ; - BOOL m_bInHashMap; -#ifndef DACCESS_COMPILE - void SetLayout(DWORD dwLayout, PTR_PEImageLayout pLayout); -#endif // DACCESS_COMPILE - #ifdef METADATATRACKER_DATA class MetaDataTracker *m_pMDTracker; @@ -294,75 +298,6 @@ class PEImage IMDInternalImport* m_pMDImport; IMDInternalImport* m_pNativeMDImport; - - -private: - - - // ------------------------------------------------------------ - // Static members - // ------------------------------------------------------------ - - static CrstStatic s_hashLock; - - static PtrHashMap *s_Images; - - HANDLE m_hFile; - bool m_bOwnHandle; - - //@TODO:workaround: Remove this when we have one PEImage per mapped image, - //@TODO:workaround: and move the lock there - // This is for IJW thunk initialization, as it is no longer guaranteed - // that the initialization will occur under the loader lock. - static CrstStatic s_ijwHashLock; - static PtrHashMap *s_ijwFixupDataHash; - -public: - class IJWFixupData - { - private: - Crst m_lock; - void *m_base; - DWORD m_flags; - PTR_LoaderHeap m_DllThunkHeap; - - // the fixup for the next iteration in FixupVTables - // we use it to make sure that we do not try to fix up the same entry twice - // if there was a pass that was aborted in the middle - COUNT_T m_iNextFixup; - COUNT_T m_iNextMethod; - - enum { - e_FIXED_UP = 0x1 - }; - - public: - IJWFixupData(void *pBase); - ~IJWFixupData(); - void *GetBase() { LIMITED_METHOD_CONTRACT; return m_base; } - Crst *GetLock() { LIMITED_METHOD_CONTRACT; return &m_lock; } - BOOL IsFixedUp() { LIMITED_METHOD_CONTRACT; return m_flags & e_FIXED_UP; } - void SetIsFixedUp() { LIMITED_METHOD_CONTRACT; m_flags |= e_FIXED_UP; } - PTR_LoaderHeap GetThunkHeap(); - void MarkMethodFixedUp(COUNT_T iFixup, COUNT_T iMethod); - BOOL IsMethodFixedUp(COUNT_T iFixup, COUNT_T iMethod); - }; - - static IJWFixupData *GetIJWData(void *pBase); - static PTR_LoaderHeap GetDllThunkHeap(void *pBase); - static void UnloadIJWModule(void *pBase); - -private: - DWORD m_dwPEKind; - DWORD m_dwMachine; - BOOL m_fCachedKindAndMachine; - - - -public: - void CachePEKindAndMachine(); - void GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine); - }; FORCEINLINE void PEImageRelease(PEImage *i) diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index b855d379bd31e..8dc72d416fac3 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -106,24 +106,6 @@ inline BOOL PEImage::IsFile() return !GetPathToLoad().IsEmpty(); } -#ifndef DACCESS_COMPILE -inline void PEImage::SetLayout(DWORD dwLayout, PEImageLayout* pLayout) -{ - LIMITED_METHOD_CONTRACT; - _ASSERTE(dwLayoutHasNTHeaders(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->HasNTHeaders(); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->HasNTHeaders(); } inline BOOL PEImage::HasCorHeader() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->HasCorHeader(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->HasCorHeader(); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->HasCorHeader(); } inline BOOL PEImage::IsComponentAssembly() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->IsComponentAssembly(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->IsComponentAssembly(); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->IsComponentAssembly(); } inline BOOL PEImage::HasReadyToRunHeader() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->HasReadyToRunHeader(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->HasReadyToRunHeader(); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->HasReadyToRunHeader(); } inline BOOL PEImage::HasDirectoryEntry(int entry) { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->HasDirectoryEntry(entry); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->HasDirectoryEntry(entry); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->HasDirectoryEntry(entry); } inline mdToken PEImage::GetEntryPointToken() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - { - PTR_PEImageLayout pLayout = GetLoadedLayout(); - if (!pLayout->HasManagedEntryPoint()) - return mdTokenNil; - return pLayout->GetEntryPointToken(); - } - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - if (!pLayout->HasManagedEntryPoint()) - return mdTokenNil; - return pLayout->GetEntryPointToken(); - } + PEImageLayout* pLayout = GetOrCreateLayout(PEImageLayout::LAYOUT_ANY); + if (!pLayout->HasManagedEntryPoint()) + return mdTokenNil; + return pLayout->GetEntryPointToken(); } inline DWORD PEImage::GetCorHeaderFlags() { WRAPPER_NO_CONTRACT; - - if (HasLoadedLayout()) - { - PTR_PEImageLayout pLayout = GetLoadedLayout(); - return VAL32(pLayout->GetCorHeader()->Flags); - } - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return VAL32(pLayout->GetCorHeader()->Flags); - } + return VAL32(GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->GetCorHeader()->Flags); } inline BOOL PEImage::MDImportLoaded() @@ -299,93 +240,32 @@ inline BOOL PEImage::HasV1Metadata() inline BOOL PEImage::IsILOnly() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->IsILOnly(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->IsILOnly(); - } -} - -inline WORD PEImage::GetSubsystem() -{ - WRAPPER_NO_CONTRACT; - SUPPORTS_DAC; - - if (HasLoadedLayout()) - return GetLoadedLayout()->GetSubsystem(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->GetSubsystem(); - } -} - -inline BOOL PEImage::IsDll() -{ - WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->IsDll(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->IsDll(); - } -} - -inline BOOL PEImage::IsIbcOptimized() -{ - return false; + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->IsILOnly(); } inline PTR_CVOID PEImage::GetNativeManifestMetadata(COUNT_T *pSize) { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->GetNativeManifestMetadata(pSize); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->GetNativeManifestMetadata(pSize); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->GetNativeManifestMetadata(pSize); } inline PTR_CVOID PEImage::GetMetadata(COUNT_T *pSize) { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->GetMetadata(pSize); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->GetMetadata(pSize); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->GetMetadata(pSize); } inline BOOL PEImage::HasContents() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->HasContents(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->HasContents(); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->HasContents(); } inline CHECK PEImage::CheckFormat() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - CHECK(GetLoadedLayout()->CheckFormat()); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - CHECK(pLayout->CheckFormat()); - } + CHECK(GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->CheckFormat()); CHECK_OK; } @@ -429,15 +309,13 @@ inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath, BOOL isInBundle /* = TRUE DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) wcslen(pPath)); #endif return (PEImage *) s_Images->LookupValue(dwHash, &locator); - } /* static */ inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags /* = MDInternalImport_Default */, BundleFileLocation bundleFileLocation) { - BOOL fUseCache = !((flags & MDInternalImport_NoCache) == MDInternalImport_NoCache); - - if (!fUseCache) + BOOL forbidCache = (flags & MDInternalImport_NoCache); + if (forbidCache) { PEImageHolder pImage(new PEImage); pImage->Init(pPath, bundleFileLocation); @@ -447,8 +325,6 @@ inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags CrstHolder holder(&s_hashLock); PEImage* found = FindByPath(pPath, bundleFileLocation.IsValid()); - - if (found == (PEImage*) INVALIDENTRY) { // We did not find the entry in the Cache, and we've been asked to only use the cache. @@ -470,15 +346,8 @@ inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags } #endif -inline BOOL PEImage::IsFileLocked() -{ - WRAPPER_NO_CONTRACT; - return (m_pLayouts[IMAGE_FLAT])!=NULL || (m_pLayouts[IMAGE_MAPPED])!=NULL ; -} - #ifndef DACCESS_COMPILE - inline void PEImage::AddToHashMap() { CONTRACTL @@ -490,40 +359,30 @@ inline void PEImage::AddToHashMap() CONTRACTL_END; _ASSERTE(s_hashLock.OwnedByCurrentThread()); - s_Images->InsertValue(GetIDHash(),this); + s_Images->InsertValue(GetPathHash(),this); m_bInHashMap=TRUE; } #endif - - - inline BOOL PEImage::Has32BitNTHeaders() { WRAPPER_NO_CONTRACT; - if (HasLoadedLayout()) - return GetLoadedLayout()->Has32BitNTHeaders(); - else - { - PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED)); - return pLayout->Has32BitNTHeaders(); - } + return GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->Has32BitNTHeaders(); } -inline BOOL PEImage::HasID() +inline BOOL PEImage::HasPath() { LIMITED_METHOD_CONTRACT; - return !GetPath().IsEmpty(); } -inline ULONG PEImage::GetIDHash() +inline ULONG PEImage::GetPathHash() { CONTRACT(ULONG) { - PRECONDITION(HasID()); + PRECONDITION(HasPath()); MODE_ANY; GC_NOTRIGGER; THROWS; @@ -537,7 +396,7 @@ inline ULONG PEImage::GetIDHash() #endif } -inline void PEImage::CachePEKindAndMachine() +inline void PEImage::GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine) { CONTRACTL { @@ -547,40 +406,20 @@ inline void PEImage::CachePEKindAndMachine() } CONTRACTL_END; - // Do nothing if we have cached the information already - if(m_fCachedKindAndMachine) - return; - - PEImageLayoutHolder pLayout; - if (HasLoadedLayout()) - { - pLayout.Assign(GetLoadedLayout(), false); - } - else + // first check if we have a valid PE kind + if (VolatileLoad(&m_dwPEKind) == 0) { - pLayout.Assign(GetLayout(PEImageLayout::LAYOUT_MAPPED|PEImageLayout::LAYOUT_FLAT, - PEImage::LAYOUT_CREATEIFNEEDED)); - } - - // Compute result into a local variables first - DWORD dwPEKind, dwMachine; - pLayout->GetPEKindAndMachine(&dwPEKind, &dwMachine); + // Compute result into a local variables first + DWORD dwPEKind, dwMachine; + GetOrCreateLayout(PEImageLayout::LAYOUT_ANY)->GetPEKindAndMachine(&dwPEKind, &dwMachine); - // Write the final result into the lock-free cache. - m_dwPEKind = dwPEKind; - m_dwMachine = dwMachine; - MemoryBarrier(); - m_fCachedKindAndMachine = TRUE; -} + // Write the final results - first machine, then kind. + m_dwMachine = dwMachine; + VolatileStore(&m_dwPEKind, dwPEKind); + } -inline void PEImage::GetPEKindAndMachine(DWORD* pdwKind, DWORD* pdwMachine) -{ - WRAPPER_NO_CONTRACT; - CachePEKindAndMachine(); - if (pdwKind) - *pdwKind = m_dwPEKind; - if (pdwMachine) - *pdwMachine = m_dwMachine; + *pdwKind = m_dwPEKind; + *pdwMachine = m_dwMachine; } #endif // PEIMAGE_INL_ diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 33081b9b60586..e4c4c274cf309 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -806,7 +806,7 @@ PEImageLayout::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) { WRAPPER_NO_CONTRACT; DAC_ENUM_VTHIS(); - EMEM_OUT(("MEM: %p PEFile\n", dac_cast(this))); + EMEM_OUT(("MEM: %p PEAssembly\n", dac_cast(this))); PEDecoder::EnumMemoryRegions(flags,false); } #endif //DACCESS_COMPILE diff --git a/src/coreclr/vm/perfinfo.cpp b/src/coreclr/vm/perfinfo.cpp index b645052f46d2e..667223fedc605 100644 --- a/src/coreclr/vm/perfinfo.cpp +++ b/src/coreclr/vm/perfinfo.cpp @@ -27,28 +27,28 @@ PerfInfo::PerfInfo(int pid) } // Logs image loads into the process' perfinfo-%d.map file -void PerfInfo::LogImage(PEFile* pFile, WCHAR* guid) +void PerfInfo::LogImage(PEAssembly* pPEAssembly, WCHAR* guid) { CONTRACTL { THROWS; GC_NOTRIGGER; MODE_PREEMPTIVE; - PRECONDITION(pFile != nullptr); + PRECONDITION(pPEAssembly != nullptr); PRECONDITION(guid != nullptr); } CONTRACTL_END; SString value; - const SString& path = pFile->GetPath(); + const SString& path = pPEAssembly->GetPath(); if (path.IsEmpty()) { return; } SIZE_T baseAddr = 0; - if (pFile->IsReadyToRun()) + if (pPEAssembly->IsReadyToRun()) { - PEImageLayout *pLoadedLayout = pFile->GetLoaded(); + PEImageLayout *pLoadedLayout = pPEAssembly->GetLoadedLayout(); if (pLoadedLayout) { baseAddr = (SIZE_T)pLoadedLayout->GetBase(); diff --git a/src/coreclr/vm/perfinfo.h b/src/coreclr/vm/perfinfo.h index 759a844f30925..16b06865925c6 100644 --- a/src/coreclr/vm/perfinfo.h +++ b/src/coreclr/vm/perfinfo.h @@ -22,7 +22,7 @@ class PerfInfo { public: PerfInfo(int pid); ~PerfInfo(); - void LogImage(PEFile* pFile, WCHAR* guid); + void LogImage(PEAssembly* pPEAssembly, WCHAR* guid); private: CFileStream* m_Stream; diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 31da16cac5586..48f178aeb67c3 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -219,22 +219,22 @@ void PerfMap::LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, cons } -void PerfMap::LogImageLoad(PEFile * pFile) +void PerfMap::LogImageLoad(PEAssembly * pPEAssembly) { if (s_enabled) { - s_Current->LogImage(pFile); + s_Current->LogImage(pPEAssembly); } } // Log an image load to the map. -void PerfMap::LogImage(PEFile * pFile) +void PerfMap::LogImage(PEAssembly * pPEAssembly) { CONTRACTL{ THROWS; GC_NOTRIGGER; MODE_PREEMPTIVE; - PRECONDITION(pFile != nullptr); + PRECONDITION(pPEAssembly != nullptr); } CONTRACTL_END; @@ -247,9 +247,9 @@ void PerfMap::LogImage(PEFile * pFile) EX_TRY { WCHAR wszSignature[39]; - GetNativeImageSignature(pFile, wszSignature, lengthof(wszSignature)); + GetNativeImageSignature(pPEAssembly, wszSignature, lengthof(wszSignature)); - m_PerfInfo->LogImage(pFile, wszSignature); + m_PerfInfo->LogImage(pPEAssembly, wszSignature); } EX_CATCH{} EX_END_CATCH(SwallowAllExceptions); } @@ -361,10 +361,10 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, EX_CATCH{} EX_END_CATCH(SwallowAllExceptions); } -void PerfMap::GetNativeImageSignature(PEFile * pFile, WCHAR * pwszSig, unsigned int nSigSize) +void PerfMap::GetNativeImageSignature(PEAssembly * pPEAssembly, WCHAR * pwszSig, unsigned int nSigSize) { CONTRACTL{ - PRECONDITION(pFile != nullptr); + PRECONDITION(pPEAssembly != nullptr); PRECONDITION(pwszSig != nullptr); PRECONDITION(nSigSize >= 39); } CONTRACTL_END; @@ -372,7 +372,7 @@ void PerfMap::GetNativeImageSignature(PEFile * pFile, WCHAR * pwszSig, unsigned // We use the MVID as the signature, since ready to run images // don't have a native image signature. GUID mvid; - pFile->GetMVID(&mvid); + pPEAssembly->GetMVID(&mvid); if(!StringFromGUID2(mvid, pwszSig, nSigSize)) { pwszSig[0] = '\0'; @@ -417,7 +417,7 @@ void NativeImagePerfMap::LogDataForModule(Module * pModule) { STANDARD_VM_CONTRACT; - PEImageLayout * pLoadedLayout = pModule->GetFile()->GetLoaded(); + PEImageLayout * pLoadedLayout = pModule->GetPEAssembly()->GetLoadedLayout(); _ASSERTE(pLoadedLayout != nullptr); ReadyToRunInfo::MethodIterator mi(pModule->GetReadyToRunInfo()); diff --git a/src/coreclr/vm/perfmap.h b/src/coreclr/vm/perfmap.h index 14595813877d8..587a776e68276 100644 --- a/src/coreclr/vm/perfmap.h +++ b/src/coreclr/vm/perfmap.h @@ -57,17 +57,17 @@ class PerfMap void LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, const char *optimizationTier); // Does the actual work to log an image - void LogImage(PEFile * pFile); + void LogImage(PEAssembly * pPEAssembly); // Get the image signature and store it as a string. - static void GetNativeImageSignature(PEFile * pFile, WCHAR * pwszSig, unsigned int nSigSize); + static void GetNativeImageSignature(PEAssembly * pPEAssembly, WCHAR * pwszSig, unsigned int nSigSize); public: // Initialize the map for the current process. static void Initialize(); // Log a native image load to the map. - static void LogImageLoad(PEFile * pFile); + static void LogImageLoad(PEAssembly * pPEAssembly); // Log a JIT compiled method to the map. static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig); diff --git a/src/coreclr/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/vm/proftoeeinterfaceimpl.cpp index 4df33eb464dcc..c59ecb553d748 100644 --- a/src/coreclr/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/vm/proftoeeinterfaceimpl.cpp @@ -2131,7 +2131,7 @@ HRESULT ProfToEEInterfaceImpl::GetTokenAndMetaDataFromFunction( // Yay! EE_THREAD_NOT_REQUIRED; - // PEFile::GetRWImporter and GetReadablePublicMetaDataInterface take locks + // PEAssembly::GetRWImporter and GetReadablePublicMetaDataInterface take locks CAN_TAKE_LOCK; } @@ -3977,11 +3977,11 @@ DWORD ProfToEEInterfaceImpl::GetModuleFlags(Module * pModule) } CONTRACTL_END; - PEFile * pPEFile = pModule->GetFile(); - if (pPEFile == NULL) + PEAssembly * pPEAssembly = pModule->GetPEAssembly(); + if (pPEAssembly == NULL) { // Hopefully this should never happen; but just in case, don't try to determine the - // flags without a PEFile. + // flags without a PEAssembly. return 0; } @@ -3996,15 +3996,15 @@ DWORD ProfToEEInterfaceImpl::GetModuleFlags(Module * pModule) dwRet |= (COR_PRF_MODULE_DISK | COR_PRF_MODULE_NGEN); } #endif - // Not NGEN or ReadyToRun. - if (pPEFile->HasOpenedILimage()) + // Not Dynamic. + if (pPEAssembly->HasPEImage()) { - PEImage * pILImage = pPEFile->GetOpenedILimage(); + PEImage * pILImage = pPEAssembly->GetPEImage(); if (pILImage->IsFile()) { dwRet |= COR_PRF_MODULE_DISK; } - if (pPEFile->GetLoadedIL()->IsFlat()) + if (pPEAssembly->GetLoadedLayout()->IsFlat()) { dwRet |= COR_PRF_MODULE_FLAT_LAYOUT; } @@ -4020,11 +4020,6 @@ DWORD ProfToEEInterfaceImpl::GetModuleFlags(Module * pModule) dwRet |= COR_PRF_MODULE_COLLECTIBLE; } - if (pModule->IsResource()) - { - dwRet |= COR_PRF_MODULE_RESOURCE; - } - return dwRet; } @@ -4086,7 +4081,7 @@ HRESULT ProfToEEInterfaceImpl::GetModuleInfo2(ModuleID moduleId, EX_TRY { - PEFile * pFile = pModule->GetFile(); + PEAssembly * pFile = pModule->GetPEAssembly(); // Pick some safe defaults to begin with. if (ppBaseLoadAddress != NULL) @@ -4209,7 +4204,7 @@ HRESULT ProfToEEInterfaceImpl::GetModuleMetaData(ModuleID moduleId, // but we might be able to lift that restriction and make this be // EE_THREAD_NOT_REQUIRED. - // PEFile::GetRWImporter & PEFile::GetEmitter & + // PEAssembly::GetRWImporter & PEAssembly::GetEmitter & // GetReadablePublicMetaDataInterface take locks CAN_TAKE_LOCK; @@ -4244,14 +4239,6 @@ HRESULT ProfToEEInterfaceImpl::GetModuleMetaData(ModuleID moduleId, return CORPROF_E_DATAINCOMPLETE; } - // Make sure we can get the importer first - if (pModule->IsResource()) - { - if (ppOut) - *ppOut = NULL; - return S_FALSE; - } - // Decide which type of open mode we are in to see which you require. if ((dwOpenFlags & ofWrite) == 0) { @@ -4299,7 +4286,7 @@ HRESULT ProfToEEInterfaceImpl::GetILFunctionBody(ModuleID moduleId, // Yay! MODE_ANY; - // PEFile::CheckLoaded & Module::GetDynamicIL both take a lock + // Module::GetDynamicIL both take a lock CAN_TAKE_LOCK; } @@ -4337,9 +4324,9 @@ HRESULT ProfToEEInterfaceImpl::GetILFunctionBody(ModuleID moduleId, IMDInternalImport *pImport = pModule->GetMDImport(); _ASSERTE(pImport); - PEFile *pFile = pModule->GetFile(); + PEAssembly *pPEAssembly = pModule->GetPEAssembly(); - if (!pFile->CheckLoaded()) + if (!pPEAssembly->HasLoadedPEImage()) return (CORPROF_E_DATAINCOMPLETE); LPCBYTE pbMethod = NULL; @@ -4354,7 +4341,7 @@ HRESULT ProfToEEInterfaceImpl::GetILFunctionBody(ModuleID moduleId, IfFailRet(pImport->GetMethodImplProps(methodId, &RVA, &dwImplFlags)); // Check to see if the method has associated IL - if ((RVA == 0 && !pFile->IsDynamic()) || !(IsMiIL(dwImplFlags) || IsMiOPTIL(dwImplFlags) || IsMiInternalCall(dwImplFlags))) + if ((RVA == 0 && !pPEAssembly->IsDynamic()) || !(IsMiIL(dwImplFlags) || IsMiOPTIL(dwImplFlags) || IsMiInternalCall(dwImplFlags))) { return (CORPROF_E_FUNCTION_NOT_IL); } @@ -4449,7 +4436,7 @@ HRESULT ProfToEEInterfaceImpl::GetILFunctionBodyAllocator(ModuleID modul Module * pModule = (Module *) moduleId; if (pModule->IsBeingUnloaded() || - !pModule->GetFile()->CheckLoaded()) + !pModule->GetPEAssembly()->HasLoadedPEImage()) { return (CORPROF_E_DATAINCOMPLETE); } @@ -4472,7 +4459,7 @@ HRESULT ProfToEEInterfaceImpl::SetILFunctionBody(ModuleID moduleId, { CONTRACTL { - // PEFile::GetEmitter, Module::SetDynamicIL all throw + // PEAssembly::GetEmitter, Module::SetDynamicIL all throw THROWS; // Locks are taken (see CAN_TAKE_LOCK below), which may cause mode switch to @@ -4482,7 +4469,7 @@ HRESULT ProfToEEInterfaceImpl::SetILFunctionBody(ModuleID moduleId, // Yay! MODE_ANY; - // Module::SetDynamicIL & PEFile::CheckLoaded & PEFile::GetEmitter take locks + // Module::SetDynamicIL & PEAssembly::GetEmitter take locks CAN_TAKE_LOCK; } diff --git a/src/coreclr/vm/readytoruninfo.cpp b/src/coreclr/vm/readytoruninfo.cpp index 4a6052b1ef162..bf77758eeccdf 100644 --- a/src/coreclr/vm/readytoruninfo.cpp +++ b/src/coreclr/vm/readytoruninfo.cpp @@ -392,7 +392,7 @@ BOOL ReadyToRunInfo::IsReadyToRunEnabled() // Any other value: Handle of the log file. static FILE * volatile s_r2rLogFile = (FILE *)(-1); -static void LogR2r(const char *msg, PEFile *pFile) +static void LogR2r(const char *msg, PEAssembly *pPEAssembly) { STANDARD_VM_CONTRACT; @@ -430,7 +430,7 @@ static void LogR2r(const char *msg, PEFile *pFile) if (r2rLogFile == NULL) return; - fprintf(r2rLogFile, "%s: \"%S\".\n", msg, pFile->GetPath().GetUnicode()); + fprintf(r2rLogFile, "%s: \"%S\".\n", msg, pPEAssembly->GetPath().GetUnicode()); fflush(r2rLogFile); } @@ -503,7 +503,7 @@ static NativeImage *AcquireCompositeImage(Module * pModule, PEImageLayout * pLay if (ownerCompositeExecutableName != NULL) { - AssemblyBinder *binder = pModule->GetFile()->GetAssemblyBinder(); + AssemblyBinder *binder = pModule->GetPEAssembly()->GetAssemblyBinder(); return binder->LoadNativeImage(pModule, ownerCompositeExecutableName); } @@ -514,7 +514,7 @@ PTR_ReadyToRunInfo ReadyToRunInfo::Initialize(Module * pModule, AllocMemTracker { STANDARD_VM_CONTRACT; - PEFile * pFile = pModule->GetFile(); + PEAssembly * pFile = pModule->GetPEAssembly(); if (!IsReadyToRunEnabled()) { @@ -529,13 +529,13 @@ PTR_ReadyToRunInfo ReadyToRunInfo::Initialize(Module * pModule, AllocMemTracker return NULL; } - if (!pFile->HasLoadedIL()) + if (!pFile->HasLoadedPEImage()) { - DoLog("Ready to Run disabled - no loaded IL image"); + DoLog("Ready to Run disabled - no loaded PE image"); return NULL; } - PEImageLayout * pLayout = pFile->GetLoadedIL(); + PEImageLayout * pLayout = pFile->GetLoadedLayout(); if (!pLayout->HasReadyToRunHeader()) { DoLog("Ready to Run header not found"); diff --git a/src/coreclr/vm/runtimehandles.cpp b/src/coreclr/vm/runtimehandles.cpp index 620ead8289e4f..5c436a73c9000 100644 --- a/src/coreclr/vm/runtimehandles.cpp +++ b/src/coreclr/vm/runtimehandles.cpp @@ -2728,7 +2728,7 @@ void QCALLTYPE ModuleHandle::GetPEKind(QCall::ModuleHandle pModule, DWORD* pdwPE QCALL_CONTRACT; BEGIN_QCALL; - pModule->GetFile()->GetPEKindAndMachine(pdwPEKind, pdwMachine); + pModule->GetPEAssembly()->GetPEKindAndMachine(pdwPEKind, pdwMachine); END_QCALL; } @@ -2742,10 +2742,6 @@ FCIMPL1(INT32, ModuleHandle::GetMDStreamVersion, ReflectModuleBaseObject * pModu FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle")); Module *pModule = refModule->GetModule(); - - if (pModule->IsResource()) - return 0; - return pModule->GetMDImport()->GetMetadataStreamVersion(); } FCIMPLEND @@ -2787,10 +2783,6 @@ FCIMPL1(INT32, ModuleHandle::GetToken, ReflectModuleBaseObject * pModuleUNSAFE) FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle")); Module *pModule = refModule->GetModule(); - - if (pModule->IsResource()) - return mdModuleNil; - return pModule->GetMDImport()->GetModuleFromScope(); } FCIMPLEND @@ -2805,10 +2797,6 @@ FCIMPL1(IMDInternalImport*, ModuleHandle::GetMetadataImport, ReflectModuleBaseOb FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle")); Module *pModule = refModule->GetModule(); - - if (pModule->IsResource()) - return NULL; - return pModule->GetMDImport(); } FCIMPLEND diff --git a/src/coreclr/vm/siginfo.cpp b/src/coreclr/vm/siginfo.cpp index a3aea61ba7b2b..4c438360513cb 100644 --- a/src/coreclr/vm/siginfo.cpp +++ b/src/coreclr/vm/siginfo.cpp @@ -3547,7 +3547,7 @@ BOOL CompareTypeTokens(mdToken tk1, mdToken tk2, Module *pModule1, Module *pModu #ifdef DACCESS_COMPILE ThrowHR(hr); #else - EEFileLoadException::Throw(pModule2->GetFile(), hr); + EEFileLoadException::Throw(pModule2->GetPEAssembly(), hr); #endif //!DACCESS_COMPILE } // CompareTypeTokens diff --git a/src/coreclr/vm/typeparse.cpp b/src/coreclr/vm/typeparse.cpp index 84ce7124c473c..258b50d86916b 100644 --- a/src/coreclr/vm/typeparse.cpp +++ b/src/coreclr/vm/typeparse.cpp @@ -1415,7 +1415,7 @@ TypeName::GetTypeHaveAssemblyHelper( if (pManifestModule->LookupFile(mdFile)) continue; - pManifestModule->LoadModule(GetAppDomain(), mdFile, FALSE); + pManifestModule->LoadModule(GetAppDomain(), mdFile); th = GetTypeHaveAssemblyHelper(pAssembly, bThrowIfNotFound, bIgnoreCase, NULL, FALSE); @@ -1479,7 +1479,7 @@ DomainAssembly * LoadDomainAssembly( { // If the requesting assembly has Fallback LoadContext binder available, // then set it up in the AssemblySpec. - PEFile *pRequestingAssemblyManifestFile = pRequestingAssembly->GetManifestFile(); + PEAssembly *pRequestingAssemblyManifestFile = pRequestingAssembly->GetManifestFile(); spec.SetFallbackBinderForRequestingAssembly(pRequestingAssemblyManifestFile->GetFallbackBinder()); }