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

Đang mở
#194 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, macos
Lĩnh vực
backend, mobile-dev

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C
Star
90
Fork
34
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của libretro/parallel-ps2

Tất cả issue của libretro/parallel-ps2

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.