summaryrefslogtreecommitdiff
path: root/src/vm
diff options
context:
space:
mode:
authorKonstantin Baladurin <k.baladurin@partner.samsung.com>2018-03-30 10:18:04 +0300
committerRuss Keldorph <russ.keldorph@microsoft.com>2018-03-30 20:07:26 -0700
commit4a2a446bce2035ea477de234fb24c37e7f134616 (patch)
tree73c295568fb3b98b670c0455cb25c261a452cd84 /src/vm
parent2023be14efa54af8b339d36499018a8743b32a29 (diff)
downloadcoreclr-4a2a446bce2035ea477de234fb24c37e7f134616.tar.gz
coreclr-4a2a446bce2035ea477de234fb24c37e7f134616.tar.bz2
coreclr-4a2a446bce2035ea477de234fb24c37e7f134616.zip
PEImageLayout: clear instruction cache after relocations
It fixes crashes on arm when using AOT images.
Diffstat (limited to 'src/vm')
-rw-r--r--src/vm/peimagelayout.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp
index 0a84892421..a3514e5a06 100644
--- a/src/vm/peimagelayout.cpp
+++ b/src/vm/peimagelayout.cpp
@@ -149,6 +149,8 @@ void PEImageLayout::ApplyBaseRelocations()
SIZE_T cbWriteableRegion = 0;
DWORD dwOldProtection = 0;
+ BOOL bRelocDone = FALSE;
+
COUNT_T dirPos = 0;
while (dirPos < dirSize)
{
@@ -175,10 +177,20 @@ void PEImageLayout::ApplyBaseRelocations()
// 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 (bRelocDone && bExecRegion)
+ {
+ ClrFlushInstructionCache(pWriteableRegion, cbWriteableRegion);
+ }
+
+ bRelocDone = FALSE;
+
dwOldProtection = 0;
}
@@ -221,11 +233,13 @@ void PEImageLayout::ApplyBaseRelocations()
{
case IMAGE_REL_BASED_PTR:
*(TADDR *)address += delta;
+ bRelocDone = TRUE;
break;
#ifdef _TARGET_ARM_
case IMAGE_REL_BASED_THUMB_MOV32:
PutThumb2Mov32((UINT16 *)address, GetThumb2Mov32((UINT16 *)address) + delta);
+ bRelocDone = TRUE;
break;
#endif
@@ -245,10 +259,18 @@ void PEImageLayout::ApplyBaseRelocations()
#ifndef CROSSGEN_COMPILE
if (dwOldProtection != 0)
{
+ 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 (bRelocDone && bExecRegion)
+ {
+ ClrFlushInstructionCache(pWriteableRegion, cbWriteableRegion);
+ }
}
#endif // CROSSGEN_COMPILE
}