Skip to content

Core: Fix module load addresses - #2879

Merged
squidbus merged 6 commits into
shadps4-emu:mainfrom
StevenMiller123:fix-module-mappings
May 5, 2025
Merged

Core: Fix module load addresses#2879
squidbus merged 6 commits into
shadps4-emu:mainfrom
StevenMiller123:fix-module-mappings

Conversation

@StevenMiller123

Copy link
Copy Markdown
Collaborator

On a PS4, all modules are mapped starting at address 0x800000000, and with no gaps in-between. Since all platforms are able to map to these addresses, we can hard code this address as a constant and use that as the "base" address we map to.

The information this PR is based on comes from observations visible in this klog:
Memory Map Query klog.txt

These changes fix [Debug] <Critical> memory.cpp:331 operator(): Assertion Failed! when booting some Call of Duty games.
Specifically from my testing, this fixes updated versions of Call of Duty®: Advanced Warfare (CUSA00803) crashing on startup (note that these titles still need to be loaded from default.elf to bypass sceSystemServiceLoadExec)
CoD AW main log.txt
CoD AW PR log.txt

Screenshot from 2025-05-03 20-29-05

This doesn't appear to regress any games on my end, wouldn't hurt to have testers though.

Stephen Miller added 5 commits May 3, 2025 20:08
Most modules are mapped starting at 0x800000000, with no gaps between mappings.
Looking at our address space, all platforms will have this base address mapped, so there shouldn't be any problem in using it.
Since real hardware has no gap between module mappings, the Fixed flag is just an annoyance to work around, and has no impact on the actual mappings.
Swapping the module mappings to use flags NoFlags instead simplifies our code slightly.
On real hardware, the file extension is part of the mapping name. Easiest way to manage this is to swap the name to be `file.filename().string()` instead of `file.stem().string()`
@Missake212

Copy link
Copy Markdown
Contributor

No regressions on my end.

Comment thread src/core/module.cpp
@Xcedf

Xcedf commented May 4, 2025

Copy link
Copy Markdown

Battlefield 4 same error, but unfortunately still not affected
shad_log.log

Completely missed this, whoops.
@StevenMiller123
StevenMiller123 marked this pull request as draft May 4, 2025 18:07
@StevenMiller123

Copy link
Copy Markdown
Collaborator Author

As a note for future reference, this PR still isn't fully accurate.
Specifically (according to red-prig), modules loaded by games (through sceKernelLoadStartModule) should be loaded at a base address of 0x80000000.
Additionally, the executable sections of the game's eboot.bin should be mapped at 0x400000.

Due to our current address space implementation, handling these accurately isn't possible on Windows. Both of these addresses can be before the system_managed_base set during emulator init.

@StevenMiller123
StevenMiller123 marked this pull request as ready for review May 4, 2025 19:20
@squidbus
squidbus merged commit fed0649 into shadps4-emu:main May 5, 2025
@rafael-57

Copy link
Copy Markdown
Contributor

As a note for future reference, this PR still isn't fully accurate. Specifically (according to red-prig), modules loaded by games (through sceKernelLoadStartModule) should be loaded at a base address of 0x80000000. Additionally, the executable sections of the game's eboot.bin should be mapped at 0x400000.

Due to our current address space implementation, handling these accurately isn't possible on Windows. Both of these addresses can be before the system_managed_base set during emulator init.

image

Wouldn't it be better to add a comment explaining this here or nah?

@StevenMiller123
StevenMiller123 deleted the fix-module-mappings branch May 5, 2025 14:17
@StevenMiller123

Copy link
Copy Markdown
Collaborator Author

@rafael-57
I'll probably end up making a feature request issue detailing all these address-space issues I've come across in my recent PRs.
We'll need to rework it on all platforms if we want to accurately handle the PS4's memory map.

alextrack2013 pushed a commit to alextrack2013/shadPS4 that referenced this pull request May 5, 2025
* Fix module map addresses

Most modules are mapped starting at 0x800000000, with no gaps between mappings.

* Hardcode hardware accurate base address

Looking at our address space, all platforms will have this base address mapped, so there shouldn't be any problem in using it.

* Clang

* Swap module mapping to NoFlags, remove offset code

Since real hardware has no gap between module mappings, the Fixed flag is just an annoyance to work around, and has no impact on the actual mappings.
Swapping the module mappings to use flags NoFlags instead simplifies our code slightly.

* Fix module mapping names

On real hardware, the file extension is part of the mapping name. Easiest way to manage this is to swap the name to be `file.filename().string()` instead of `file.stem().string()`

* Fix patches

Completely missed this, whoops.
AzaharPlus pushed a commit to AzaharPlus/shadPS4Plus that referenced this pull request May 5, 2025
* Fix module map addresses

Most modules are mapped starting at 0x800000000, with no gaps between mappings.

* Hardcode hardware accurate base address

Looking at our address space, all platforms will have this base address mapped, so there shouldn't be any problem in using it.

* Clang

* Swap module mapping to NoFlags, remove offset code

Since real hardware has no gap between module mappings, the Fixed flag is just an annoyance to work around, and has no impact on the actual mappings.
Swapping the module mappings to use flags NoFlags instead simplifies our code slightly.

* Fix module mapping names

On real hardware, the file extension is part of the mapping name. Easiest way to manage this is to swap the name to be `file.filename().string()` instead of `file.stem().string()`

* Fix patches

Completely missed this, whoops.
alextrack2013 pushed a commit to alextrack2013/shadPS4 that referenced this pull request May 9, 2025
* Fix module map addresses

Most modules are mapped starting at 0x800000000, with no gaps between mappings.

* Hardcode hardware accurate base address

Looking at our address space, all platforms will have this base address mapped, so there shouldn't be any problem in using it.

* Clang

* Swap module mapping to NoFlags, remove offset code

Since real hardware has no gap between module mappings, the Fixed flag is just an annoyance to work around, and has no impact on the actual mappings.
Swapping the module mappings to use flags NoFlags instead simplifies our code slightly.

* Fix module mapping names

On real hardware, the file extension is part of the mapping name. Easiest way to manage this is to swap the name to be `file.filename().string()` instead of `file.stem().string()`

* Fix patches

Completely missed this, whoops.
Xcedf pushed a commit to Xcedf/shadPS4 that referenced this pull request May 12, 2025
Xcedf pushed a commit to Xcedf/shadPS4 that referenced this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants