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

PPU Loader: Fix main()'s envp, move process arguments to stack #14461

Merged
merged 1 commit into from Aug 11, 2023

Conversation

elad335
Copy link
Contributor

@elad335 elad335 commented Aug 10, 2023

This originally came from that I knew for a while that R1 of main thread is not accurate to realh unlike in other threads, I did not fix it originally when discovered because I was not sure why R1 changes sometimes.
Today it hitted me that it may because the argv and envp are passed on the stack and their size may differ when using different arguments.
So I tested it on realhw, fixing it by moving argv and envp to stack instead of dynamic memory. Saving a whopping 128KB of RAM as a side effect ;)
But this was not playing nice with envp, after some reversing it turned out we were emulating envp wrong.
Originally, the argv and envp pointer arrays are 64-bit arrays because CELL is natively a 64-bit processor, but games use 32-bit pointers exclusively. So the workaround embedded in all EBOOT.BIN is to convert the 64-bit array into 32-bit array. This functionality needs to know how many arguments are in each array in total. Total amount of envp arguments is passed in the R6 register to the program but we were always initializaing it with 0 so it could not fix the envp array resutling in crashes (because it always pointed to 32-bit nullptr) when dereferencing it!

Hwtest: elad335/myps3tests@173d346

Fixes #13014 as it turns out :)

@elad335 elad335 added Bugfix Amazing Contribution Only awarded to the most outstanding performances labels Aug 10, 2023
@MastaG
Copy link

MastaG commented Aug 10, 2023

Awesome work there!

@capriots
Copy link
Contributor

Fixes #13014

@elad335 elad335 merged commit eae1c5a into RPCS3:master Aug 11, 2023
5 checks passed
@elad335 elad335 added the Loader Involving the load of PS3 file formats label Aug 11, 2023
@elad335 elad335 deleted the envp branch May 6, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Amazing Contribution Only awarded to the most outstanding performances Bugfix Loader Involving the load of PS3 file formats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tekken 5 Dark Resurrection Online (NPUB30009) - Game crashes when network status set to "Connected"
3 participants