diff --git a/docs/debugging.md b/docs/debugging.md
index 6f001666..fb44f3a0 100644
--- a/docs/debugging.md
+++ b/docs/debugging.md
@@ -144,7 +144,7 @@ every thread blocked a second or more in one of those waits: the handle, the tim
kind or semaphore counts, creating thread and time, the game frames of the creating call) and whether it was signaled
since, how often and by which thread last (`WaitObjects`), and the game frames of the waiting call. A handle the shims did
not see made is named when it is a thread's (a join). Frames come from a scan of the thread's stack for return addresses
-into the game (`ReturnAddresses`): a walk stops in the shims' generated code, and #13's first report named no creator. A stall whose waiter sits on an object nobody signals any
+into the game (`ReturnAddresses`; only values whose call bytes sit in committed readable code, so never in an execute-only section): a walk stops in the shims' generated code, and #13's first report named no creator. A stall whose waiter sits on an object nobody signals any
more (a lost wake-up) then names that object and its creator. For each thread in the game's fence wait (0x144fb0ad0) it also names what the wait depends on
(`StallCulprit`): the queue that was asked to signal that fence to the awaited value and the last six executions it
was given before that Signal, newest first, each with its last pipeline and whether it finished, and any Wait on another
diff --git a/src/FiveStar.Loader/Diagnostics/GameHangWatch.cs b/src/FiveStar.Loader/Diagnostics/GameHangWatch.cs
index 8bead4ca..6b7f3a99 100644
--- a/src/FiveStar.Loader/Diagnostics/GameHangWatch.cs
+++ b/src/FiveStar.Loader/Diagnostics/GameHangWatch.cs
@@ -198,8 +198,11 @@ private static string Describe()
return $"main state {(short)state} (next {(short)next}), loading screen {loading}, loading render callback {loadingRender}, session 0x{session:x} ready {ready}, watchdog paused {paused}, handler 0x{handler:x}";
}
- /// Whether is committed and accessible in this process.
- internal static bool IsReadable(ulong address)
+ ///
+ /// Whether is committed and accessible in this process; with ,
+ /// also whether its page has one of them.
+ ///
+ internal static bool IsReadable(ulong address, uint protections = 0)
{
MemoryBasicInformation info;
@@ -210,6 +213,8 @@ internal static bool IsReadable(ulong address)
bool blocked = (info.Protect & (Win32Constants.PageNoAccess | Win32Constants.PageGuard)) != 0;
- return info.State == Win32Constants.MemCommit && !blocked;
+ bool allowed = protections == 0 || (info.Protect & protections) != 0;
+
+ return info.State == Win32Constants.MemCommit && !blocked && allowed;
}
}
diff --git a/src/FiveStar.Loader/Diagnostics/ReturnAddresses.cs b/src/FiveStar.Loader/Diagnostics/ReturnAddresses.cs
index 2c6ae248..ee5b07ff 100644
--- a/src/FiveStar.Loader/Diagnostics/ReturnAddresses.cs
+++ b/src/FiveStar.Loader/Diagnostics/ReturnAddresses.cs
@@ -32,6 +32,12 @@ internal static unsafe class ReturnAddresses
private const byte Displacement8 = 0x50;
private const byte Displacement32 = 0x90;
+ ///
+ /// Pages whose bytes can be read as code. PAGE_EXECUTE alone is not one: the loader maps execute-only sections, and
+ /// a read there faults like an uncommitted page.
+ ///
+ private const uint ReadableCode = Win32Constants.PageExecuteRead | Win32Constants.PageExecuteReadWrite | Win32Constants.PageExecuteWriteCopy;
+
/// Up to return addresses into mapped images above the caller, innermost first.
public static nint[] Scan(ImageTable images, int count)
{
@@ -59,8 +65,9 @@ public static nint[] Scan(ImageTable images, int count)
}
///
- /// Whether the 6 bytes before are committed: an image's range has pages that are not (a section
- /// window unmapped, a discarded section), and a read there killed a boot inside a wait.
+ /// Whether the 6 bytes before are committed readable code (): an
+ /// image's range has pages that are not (a section window unmapped, a discarded section, an execute-only section), and
+ /// a read there killed a boot inside a wait.
///
internal static bool CallBytesReadable(nint value)
{
@@ -69,7 +76,7 @@ internal static bool CallBytesReadable(nint value)
ulong page = (ulong)Environment.SystemPageSize;
bool samePage = first / page == last / page;
- return GameHangWatch.IsReadable(first) && (samePage || GameHangWatch.IsReadable(last));
+ return GameHangWatch.IsReadable(first, ReadableCode) && (samePage || GameHangWatch.IsReadable(last, ReadableCode));
}
/// Whether the bytes before end a call instruction (6 readable bytes before it).
diff --git a/src/FiveStar.Loader/Native/Win32Constants.cs b/src/FiveStar.Loader/Native/Win32Constants.cs
index 3607eed3..5281e53f 100644
--- a/src/FiveStar.Loader/Native/Win32Constants.cs
+++ b/src/FiveStar.Loader/Native/Win32Constants.cs
@@ -20,6 +20,7 @@ internal static class Win32Constants
public const uint PageExecute = 0x10;
public const uint PageExecuteRead = 0x20;
public const uint PageExecuteReadWrite = 0x40;
+ public const uint PageExecuteWriteCopy = 0x80;
public const uint PageGuard = 0x100;
/// The x64 page size (winnt.h PAGE_SIZE on AMD64).
diff --git a/tests/FiveStar.Loader.Tests/WaitObjectsTests.cs b/tests/FiveStar.Loader.Tests/WaitObjectsTests.cs
index a946ed41..f605d636 100644
--- a/tests/FiveStar.Loader.Tests/WaitObjectsTests.cs
+++ b/tests/FiveStar.Loader.Tests/WaitObjectsTests.cs
@@ -78,9 +78,13 @@ public void A_wait_on_a_thread_handle_names_the_thread_it_joins()
}
}
- /// A stack value inside an image's range is only read when the call bytes before it are committed.
- [Fact]
- public void A_value_after_an_uncommitted_page_is_not_read()
+ /// A stack value inside an image's range is only read when the call bytes before it are committed readable code.
+ [Theory]
+ [InlineData(Win32Constants.PageExecuteRead, true)]
+ [InlineData(Win32Constants.PageExecuteReadWrite, true)]
+ [InlineData(Win32Constants.PageExecute, false)]
+ [InlineData(Win32Constants.PageReadWrite, false)]
+ public void A_value_after_a_page_that_is_not_readable_code_is_not_read(uint protection, bool read)
{
int page = Environment.SystemPageSize;
nint region = Kernel32.VirtualAlloc(0, (nuint)(page * 2), Win32Constants.MemReserve, Win32Constants.PageReadWrite);
@@ -88,11 +92,11 @@ public void A_value_after_an_uncommitted_page_is_not_read()
try
{
- Assert.NotEqual(0, Kernel32.VirtualAlloc(region + page, (nuint)page, Win32Constants.MemCommit, Win32Constants.PageReadWrite));
+ Assert.NotEqual(0, Kernel32.VirtualAlloc(region + page, (nuint)page, Win32Constants.MemCommit, protection));
Assert.False(ReturnAddresses.CallBytesReadable(region + 16));
Assert.False(ReturnAddresses.CallBytesReadable(region + page + 2));
- Assert.True(ReturnAddresses.CallBytesReadable(region + page + 16));
+ Assert.Equal(read, ReturnAddresses.CallBytesReadable(region + page + 16));
}
finally
{