Skip to content

Commit 93c0532

Browse files
Call FlushInstructionCache in CFG test
Should address #82307 (comment).
1 parent 1b2eb12 commit 93c0532

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGuard.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ static IntPtr CreateNewMethod()
174174
if (s_armed)
175175
flProtect |= 0x40000000 /* TARGETS_INVALID */;
176176

177+
uint allocSize = 4096;
178+
177179
IntPtr address = VirtualAlloc(
178180
lpAddress: IntPtr.Zero,
179-
dwSize: 4096,
181+
dwSize: allocSize,
180182
flAllocationType: 0x00001000 | 0x00002000 /* COMMIT+RESERVE*/,
181183
flProtect: flProtect);
182184

@@ -196,6 +198,15 @@ static IntPtr CreateNewMethod()
196198
throw new NotSupportedException();
197199
}
198200

201+
[DllImport("kernel32", ExactSpelling = true)]
202+
static extern IntPtr GetCurrentProcess();
203+
204+
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
205+
static extern int FlushInstructionCache(IntPtr hProcess, IntPtr lpBaseAddress, nuint dwSize);
206+
207+
if (FlushInstructionCache(GetCurrentProcess(), address, allocSize) == 0)
208+
Console.WriteLine("FlushInstructionCache failed");
209+
199210
return address;
200211
}
201212
}

0 commit comments

Comments
 (0)