SIZE_T cbWriteableRegion = 0;
DWORD dwOldProtection = 0;
+ BOOL bRelocDone = FALSE;
+
COUNT_T dirPos = 0;
while (dirPos < dirSize)
{
// 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;
}
{
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
#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
}