fix(loader): preserve preferred module base across exact-alloc failure - #815
Open
semirkabir wants to merge 1 commit into
Open
semirkabir wants to merge 1 commit into
semirkabir wants to merge 1 commit into
Conversation
TryAllocateAdditionalImageAtExact only writes its out-param on success, so passing imageBase as `out` clobbered the preferred base to 0 on the failure path. The fallback then called AllocateAt(0, ...), which skips its fixed-address attempt entirely (the desiredAddress != 0 branch) and allocates anywhere - putting additional modules (libc.prx, etc.) in host memory instead of the guest window. The diagnostic also reported 'preferred base 0x0000000000000000', hiding the base that was actually requested. Preserve the requested base and use it for both the fallback (so the guest-window placement is retried before giving up) and the log line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a loader bug that sends additional modules (libc.prx, libSceNpCppWebApi.prx, etc.) to host memory instead of the guest window — and lies about it in the log.
The bug
SelfLoader.LoadCorecalls:TryAllocateAdditionalImageAtExactonly writes itsout allocatedBaseon success; the failure path doesallocatedBase = 0; return false;. Because the caller passesimageBaseitself as theoutargument, a failed exact-placement attempt clobbers the preferred base to 0.Two consequences:
AllocateAt(imageBase /* = 0 */, ...), andAllocateAtdeliberately skips its fixed-address attempt whendesiredAddress == 0(theif (desiredAddress != 0)guard inPhysicalVirtualMemory.AllocateAt) — so it goes straight to "any address", landing the module in host memory. The original code clearly intendedAllocateAt(imageBase)to retry the preferred base first (that's what thedesiredAddress != 0branch is for); the clobber silently disabled that intent.Could not allocate module at preferred base 0x0000000000000000— butDetermineRequestedImageBasecannot return 0 for Gen5 (it returnsPs5MainImageBaseor a search-range candidate ≥Ps5ModuleSearchStart=0x804000000). The 0x0 in the log is purely the clobber artifact, hiding the base that was actually requested and making real failures much harder to diagnose.The fix
Preserve the requested base in a local before the call, pass a separate variable as the
outargument, and use the preserved base for both the fallback allocation (so guest-window placement is retried before giving up) and the log line.Verification
dotnet build SharpEmu.slnx -c Release→ clean, 0 errors.dotnet test SharpEmu.slnx -c Release --no-build→ 891 passed, 0 failed.DetermineRequestedImageBaseprovably cannot return 0 for Gen5, so thepreferred base 0x0log lines seen in the wild (e.g. EA UFC 5 compatibility reportsSharpEmuLog-PPSA03541-*, where libc.prx loaded at0x2781CBF0000host memory) are the clobber artifact this PR removes.Testing
N/A — no game testing; the change affects the module-placement fallback path and its diagnostic only. On hosts where exact placement succeeds (the normal case), behavior is unchanged — the
outparam is written and the newelsebranch simply adopts it, identical to before.Checklist
CONTRIBUTING.md.N/A.N/A).