@@ -149,6 +149,8 @@ void PEImageLayout::ApplyBaseRelocations()
149
149
SIZE_T cbWriteableRegion = 0 ;
150
150
DWORD dwOldProtection = 0 ;
151
151
152
+ BOOL bRelocDone = FALSE ;
153
+
152
154
COUNT_T dirPos = 0 ;
153
155
while (dirPos < dirSize)
154
156
{
@@ -175,10 +177,20 @@ void PEImageLayout::ApplyBaseRelocations()
175
177
// Restore the protection
176
178
if (dwOldProtection != 0 )
177
179
{
180
+ BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ |
181
+ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0 ;
182
+
178
183
if (!ClrVirtualProtect (pWriteableRegion, cbWriteableRegion,
179
184
dwOldProtection, &dwOldProtection))
180
185
ThrowLastError ();
181
186
187
+ if (bRelocDone && bExecRegion)
188
+ {
189
+ ClrFlushInstructionCache (pWriteableRegion, cbWriteableRegion);
190
+ }
191
+
192
+ bRelocDone = FALSE ;
193
+
182
194
dwOldProtection = 0 ;
183
195
}
184
196
@@ -221,11 +233,13 @@ void PEImageLayout::ApplyBaseRelocations()
221
233
{
222
234
case IMAGE_REL_BASED_PTR:
223
235
*(TADDR *)address += delta;
236
+ bRelocDone = TRUE ;
224
237
break ;
225
238
226
239
#ifdef _TARGET_ARM_
227
240
case IMAGE_REL_BASED_THUMB_MOV32:
228
241
PutThumb2Mov32 ((UINT16 *)address, GetThumb2Mov32 ((UINT16 *)address) + delta);
242
+ bRelocDone = TRUE ;
229
243
break ;
230
244
#endif
231
245
@@ -245,10 +259,18 @@ void PEImageLayout::ApplyBaseRelocations()
245
259
#ifndef CROSSGEN_COMPILE
246
260
if (dwOldProtection != 0 )
247
261
{
262
+ BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ |
263
+ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0 ;
264
+
248
265
// Restore the protection
249
266
if (!ClrVirtualProtect (pWriteableRegion, cbWriteableRegion,
250
267
dwOldProtection, &dwOldProtection))
251
268
ThrowLastError ();
269
+
270
+ if (bRelocDone && bExecRegion)
271
+ {
272
+ ClrFlushInstructionCache (pWriteableRegion, cbWriteableRegion);
273
+ }
252
274
}
253
275
#endif // CROSSGEN_COMPILE
254
276
}
0 commit comments