Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant the code to LdrpHandleTlsData be stuffed into __declspec(naked) instead with the asm to the function in the c++ code itself? #515

Open
AraHaan opened this issue Jul 30, 2024 · 0 comments

Comments

@AraHaan
Copy link

AraHaan commented Jul 30, 2024

After looking at the code and trying to understand it for monkey patching it into the C MemoryModule code I got to thinking about this:

  • Using __declspec(naked) for the 32-Bit version of the code for when _WIN32 is defined AND _WIN64 is not defined (probably could also trap ARM64 version of Windows perhaps as well if it is not similar to _WIN64's asm code).
  • Using __declspec(naked) for the 64-Bit version of the code for when _WIN64 is defined.

Why is this better?
Unlike patterns which could break code because they are fragile and require the debugging symbols for windows to find the updated version of this function's asm code, why not just embed the asm code for a known working version that is windows version gated, Also bonus if this same code could be invoked from C and with that able to be copy-pasted into the C MemoryModule for use in py2exe to add back in support for loading the Python Core dll in Python 3.12+ (3.12, 3.13, 3.14, ...).

Why do I need this?
Because the Python Core Developers decided it was a good idea to migrate a few things to __declspec(thread) with no other workaround but have proper TLS support and this means implementing a version of LdrpHandleTlsData safely without relying on possibly calling into arbitrary code in ntdll.dll that might not be the actual function anymore on each Windows update since the found signature from here. One can only get lucky a certain amount of times.

Links:
py2exe/py2exe#191
bb107/MemoryModulePP#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant