Remove unnecessary file handle parameter in PEImageLayout methods (dotnet/coreclr...
authorVitek Karas <vitek.karas@microsoft.com>
Fri, 6 Sep 2019 10:59:09 +0000 (03:59 -0700)
committerGitHub <noreply@github.com>
Fri, 6 Sep 2019 10:59:09 +0000 (03:59 -0700)
The handle is always the owner's PEImage->GetFileHandle, and so the PEImageLayout can call that instead of passing it around through parameters.

Commit migrated from https://github.com/dotnet/coreclr/commit/af62a24b0452392a461a4402ffad0c6320f41d9d

src/coreclr/src/vm/peimage.cpp
src/coreclr/src/vm/peimagelayout.cpp
src/coreclr/src/vm/peimagelayout.h

index b530561..528df82 100644 (file)
@@ -1077,7 +1077,7 @@ PTR_PEImageLayout PEImage::CreateLayoutMapped()
     }
     else if (IsFile())
     {
-        PEImageLayoutHolder pLayout(PEImageLayout::Map(GetFileHandle(),this));
+        PEImageLayoutHolder pLayout(PEImageLayout::Map(this));
 
         bool fMarkAnyCpuImageAsLoaded = false;
         // Avoid mapping another image if we can. We can only do this for IL-ONLY images
@@ -1131,7 +1131,7 @@ PTR_PEImageLayout PEImage::CreateLayoutFlat(BOOL bPermitWriteableSections)
 
     _ASSERTE(m_pLayouts[IMAGE_FLAT] == NULL);
 
-    PTR_PEImageLayout pFlatLayout = PEImageLayout::LoadFlat(GetFileHandle(),this);
+    PTR_PEImageLayout pFlatLayout = PEImageLayout::LoadFlat(this);
 
     if (!bPermitWriteableSections
         && pFlatLayout->CheckNTHeaders()
@@ -1321,7 +1321,7 @@ void PEImage::LoadNoMetaData()
     else
     {
         _ASSERTE(!m_path.IsEmpty());
-        SetLayout(IMAGE_LOADED,PEImageLayout::LoadFlat(GetFileHandle(),this));
+        SetLayout(IMAGE_LOADED,PEImageLayout::LoadFlat(this));
     }
 }
 
index 3ceae66..78fc62c 100644 (file)
@@ -45,7 +45,7 @@ PEImageLayout* PEImageLayout::Load(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThro
     STANDARD_VM_CONTRACT;
 
 #if defined(CROSSGEN_COMPILE) || defined(FEATURE_PAL)
-    return PEImageLayout::Map(pOwner->GetFileHandle(), pOwner);
+    return PEImageLayout::Map(pOwner);
 #else
     PEImageLayoutHolder pAlloc(new LoadedImageLayout(pOwner,bNTSafeLoad,bThrowOnError));
     if (pAlloc->GetBase()==NULL)
@@ -54,13 +54,13 @@ PEImageLayout* PEImageLayout::Load(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThro
 #endif
 }
 
-PEImageLayout* PEImageLayout::LoadFlat(HANDLE hFile,PEImage* pOwner)
+PEImageLayout* PEImageLayout::LoadFlat(PEImage* pOwner)
 {
     STANDARD_VM_CONTRACT;
-    return new FlatImageLayout(hFile,pOwner);
+    return new FlatImageLayout(pOwner);
 }
 
-PEImageLayout* PEImageLayout::Map(HANDLE hFile, PEImage* pOwner)
+PEImageLayout* PEImageLayout::Map(PEImage* pOwner)
 {
     CONTRACT(PEImageLayout*)
     {
@@ -73,11 +73,11 @@ PEImageLayout* PEImageLayout::Map(HANDLE hFile, PEImage* pOwner)
     }
     CONTRACT_END;
 
-    PEImageLayoutHolder pAlloc(new MappedImageLayout(hFile,pOwner));
+    PEImageLayoutHolder pAlloc(new MappedImageLayout(pOwner));
     if (pAlloc->GetBase()==NULL)
     {
         //cross-platform or a bad image
-        PEImageLayoutHolder pFlat(new FlatImageLayout(hFile, pOwner));
+        PEImageLayoutHolder pFlat(new FlatImageLayout(pOwner));
         if (!pFlat->CheckFormat())
             ThrowHR(COR_E_BADIMAGEFORMAT);
 
@@ -410,7 +410,7 @@ ConvertedImageLayout::ConvertedImageLayout(PEImageLayout* source)
 #endif
 }
 
-MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner)
+MappedImageLayout::MappedImageLayout(PEImage* pOwner)
 {
     CONTRACTL
     {
@@ -421,6 +421,8 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner)
     m_Layout=LAYOUT_MAPPED;
     m_pOwner=pOwner;
 
+    HANDLE hFile = pOwner->GetFileHandle();
+
     // If mapping was requested, try to do SEC_IMAGE mapping
     LOG((LF_LOADER, LL_INFO100, "PEImage: Opening OS mapped %S (hFile %p)\n", (LPCWSTR) GetPath(), hFile));
 
@@ -591,7 +593,7 @@ LoadedImageLayout::LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bTh
 }
 #endif // !CROSSGEN_COMPILE && !FEATURE_PAL
 
-FlatImageLayout::FlatImageLayout(HANDLE hFile, PEImage* pOwner)
+FlatImageLayout::FlatImageLayout(PEImage* pOwner)
 {
     CONTRACTL
     {
@@ -602,6 +604,9 @@ FlatImageLayout::FlatImageLayout(HANDLE hFile, PEImage* pOwner)
     CONTRACTL_END;
     m_Layout=LAYOUT_FLAT;
     m_pOwner=pOwner;
+
+    HANDLE hFile = pOwner->GetFileHandle();
+
     LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %S\n", (LPCWSTR) GetPath()));
 
     COUNT_T size = SafeGetFileSize(hFile, NULL);
index 17254bc..72c0cb7 100644 (file)
@@ -50,12 +50,11 @@ public:
 public:
 #ifndef DACCESS_COMPILE
     static PEImageLayout* CreateFlat(const void *flat, COUNT_T size,PEImage* pOwner);
-    static PEImageLayout* CreateFromStream(IStream* pIStream, PEImage* pOwner);
     static PEImageLayout* CreateFromHMODULE(HMODULE mappedbase,PEImage* pOwner, BOOL bTakeOwnership);
     static PEImageLayout* LoadFromFlat(PEImageLayout* pflatimage);
     static PEImageLayout* Load(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError = TRUE);
-    static PEImageLayout* LoadFlat(HANDLE hFile, PEImage* pOwner);
-    static PEImageLayout* Map (HANDLE hFile, PEImage* pOwner);
+    static PEImageLayout* LoadFlat(PEImage* pOwner);
+    static PEImageLayout* Map(PEImage* pOwner);
 #endif    
     PEImageLayout();
     virtual ~PEImageLayout();
@@ -126,7 +125,7 @@ protected:
 #endif
 public:
 #ifndef DACCESS_COMPILE    
-    MappedImageLayout(HANDLE hFile, PEImage* pOwner);    
+    MappedImageLayout(PEImage* pOwner);    
 #endif
 };
 
@@ -164,7 +163,7 @@ protected:
     CLRMapViewHolder m_FileView;
 public:
 #ifndef DACCESS_COMPILE    
-    FlatImageLayout(HANDLE hFile, PEImage* pOwner);   
+    FlatImageLayout(PEImage* pOwner);   
 #endif
 
 };