tests: kernel_file_system hangs on macOS since db7035c3 — WaitUntilSleeping reads /proc/self/task #2487

Open
opened 2026-11-26 10:21:16 +00:00 by github-bot · 0 comments
Owner

@⁠Fr0gzilla on GitHub · 2026-11-21 13:20 UTC · original

Summary

Since db7035c3 ("kernel: drop the pending-signal poll between wait slices", 2026-11-21), kernel_file_system fails on macOS before reaching any of the checks covered by #1770:

KernelFileSystemTests: failed: mutex waiter made progress

WaitUntilSleeping() (tests/KernelFileSystemTests.cpp) decides that a guest thread is blocked by reading /proc/self/task/<tid>/stat. That file only exists on Linux. On macOS the read always fails, the predicate never becomes true, and WaitForMutexTest gives up after 5 s. Windows has no /proc either, so it is probably affected too (I can't test it). CI doesn't run this test, which would explain why nobody saw it.

Environment

  • KytyPS5 source build at 39936ff (main, 2026-11-21), Release, x86_64 under Rosetta 2
  • macOS 26.6 (25G72), Apple M5
  • Apple clang 21.0.0 (Command Line Tools), SDK 26.5

Possible fix (macOS only, Linux path unchanged)

On macOS, PthreadGetHostThreadId() returns the pthread_threadid_np id. The test can find that thread with task_threads() + THREAD_IDENTIFIER_INFO and read its state with THREAD_BASIC_INFO: a thread blocked in a wait reports TH_STATE_WAITING, which matches the S state the Linux path looks for.

With this change alone, the test gets past the mutex hand-off section and stops at the PTHREAD_CANCELED check that #1770 fixes. With this change + #1770 + #2269 (so a Vulkan device is accepted on MoltenVK), I get KernelFileSystemTests: all cases passed in 5 out of 5 runs.

Diff (against 39936ff)
diff --git a/tests/KernelFileSystemTests.cpp b/tests/KernelFileSystemTests.cpp
index e99ebb84..5de0658d 100644
--- a/tests/KernelFileSystemTests.cpp
+++ b/tests/KernelFileSystemTests.cpp
@@ -50,6 +50,10 @@
 #include <unistd.h>
 #endif
 
+#if defined(__APPLE__)
+#include <mach/mach.h>
+#endif
+
 namespace Libs::LibKernelApr {
 void InitLibKernel_1_Apr(Loader::SymbolDatabase *symbols);
 }
@@ -124,8 +128,42 @@ SignalExports ResolveSignalExports() {
           reinterpret_cast<decltype(SignalExports::raise)>(find("il03nluKfMk"))};
 }
 
+#if defined(__APPLE__)
+// Reports whether the host thread with this pthread_threadid_np id is blocked.
+bool IsHostThreadWaiting(uint64_t thread_id) {
+  thread_act_array_t threads = nullptr;
+  mach_msg_type_number_t count = 0;
+  if (task_threads(mach_task_self(), &threads, &count) != KERN_SUCCESS) {
+    return false;
+  }
+  bool waiting = false;
+  for (mach_msg_type_number_t i = 0; i < count; ++i) {
+    thread_identifier_info_data_t identifier{};
+    mach_msg_type_number_t identifier_count = THREAD_IDENTIFIER_INFO_COUNT;
+    thread_basic_info_data_t basic{};
+    mach_msg_type_number_t basic_count = THREAD_BASIC_INFO_COUNT;
+    if (thread_info(threads[i], THREAD_IDENTIFIER_INFO,
+                    reinterpret_cast<thread_info_t>(&identifier),
+                    &identifier_count) == KERN_SUCCESS &&
+        identifier.thread_id == thread_id &&
+        thread_info(threads[i], THREAD_BASIC_INFO, reinterpret_cast<thread_info_t>(&basic),
+                    &basic_count) == KERN_SUCCESS) {
+      waiting = basic.run_state == TH_STATE_WAITING;
+    }
+    mach_port_deallocate(mach_task_self(), threads[i]);
+  }
+  vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(threads),
+                count * sizeof(thread_act_t));
+  return waiting;
+}
+#endif
+
 // Waits until a guest thread's host thread sleeps in a blocking call.
 void WaitUntilSleeping(Libs::LibKernel::Pthread thread) {
+#if defined(__APPLE__)
+  const auto thread_id = Libs::LibKernel::PthreadGetHostThreadId(thread);
+  WaitForMutexTest([&] { return IsHostThreadWaiting(thread_id); });
+#else
   const auto path = "/proc/self/task/" +
                     std::to_string(Libs::LibKernel::PthreadGetHostThreadId(thread)) + "/stat";
   WaitForMutexTest([&] {
@@ -135,6 +173,7 @@ void WaitUntilSleeping(Libs::LibKernel::Pthread thread) {
     const auto state = line.rfind(") ");
     return state != std::string::npos && line[state + 2] == 'S';
   });
+#endif
 }
 
 void TestStaticRwlockDestroy() {

I can open a PR with this if you want it.

AI disclosure: I used an AI assistant to investigate the failure and write the patch. I reviewed the change and ran the tests myself on my Mac.

**@⁠Fr0gzilla** on GitHub · 2026-11-21 13:20 UTC · [original](https://github.com/KytyPS5/KytyPS5/issues/2487) ## Summary Since db7035c3 ("kernel: drop the pending-signal poll between wait slices", 2026-11-21), `kernel_file_system` fails on macOS before reaching any of the checks covered by #1770: ``` KernelFileSystemTests: failed: mutex waiter made progress ``` `WaitUntilSleeping()` (tests/KernelFileSystemTests.cpp) decides that a guest thread is blocked by reading `/proc/self/task/<tid>/stat`. That file only exists on Linux. On macOS the read always fails, the predicate never becomes true, and `WaitForMutexTest` gives up after 5 s. Windows has no `/proc` either, so it is probably affected too (I can't test it). CI doesn't run this test, which would explain why nobody saw it. ## Environment - KytyPS5 source build at 39936ff (main, 2026-11-21), Release, x86_64 under Rosetta 2 - macOS 26.6 (25G72), Apple M5 - Apple clang 21.0.0 (Command Line Tools), SDK 26.5 ## Possible fix (macOS only, Linux path unchanged) On macOS, `PthreadGetHostThreadId()` returns the `pthread_threadid_np` id. The test can find that thread with `task_threads()` + `THREAD_IDENTIFIER_INFO` and read its state with `THREAD_BASIC_INFO`: a thread blocked in a wait reports `TH_STATE_WAITING`, which matches the `S` state the Linux path looks for. With this change alone, the test gets past the mutex hand-off section and stops at the `PTHREAD_CANCELED` check that #1770 fixes. With this change + #1770 + #2269 (so a Vulkan device is accepted on MoltenVK), I get `KernelFileSystemTests: all cases passed` in 5 out of 5 runs. <details> <summary>Diff (against 39936ff)</summary> ```diff diff --git a/tests/KernelFileSystemTests.cpp b/tests/KernelFileSystemTests.cpp index e99ebb84..5de0658d 100644 --- a/tests/KernelFileSystemTests.cpp +++ b/tests/KernelFileSystemTests.cpp @@ -50,6 +50,10 @@ #include <unistd.h> #endif +#if defined(__APPLE__) +#include <mach/mach.h> +#endif + namespace Libs::LibKernelApr { void InitLibKernel_1_Apr(Loader::SymbolDatabase *symbols); } @@ -124,8 +128,42 @@ SignalExports ResolveSignalExports() { reinterpret_cast<decltype(SignalExports::raise)>(find("il03nluKfMk"))}; } +#if defined(__APPLE__) +// Reports whether the host thread with this pthread_threadid_np id is blocked. +bool IsHostThreadWaiting(uint64_t thread_id) { + thread_act_array_t threads = nullptr; + mach_msg_type_number_t count = 0; + if (task_threads(mach_task_self(), &threads, &count) != KERN_SUCCESS) { + return false; + } + bool waiting = false; + for (mach_msg_type_number_t i = 0; i < count; ++i) { + thread_identifier_info_data_t identifier{}; + mach_msg_type_number_t identifier_count = THREAD_IDENTIFIER_INFO_COUNT; + thread_basic_info_data_t basic{}; + mach_msg_type_number_t basic_count = THREAD_BASIC_INFO_COUNT; + if (thread_info(threads[i], THREAD_IDENTIFIER_INFO, + reinterpret_cast<thread_info_t>(&identifier), + &identifier_count) == KERN_SUCCESS && + identifier.thread_id == thread_id && + thread_info(threads[i], THREAD_BASIC_INFO, reinterpret_cast<thread_info_t>(&basic), + &basic_count) == KERN_SUCCESS) { + waiting = basic.run_state == TH_STATE_WAITING; + } + mach_port_deallocate(mach_task_self(), threads[i]); + } + vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(threads), + count * sizeof(thread_act_t)); + return waiting; +} +#endif + // Waits until a guest thread's host thread sleeps in a blocking call. void WaitUntilSleeping(Libs::LibKernel::Pthread thread) { +#if defined(__APPLE__) + const auto thread_id = Libs::LibKernel::PthreadGetHostThreadId(thread); + WaitForMutexTest([&] { return IsHostThreadWaiting(thread_id); }); +#else const auto path = "/proc/self/task/" + std::to_string(Libs::LibKernel::PthreadGetHostThreadId(thread)) + "/stat"; WaitForMutexTest([&] { @@ -135,6 +173,7 @@ void WaitUntilSleeping(Libs::LibKernel::Pthread thread) { const auto state = line.rfind(") "); return state != std::string::npos && line[state + 2] == 'S'; }); +#endif } void TestStaticRwlockDestroy() { ``` </details> I can open a PR with this if you want it. AI disclosure: I used an AI assistant to investigate the failure and write the patch. I reviewed the change and ran the tests myself on my Mac.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:21:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/KytyPS5--KytyPS5#2487
No description provided.