fix(relinker): hand the guest the real argv on Linux #418
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/418"
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 oneandonlydean on 2026-10-02T22:34:52Z.
What
The Linux entry stub handed the guest's
_startthe wrong argv. The guest expects a pointer to its entry parameter block,{int argc; pad; const char* argv[]}, with the argv pointers inline after argc. The stub popped argc, built a copy of that block on the stack and stored a pointer to the host argv array in it, so the guest read that pointer asargv[0]and uninitialised stack asargv[1..]: it saw a garbageargv[0]and none of the real arguments.At process entry the kernel leaves rsp at argc (a qword whose high half is zero), followed by the argv pointers and a null. That is already the guest's layout, so the stub now passes rsp itself in rdi, aligns the stack and calls the entry as before. The constants of the removed instructions are dropped.
Titles that parse their own command line now see the extra arguments; for example PPSA21564 accepts
-lvl <level file>to boot straight into a level.The Windows entry stub already builds the block this way (checked by @QDarkRex below), so only the Linux one changes.
Tested
BUILD_TESTING=ONandctestpass.linux_entry_argv(test_linux_entry_argv.py): relinks a fixture whose entry checksargc == 2,argv[0] != NULL,argv[1] == "Z"andargv[2] == NULL, then runs the output on Linux x86-64 withZ(expects the entry'sint3) and withZ extra(expects itsud2). On other hosts it only checks the relink, like the Windows tests that run their output only on Windows. Against main's relinker the first run ends in SIGILL instead of SIGTRAP (the guest sees the wrong argv), so the test fails without the fix.-lvlreaches the requested level.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)Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-03T04:31:06Z.
I checked the Windows side you mentioned: its entry stub already builds the block the way this PR now does on Linux. It writes argc as a qword, then the UTF-8 argv pointers inline after it, with a null after the last one (from
CommandLineToArgvW+WideCharToMultiByteinto a zeroedVirtualAllocblock), and passes that block in rdi. I ran yourARGV_CHECKfixture throughrelinker --windowson main (313de1c) and ran the exe on Windows 11:Zhits theint3, whileZ extra, no argument,YandZzall hit theud2. So-lvlshould already reach the guest on Windows without a change there.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T06:28:34Z.
Thanks for checking the Windows stub and running the fixture on Windows 11. I'll update the description to say the Windows stub already builds the block this way, so only the Linux one needed the fix.