[PR #685] [MERGED] core: Fix CPU patch stack issues #1711

Closed
opened 2026-02-27 21:13:39 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/685
Author: @squidbus
Created: 8/31/2024
Status: Merged
Merged: 8/31/2024
Merged by: @georgemoralis

Base: mainHead: patch-fixes


📝 Commits (1)

  • 61db246 core: Fix CPU patch stack issues

📊 Changes

4 files changed (+14 additions, -25 deletions)

View changed files

📝 CMakeLists.txt (+1 -1)
📝 src/core/cpu_patches.cpp (+11 -19)
📝 src/core/libraries/kernel/thread_management.cpp (+1 -2)
📝 src/core/linker.cpp (+1 -3)

📄 Description

Ran some games with address sanitizer enabled and fixed some issues that game out of final refactoring of the CPU patches updates. Note that only macOS patches use this currently.

  • Properly place patch stack pointer at the end of the buffer instead of the start.
  • Use pthread_key_create destructor parameter for freeing patch stacks instead of a separate cleanup function that needs to be manually called.
  • Fix mistake in restoring context when skipping a normal destination register, where the wrong offset would be added to the stack pointer. In practice the only place full context save/restore is used so far is with vector destination registers, so this code was not called.
  • Move patch stack initialization a bit further up as a precaution.
  • Misc: increase the emulator code base address on macOS to get it out of the way of allocating user memory lower in the address space, since the size increased from 1 << 39 to 1 << 40 since this was initially defined.

Did not get any address sanitizer errors after applying these changes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/685 **Author:** [@squidbus](https://github.com/squidbus) **Created:** 8/31/2024 **Status:** ✅ Merged **Merged:** 8/31/2024 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `patch-fixes` --- ### 📝 Commits (1) - [`61db246`](https://github.com/shadps4-emu/shadPS4/commit/61db246c5ec86aa63215a13ad915f42da1f98426) core: Fix CPU patch stack issues ### 📊 Changes **4 files changed** (+14 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+1 -1) 📝 `src/core/cpu_patches.cpp` (+11 -19) 📝 `src/core/libraries/kernel/thread_management.cpp` (+1 -2) 📝 `src/core/linker.cpp` (+1 -3) </details> ### 📄 Description Ran some games with address sanitizer enabled and fixed some issues that game out of final refactoring of the CPU patches updates. Note that only macOS patches use this currently. * Properly place patch stack pointer at the end of the buffer instead of the start. * Use `pthread_key_create` destructor parameter for freeing patch stacks instead of a separate cleanup function that needs to be manually called. * Fix mistake in restoring context when skipping a normal destination register, where the wrong offset would be added to the stack pointer. In practice the only place full context save/restore is used so far is with vector destination registers, so this code was not called. * Move patch stack initialization a bit further up as a precaution. * Misc: increase the emulator code base address on macOS to get it out of the way of allocating user memory lower in the address space, since the size increased from `1 << 39` to `1 << 40` since this was initially defined. Did not get any address sanitizer errors after applying these changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:13:39 +03:00
Sign in to join this conversation.
No milestone
No project
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
starred/shadPS4#1711
No description provided.