Repository navigation
fix(relinker): hand the guest the real argv on Linux - #418
Conversation
The Linux entry stub built a copy of the entry parameter block holding argc and a pointer to the host argv array, so the guest read that pointer as argv[0] and uninitialised stack as argv[1..]. The process stack at entry already has the guest's layout (argc as a qword, then the argv pointers and a null), so pass rsp itself. Test: linux_entry_argv relinks a fixture whose entry checks argc and argv and runs the output on Linux x86-64.
f736d9f to
d8b8aaf
Compare
|
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 |
|
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. |
…heir PR heads The code of the three open PRs is unchanged on their heads apart from the opt-outs and comments astrobot keeps. Their heads add tests: boykopovar#415's EvaluatedValues table test (and drops an unused include), boykopovar#417's flip test releases its GPU work without an interrupt select, and boykopovar#418's linux_entry_argv relinks a fixture whose entry checks argc and argv.
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)