summaryrefslogtreecommitdiff
path: root/src/vm
diff options
context:
space:
mode:
authorKonstantin Baladurin <k.baladurin@samsung.com>2019-07-05 19:36:28 +0300
committer이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 <leee.lee@samsung.com>2019-10-15 06:54:39 +0900
commit5647236eac21fb0e01a55a12289a66bc9f874f19 (patch)
treef81eede622d29edc955cf9fe3d5dcb670ec95675 /src/vm
parentc4c19b84a37bbc750e2cc13570dd096b13abfff0 (diff)
downloadcoreclr-accepted/tizen/5.5/unified/mobile/hotfix/20201027.061818.tar.gz
coreclr-accepted/tizen/5.5/unified/mobile/hotfix/20201027.061818.tar.bz2
coreclr-accepted/tizen/5.5/unified/mobile/hotfix/20201027.061818.zip
Diffstat (limited to 'src/vm')
-rw-r--r--src/vm/corhost.cpp41
-rw-r--r--src/vm/peimagelayout.cpp102
-rw-r--r--src/vm/peimagelayout.h2
3 files changed, 99 insertions, 46 deletions
diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp
index be91820e6c..96ade5ca08 100644
--- a/src/vm/corhost.cpp
+++ b/src/vm/corhost.cpp
@@ -368,6 +368,47 @@ void SetCommandLineArgs(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR* argv)
GCPROTECT_END();
}
+/*
+ * This method allows to preload assembly to memory and apply relocations before initialization of CoreCLR.
+ * Assemblies are stored in the list, which is scanned during general loading after CoreCLR initialization.
+ * If path is found in the list, preloaded memory is used.
+ * If CoreCLR is already initialized, it returns E_FAIL.
+ */
+HRESULT CorHost2::PreloadAssembly(LPCSTR szPath)
+{
+#ifndef FEATURE_PAL
+ // Preloading is not available without FEATURE_PAL, as it requires some PAL changes
+ return E_FAIL;
+#else
+ if (g_fEEStarted)
+ {
+ return HOST_E_INVALIDOPERATION;
+ }
+
+ void *preloadedImage = PAL_LOADPreloadPEFile(szPath);
+ if (preloadedImage == NULL)
+ {
+ return E_FAIL;
+ }
+
+ return S_OK;
+#endif
+}
+
+HRESULT CorHost2::UnloadPreloadedAssemblies()
+{
+#ifndef FEATURE_PAL
+ // Preloading is not available without FEATURE_PAL, as it requires some PAL changes
+ return E_FAIL;
+#else
+ if (!PAL_LOADUnloadPreloadedPEFiles())
+ {
+ return E_FAIL;
+ }
+ return S_OK;
+#endif
+}
+
HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId,
LPCWSTR pwzAssemblyPath,
int argc,
diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp
index 906e443af7..1d08558c70 100644
--- a/src/vm/peimagelayout.cpp
+++ b/src/vm/peimagelayout.cpp
@@ -124,7 +124,9 @@ DWORD SectionCharacteristicsToPageProtection(UINT characteristics)
//To force base relocation on Vista (which uses ASLR), unmask IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
//(0x40) for OptionalHeader.DllCharacteristics
-void PEImageLayout::ApplyBaseRelocations()
+//
+//NOTE: MAPApplyBaseRelocationsPreloadedPEFile should match this function exactly!
+void PEImageLayout::ApplyBaseRelocations(BOOL isRelocated)
{
STANDARD_VM_CONTRACT;
@@ -177,48 +179,51 @@ void PEImageLayout::ApplyBaseRelocations()
BYTE * pageAddress = (BYTE *)GetBase() + rva;
- // Check whether the page is outside the unprotected region
- if ((SIZE_T)(pageAddress - pWriteableRegion) >= cbWriteableRegion)
+ if (!isRelocated)
{
- // Restore the protection
- if (dwOldProtection != 0)
+ // Check whether the page is outside the unprotected region
+ if ((SIZE_T)(pageAddress - pWriteableRegion) >= cbWriteableRegion)
{
- BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ |
- PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0;
+ // Restore the protection
+ if (dwOldProtection != 0)
+ {
+ BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ |
+ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0;
- if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion,
- dwOldProtection, &dwOldProtection))
- ThrowLastError();
+ if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion,
+ dwOldProtection, &dwOldProtection))
+ ThrowLastError();
- dwOldProtection = 0;
- }
+ dwOldProtection = 0;
+ }
- USHORT fixup = VAL16(fixups[0]);
+ USHORT fixup = VAL16(fixups[0]);
- IMAGE_SECTION_HEADER *pSection = RvaToSection(rva + (fixup & 0xfff));
- PREFIX_ASSUME(pSection != NULL);
+ IMAGE_SECTION_HEADER *pSection = RvaToSection(rva + (fixup & 0xfff));
+ PREFIX_ASSUME(pSection != NULL);
- pWriteableRegion = (BYTE*)GetRvaData(VAL32(pSection->VirtualAddress));
- cbWriteableRegion = VAL32(pSection->SizeOfRawData);
+ pWriteableRegion = (BYTE*)GetRvaData(VAL32(pSection->VirtualAddress));
+ cbWriteableRegion = VAL32(pSection->SizeOfRawData);
- // Unprotect the section if it is not writable
- if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_WRITE)) == 0))
- {
- DWORD dwNewProtection = PAGE_READWRITE;
-#if defined(FEATURE_PAL) && !defined(CROSSGEN_COMPILE)
- if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_EXECUTE)) != 0))
+ // Unprotect the section if it is not writable
+ if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_WRITE)) == 0))
{
- // On SELinux, we cannot change protection that doesn't have execute access rights
- // to one that has it, so we need to set the protection to RWX instead of RW
- dwNewProtection = PAGE_EXECUTE_READWRITE;
- }
+ DWORD dwNewProtection = PAGE_READWRITE;
+#if defined(FEATURE_PAL) && !defined(CROSSGEN_COMPILE)
+ if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_EXECUTE)) != 0))
+ {
+ // On SELinux, we cannot change protection that doesn't have execute access rights
+ // to one that has it, so we need to set the protection to RWX instead of RW
+ dwNewProtection = PAGE_EXECUTE_READWRITE;
+ }
#endif // FEATURE_PAL && !CROSSGEN_COMPILE
- if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion,
- dwNewProtection, &dwOldProtection))
- ThrowLastError();
+ if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion,
+ dwNewProtection, &dwOldProtection))
+ ThrowLastError();
#ifdef FEATURE_PAL
- dwOldProtection = SectionCharacteristicsToPageProtection(pSection->Characteristics);
+ dwOldProtection = SectionCharacteristicsToPageProtection(pSection->Characteristics);
#endif // FEATURE_PAL
+ }
}
}
@@ -232,13 +237,19 @@ void PEImageLayout::ApplyBaseRelocations()
switch (fixup>>12)
{
case IMAGE_REL_BASED_PTR:
- *(TADDR *)address += delta;
+ if (!isRelocated)
+ {
+ *(TADDR *)address += delta;
+ }
pEndAddressToFlush = max(pEndAddressToFlush, address + sizeof(TADDR));
break;
#ifdef _TARGET_ARM_
case IMAGE_REL_BASED_THUMB_MOV32:
- PutThumb2Mov32((UINT16 *)address, GetThumb2Mov32((UINT16 *)address) + (INT32)delta);
+ if (!isRelocated)
+ {
+ PutThumb2Mov32((UINT16 *)address, GetThumb2Mov32((UINT16 *)address) + (INT32)delta);
+ }
pEndAddressToFlush = max(pEndAddressToFlush, address + 8);
break;
#endif
@@ -275,15 +286,15 @@ void PEImageLayout::ApplyBaseRelocations()
_ASSERTE(dirSize == dirPos);
#ifndef CROSSGEN_COMPILE
- if (dwOldProtection != 0)
+ if (!isRelocated)
{
- BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ |
- PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0;
-
- // Restore the protection
- if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion,
- dwOldProtection, &dwOldProtection))
- ThrowLastError();
+ if (dwOldProtection != 0)
+ {
+ // Restore the protection
+ if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion,
+ dwOldProtection, &dwOldProtection))
+ ThrowLastError();
+ }
}
#endif // CROSSGEN_COMPILE
@@ -403,7 +414,7 @@ ConvertedImageLayout::ConvertedImageLayout(PEImageLayout* source)
#ifdef CROSSGEN_COMPILE
if (HasNativeHeader())
- ApplyBaseRelocations();
+ ApplyBaseRelocations(FALSE);
#endif
}
@@ -487,7 +498,7 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner)
if (!IsNativeMachineFormat())
ThrowHR(COR_E_BADIMAGEFORMAT);
- ApplyBaseRelocations();
+ ApplyBaseRelocations(FALSE);
}
}
else
@@ -518,7 +529,8 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner)
#else //!FEATURE_PAL
#ifndef CROSSGEN_COMPILE
- m_LoadedFile = PAL_LOADLoadPEFile(hFile);
+ BOOL isPreloaded;
+ m_LoadedFile = PAL_LOADLoadPEFile(hFile, (LPCWSTR) GetPath(), &isPreloaded);
if (m_LoadedFile == NULL)
{
@@ -543,7 +555,7 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner)
if (!IsNativeMachineFormat())
ThrowHR(COR_E_BADIMAGEFORMAT);
- ApplyBaseRelocations();
+ ApplyBaseRelocations(isPreloaded);
SetRelocated();
}
diff --git a/src/vm/peimagelayout.h b/src/vm/peimagelayout.h
index 17254bcb72..4e358b37e1 100644
--- a/src/vm/peimagelayout.h
+++ b/src/vm/peimagelayout.h
@@ -68,7 +68,7 @@ public:
ULONG Release();
const SString& GetPath();
- void ApplyBaseRelocations();
+ void ApplyBaseRelocations(BOOL isRelocated);
public:
#ifdef DACCESS_COMPILE