mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-31 06:59:45 +08:00
revert: restore state before huge regression
This commit is contained in:
@@ -24,53 +24,13 @@ public sealed unsafe class GuestImageWriteTrackerTests
|
||||
// spilling onto neighbouring heap pages.
|
||||
private const nuint TrackedByteCount = 4096;
|
||||
private const nuint HostPageAlignment = 16384;
|
||||
private const uint MemCommit = 0x1000;
|
||||
private const uint MemReserve = 0x2000;
|
||||
private const uint MemRelease = 0x8000;
|
||||
private const uint PageReadWrite = 0x04;
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern nint VirtualAlloc(
|
||||
nint lpAddress,
|
||||
nuint dwSize,
|
||||
uint flAllocationType,
|
||||
uint flProtect);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern int VirtualFree(nint lpAddress, nuint dwSize, uint dwFreeType);
|
||||
|
||||
private static ulong AllocateTrackedPages(out void* allocation)
|
||||
{
|
||||
// VirtualProtect (Windows) / mprotect (POSIX) must target
|
||||
// VirtualAlloc/mmap pages. Protecting CRT heap pages poisons
|
||||
// neighbouring allocator metadata and crashes the test host.
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
var windowsAllocation = VirtualAlloc(
|
||||
0,
|
||||
HostPageAlignment,
|
||||
MemCommit | MemReserve,
|
||||
PageReadWrite);
|
||||
Assert.NotEqual(nint.Zero, windowsAllocation);
|
||||
allocation = (void*)windowsAllocation;
|
||||
return (ulong)windowsAllocation;
|
||||
}
|
||||
|
||||
allocation = NativeMemory.AlignedAlloc(2 * HostPageAlignment, HostPageAlignment);
|
||||
return (ulong)allocation;
|
||||
}
|
||||
|
||||
private static void FreeTrackedPages(void* allocation)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_ = VirtualFree((nint)allocation, 0, MemRelease);
|
||||
return;
|
||||
}
|
||||
|
||||
NativeMemory.Free(allocation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerationSurvivesDirtyConsume()
|
||||
{
|
||||
@@ -98,7 +58,7 @@ public sealed unsafe class GuestImageWriteTrackerTests
|
||||
finally
|
||||
{
|
||||
GuestImageWriteTracker.Untrack(address);
|
||||
FreeTrackedPages(allocation);
|
||||
NativeMemory.Free(allocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +89,7 @@ public sealed unsafe class GuestImageWriteTrackerTests
|
||||
finally
|
||||
{
|
||||
GuestImageWriteTracker.Untrack(address);
|
||||
FreeTrackedPages(allocation);
|
||||
NativeMemory.Free(allocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +118,7 @@ public sealed unsafe class GuestImageWriteTrackerTests
|
||||
finally
|
||||
{
|
||||
GuestImageWriteTracker.Untrack(address);
|
||||
FreeTrackedPages(allocation);
|
||||
NativeMemory.Free(allocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user