Apple silicon: loading a save state crashes with SIGBUS in state_read (write to a read-only page)

オープン
#194 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cpp, macos

調査の方向性

Start by reading libretro-common/faulthandler/faulthandler.c, cpu_thread_entry, state_read, and VMManager::Internal::ClearCPUExecutionCaches(); the report identifies these paths but does not name tests. Reproduce on Apple silicon by saving and loading a state after the game has run, then trace which protected page SaveState_FreezeMem writes. Done means state loading no longer crashes with SIGBUS on the frontend thread.

索引モデルが issue の本文から書いたものです。

説明

Loading a save state on Apple silicon crashes the whole process with SIGBUS once the game has been running. It happens in RetroArch and in a personal libretro frontend of mine, with the same stack inside the core.

Setup
  • MacBook Pro, M1 Pro, macOS 27.2
  • Core: buildbot apple/osx/arm64 nightly dated 2026-11-03, reports v2.0.0-da5b07e
  • RetroArch 1.22.2, video_driver = "metal", run-ahead off
  • pcsx2_renderer = "Software (SW)", pcsx2_sw_renderer_threads = "4" (the only renderer I tested)
  • Kingdom Hearts (USA), SLUS-20370, as an ISO; BIOS USA v01.60
Steps
  1. Start the game and let it run for about 45 seconds.
  2. Save a state. I sent SAVE_STATE through RetroArch's network commands.
  3. A few seconds later, load it with LOAD_STATE.
Result

The process dies on the frontend's main thread:

EXC_BAD_ACCESS (SIGBUS) KERN_PROTECTION_FAILURE at 0x0000000138234000
Data Abort: byte write Permission fault

0  libsystem_platform.dylib  _platform_memmove + 88
1  pcsx2_libretro.dylib      state_read(void const*, unsigned long, bool) + 1300
2  pcsx2_libretro.dylib      retro_unserialize + 388
3  RetroArch                 content_deserialize_state + 540
4  RetroArch                 content_load_state_cb + 388

I got the same top three frames in my own frontend, also at a write to a read-only page, with the frontend calling retro_unserialize on its emulation thread. In that frontend's report the faulting page is one 16 KB page marked r--/rw- inside a shared memory region, between rw- pages, which looks like a page the recompiler protected.

What I think is happening (from reading the source, not from a debugger)

fault_filter in libretro-common/faulthandler/faulthandler.c only services threads registered with the fault handler, and chains to the old handler otherwise. In normal play, the only registration I could find is FaultThreadScope in cpu_thread_entry. retro_unserialize runs on the frontend's thread, so if state_read writes to a write-protected page there, nothing rescues it. I don't know why VMManager::Internal::ClearCPUExecutionCaches() hasn't already made the page writable at that point, and I haven't confirmed which SaveState_FreezeMem call is the one faulting.

What works
  • Closing the core, opening it again, running one retro_run, then calling retro_unserialize. This loaded the same state repeatedly with no crash in my frontend, and it's what I'm using as a workaround.
  • In RetroArch, RESET survived all four times I tried it: after about 45, 60, 75 and 90 seconds, the 60-second one after a SAVE_STATE.
Possibly related

retro_reset crashed once in my frontend, with the same kind of write fault, on a call made right after a retro_serialize with no retro_run in between:

0  libsystem_platform.dylib  __bzero + 64
1  pcsx2_libretro.dylib      sys_memory_reset + 80
2  pcsx2_libretro.dylib      cpuReset() + 20
3  pcsx2_libretro.dylib      VMManager::Reset() + 244
4  pcsx2_libretro.dylib      retro_reset + 132

I only saw this once and couldn't reproduce it in RetroArch, so treat it as a lead. #69 also describes state loads crashing RetroArch, but it's closed and I haven't compared the two.

Thanks for the arm64 port: apart from this, the game runs at full speed on this Mac.

This report was prepared with an AI assistant (Claude Code), which ran the tests above. The stacks are from real macOS crash reports. Happy to test a build or send a full crash report.

主要言語
C
スター
90
フォーク
34
平均マージ
1日 17時間
マージ済み PR(30日)
9

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

libretro/parallel-ps2 のほかの issue

libretro/parallel-ps2 の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。