diff --git a/src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGuard.cs b/src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGuard.cs index 91575d469bc364..5e9189ac90a572 100644 --- a/src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGuard.cs +++ b/src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGuard.cs @@ -174,9 +174,11 @@ static IntPtr CreateNewMethod() if (s_armed) flProtect |= 0x40000000 /* TARGETS_INVALID */; + uint allocSize = 4096; + IntPtr address = VirtualAlloc( lpAddress: IntPtr.Zero, - dwSize: 4096, + dwSize: allocSize, flAllocationType: 0x00001000 | 0x00002000 /* COMMIT+RESERVE*/, flProtect: flProtect); @@ -196,6 +198,15 @@ static IntPtr CreateNewMethod() throw new NotSupportedException(); } + [DllImport("kernel32", ExactSpelling = true)] + static extern IntPtr GetCurrentProcess(); + + [DllImport("kernel32", ExactSpelling = true, SetLastError = true)] + static extern int FlushInstructionCache(IntPtr hProcess, IntPtr lpBaseAddress, nuint dwSize); + + if (FlushInstructionCache(GetCurrentProcess(), address, allocSize) == 0) + Console.WriteLine("FlushInstructionCache failed"); + return address; } }