diff options
Diffstat (limited to 'src/vm/peimagelayout.h')
-rw-r--r-- | src/vm/peimagelayout.h | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/src/vm/peimagelayout.h b/src/vm/peimagelayout.h new file mode 100644 index 0000000000..68d6315be4 --- /dev/null +++ b/src/vm/peimagelayout.h @@ -0,0 +1,196 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// -------------------------------------------------------------------------------- +// PEImageLayout.h +// + +// -------------------------------------------------------------------------------- + + +#ifndef PEIMAGELAYOUT_H_ +#define PEIMAGELAYOUT_H_ + +// -------------------------------------------------------------------------------- +// Required headers +// -------------------------------------------------------------------------------- + +#include "clrtypes.h" +#include "pedecoder.h" +#include "holder.h" + +// -------------------------------------------------------------------------------- +// Forward declarations +// -------------------------------------------------------------------------------- + +class Crst; +class PEImage; + + +typedef VPTR(class PEImageLayout) PTR_PEImageLayout; + +class PEImageLayout : public PEDecoder +{ + VPTR_BASE_CONCRETE_VTABLE_CLASS(PEImageLayout) + friend class PEModule; +#ifdef FEATURE_INCLUDE_ALL_INTERFACES + friend class CCLRDebugManager; +#endif // FEATURE_INCLUDE_ALL_INTERFACES +public: + // ------------------------------------------------------------ + // Public constants + // ------------------------------------------------------------ + enum + { + LAYOUT_MAPPED =1, + LAYOUT_FLAT =2, + LAYOUT_LOADED =4, + LAYOUT_LOADED_FOR_INTROSPECTION =8, + LAYOUT_ANY =0xf + }; + + +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); +#endif + PEImageLayout(); + virtual ~PEImageLayout(); + static void Startup(); + static CHECK CheckStartup(); + static BOOL CompareBase(UPTR path, UPTR mapping); + + // Refcount above images. + void AddRef(); + ULONG Release(); + const SString& GetPath(); + +#ifdef FEATURE_PREJIT + void ApplyBaseRelocations(); +#endif + +public: +#ifdef DACCESS_COMPILE + void EnumMemoryRegions(CLRDataEnumMemoryFlags flags); +#endif + +#if defined(_WIN64) && !defined(DACCESS_COMPILE) + bool ConvertILOnlyPE32ToPE64(); +private: + bool ConvertILOnlyPE32ToPE64Worker(); +#endif // defined(_WIN64) && !defined(DACCESS_COMPILE) + +private: + Volatile<LONG> m_refCount; +public: + PEImage* m_pOwner; + DWORD m_Layout; +}; + +typedef ReleaseHolder<PEImageLayout> PEImageLayoutHolder; + + +//RawImageView is built on external data, does not need cleanup +class RawImageLayout: public PEImageLayout +{ + VPTR_VTABLE_CLASS(RawImageLayout,PEImageLayout) +protected: + CLRMapViewHolder m_DataCopy; +#ifndef FEATURE_PAL + HModuleHolder m_LibraryHolder; +#endif // !FEATURE_PAL + +public: + RawImageLayout(const void *flat, COUNT_T size,PEImage* pOwner); + RawImageLayout(const void *mapped, PEImage* pOwner, BOOL bTakeOwnerShip, BOOL bFixedUp); +}; + +// ConvertedImageView is for the case when we manually layout a flat image +class ConvertedImageLayout: public PEImageLayout +{ + VPTR_VTABLE_CLASS(ConvertedImageLayout,PEImageLayout) +protected: + HandleHolder m_FileMap; + CLRMapViewHolder m_FileView; +public: +#ifndef DACCESS_COMPILE + ConvertedImageLayout(PEImageLayout* source); +#endif +}; + +class MappedImageLayout: public PEImageLayout +{ + VPTR_VTABLE_CLASS(MappedImageLayout,PEImageLayout) + VPTR_UNIQUE(0x15) +protected: + HandleHolder m_FileMap; + CLRMapViewHolder m_FileView; +public: +#ifndef DACCESS_COMPILE + MappedImageLayout(HANDLE hFile, PEImage* pOwner); +#endif +}; + +#if !defined(CROSSGEN_COMPILE) && !defined(FEATURE_PAL) +class LoadedImageLayout: public PEImageLayout +{ + VPTR_VTABLE_CLASS(LoadedImageLayout,PEImageLayout) +protected: + HINSTANCE m_Module; +public: +#ifndef DACCESS_COMPILE + LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError); + ~LoadedImageLayout() + { + CONTRACTL + { + NOTHROW; + GC_TRIGGERS; + MODE_ANY; + } + CONTRACTL_END; + if (m_Module) + CLRFreeLibrary(m_Module); + } +#endif // !DACCESS_COMPILE +}; +#endif // !CROSSGEN_COMPILE && !FEATURE_PAL + +class FlatImageLayout: public PEImageLayout +{ + VPTR_VTABLE_CLASS(FlatImageLayout,PEImageLayout) + VPTR_UNIQUE(0x59) +protected: + HandleHolder m_FileMap; + CLRMapViewHolder m_FileView; +public: +#ifndef DACCESS_COMPILE + FlatImageLayout(HANDLE hFile, PEImage* pOwner); +#endif + +}; + +#ifdef FEATURE_FUSION +class StreamImageLayout: public PEImageLayout +{ + VPTR_VTABLE_CLASS(StreamImageLayout,PEImageLayout) + VPTR_UNIQUE(0x71) +protected: + HandleHolder m_FileMap; + CLRMapViewHolder m_FileView; +public: +#ifndef DACCESS_COMPILE + StreamImageLayout(IStream* pIStream,PEImage* pOwner); +#endif +}; +#endif // FEATURE_FUSION + + +#endif // PEIMAGELAYOUT_H_ + |