[PR #4048] [MERGED] threads: initialize TLS on thread creation #3896

Closed
opened 2026-02-27 22:05:22 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/4048
Author: @roamic
Created: 2/18/2026
Status: Merged
Merged: 2/19/2026
Merged by: @roamic

Base: mainHead: init-thread-on-create


📝 Commits (4)

  • 781e44d initialize TLS on thread creation
  • f8fb5bc initializa tls in dimensions toypad writer thread
  • 05e870a clear stack on thread init
  • 5677f1e clear most of the stack with some black magic

📊 Changes

12 files changed (+52 additions, -51 deletions)

View changed files

📝 src/core/libraries/avplayer/avplayer_impl.cpp (+8 -8)
📝 src/core/libraries/avplayer/avplayer_state.cpp (+1 -1)
📝 src/core/libraries/ime/ime.cpp (+4 -4)
📝 src/core/libraries/ime/ime_dialog_ui.cpp (+2 -3)
📝 src/core/libraries/kernel/threads/pthread.cpp (+21 -1)
📝 src/core/libraries/kernel/threads/pthread_spec.cpp (+1 -1)
📝 src/core/libraries/network/net_ctl_obj.cpp (+2 -2)
📝 src/core/libraries/ngs2/ngs2.cpp (+2 -2)
📝 src/core/libraries/usbd/emulated/dimensions.cpp (+4 -0)
📝 src/core/linker.cpp (+5 -5)
📝 src/core/module.cpp (+2 -1)
📝 src/core/tls.h (+0 -23)

📄 Description

I'm not sure why this was like this before, but I assume the code in ExecuteGuest just initialized the TLS once per thread. I think this can be done on thread start instead of delaying it to the first guest call. This removes the need for stack cleanup hack.

I've tested this with Catherine and GR2

Let me know if this breaks something or has a potential to.


🔄 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/4048 **Author:** [@roamic](https://github.com/roamic) **Created:** 2/18/2026 **Status:** ✅ Merged **Merged:** 2/19/2026 **Merged by:** [@roamic](https://github.com/roamic) **Base:** `main` ← **Head:** `init-thread-on-create` --- ### 📝 Commits (4) - [`781e44d`](https://github.com/shadps4-emu/shadPS4/commit/781e44de34a988e656cc420780000efafb45c084) initialize TLS on thread creation - [`f8fb5bc`](https://github.com/shadps4-emu/shadPS4/commit/f8fb5bc9898d84018cddfe65657c7bc350dfde3f) initializa tls in dimensions toypad writer thread - [`05e870a`](https://github.com/shadps4-emu/shadPS4/commit/05e870a84e56251baffcb118a85f8dfb2a1cba39) clear stack on thread init - [`5677f1e`](https://github.com/shadps4-emu/shadPS4/commit/5677f1ef9d7f0cbab98b9d7bb2c29fe57a62062e) clear most of the stack with some black magic ### 📊 Changes **12 files changed** (+52 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `src/core/libraries/avplayer/avplayer_impl.cpp` (+8 -8) 📝 `src/core/libraries/avplayer/avplayer_state.cpp` (+1 -1) 📝 `src/core/libraries/ime/ime.cpp` (+4 -4) 📝 `src/core/libraries/ime/ime_dialog_ui.cpp` (+2 -3) 📝 `src/core/libraries/kernel/threads/pthread.cpp` (+21 -1) 📝 `src/core/libraries/kernel/threads/pthread_spec.cpp` (+1 -1) 📝 `src/core/libraries/network/net_ctl_obj.cpp` (+2 -2) 📝 `src/core/libraries/ngs2/ngs2.cpp` (+2 -2) 📝 `src/core/libraries/usbd/emulated/dimensions.cpp` (+4 -0) 📝 `src/core/linker.cpp` (+5 -5) 📝 `src/core/module.cpp` (+2 -1) 📝 `src/core/tls.h` (+0 -23) </details> ### 📄 Description I'm not sure why this was like this before, but I assume the code in `ExecuteGuest` just initialized the TLS once per thread. I think this can be done on thread start instead of delaying it to the first guest call. This removes the need for stack cleanup hack. I've tested this with Catherine and GR2 Let me know if this breaks something or has a potential to. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:05:22 +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#3896
No description provided.