feat(libc): record traced import calls on Windows #4546
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4546"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by codingreapermaps on 2026-10-12T15:22:23Z.
What
Adds the runtime half of an opt-in call trace on Windows. It covers part of #3815: the entry of a call, not its arguments or its result.
TraceImport_nid_no_patch(target, name, library)returnstargetunchanged unlesslibraryis named inAPS5_TRACE_CALLS(a comma-separated list, orall). For a selected library it returns a thunk that records the import, the thread and the caller's address in a ring of the last 65536 calls, counts the call, and jumps to the function. The thunk saves the integer argument registers andxmm0toxmm7, so stack arguments, varargs and struct returns pass through. One target keeps one thunk, so function pointers compare equal.The crash and abort reports end with the last 64 calls and the 32 most called imports:
Nothing calls
TraceImport_nid_no_patchin this PR, so no title is affected. The relinker option that binds imports through it is a separate PR that depends on this one. Limits (Windows only, entry only, one process-wide ring, wider vector registers untested) are indocs/dev/debt/libc.md.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), on main
43e3a70f8.guest_call_trace(new): integer, floating-point, mixed, variadic and struct-return calls through a thunk return the same result as the direct call; the ring holds the calls in order with the right thread, names and a caller address inside the test image; 4 threads of 20000 calls leave the last 65536 calls with consecutive sequence numbers; the counters match.rax,r9orxmm3before the jump.guest_call_trace_abort(new): the abort report lists the two traced calls.windows_backtrace_reportstill passes.tools/check_conventions.pyandtools/check_test_registration.pypass.With the relinker option from the follow-up PR, DOOM Shareware (PPSA99666, lowbit/ps5-doom v1.1.1, Intel i7-1165G7, before the rebase onto current main) ran with every library traced to the same point as untraced: 901,307,599 calls recorded, normal process exit. Not built on Linux or macOS; the source file is compiled only on Windows.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:19:08Z.
Reviewed the thunk (register save/restore, 16-byte stack alignment, return address read at the right offset, stack arguments and
raxfor varargs preserved) and the ring/count logic; no findings. The only conflict withmainwas adocs/dev/debt/libc.mdadjacency, so I rebased and moved the debt line a few lines up. The Windows-only code and its tests are verified by the full Build run before merging; rebasing and merging.