Stephen Miller 46a7c4e1f5 Core: Miscellaneous memory fixes and slight optimizations (#3946)
* Optimizations

Microsoft allows you to coalesce multiple free placeholders in one VirtualFreeEx call, so we can perform the VirtualFreeEx after coalescing with neighboring regions to eliminate a VirtualFreeEx call in some situations.

* Remove unnecessary VirtualProtect call

As far as I can tell, this call wastes a bunch of time, and is completely unnecessary.
With our current codebase, simply supplying prot to MapViewOfFile3 works properly.

* Properly handle file mmaps with offsets

Pretty easy fix to perform while I'm here, so I might as well include it.

* Oops

Leftover stuff from local things + clang

* Disable tracy memory tracking

Tracy's memory tracking is built around a typical malloc/free API, so each individual alloc must correspond to a free.
Moving these to address space would fix issues on Windows, but Linux/Mac would have the same issues with our current code.
Disabling VMA merging is technically a fix, but since that's hardware-accurate behavior, I'd rather not disable it.

I'm sure there's a simple solution I'm missing, but unless other devs have a better idea of how this should be handled, the best I can do is disable it so we can keep using Tracy to trace performance.

* Update address_space.cpp

* Debug logging

Should give a decent idea of how nasty these AddressSpace calls are in games that lost perf.

* test removing thread safety

Just for testing, will revert afterwards.

* Check name before merging

Fixes a regression in Apex Legends

* Revert "test removing thread safety"

This reverts commit ab897f4b1c.

* Move mutex locks before IsValidMapping calls

These aren't thread safe, this fixes a rare race condition that I ran into with Apex Legends.

* Revert "Debug logging"

This reverts commit eb2b12a46c.

* Proper VMA splitting in ProtectBytes, SetDirectMemoryType, and NameVirtualRange

Also slight optimization by eliminating AddressSpace protect calls when requested prot matches the previous prot.
Fixes a regression in God of War: Ragnarok

* Clang

* Fixes to SetDirectMemoryType logic

Fixes some regressions in Marvel's Spider-Man that occurred with my previous commits to this PR.

* Fix Genshin Impact again

* Assert on out-of-bounds protect calls

Our page tracking code is prone to causing this.

* test mutex again

This time, remember all mutex stuff

* Revert hack

I'll work on a better way to deal with mutexes in a bit, first I'm pushing up some extra fixes

* Proper logic for checked ReleaseDirectMemory, added bounds checks

Should help some games.

* Better logging for ReleaseDirectMemory errors.

* Only perform region coalescing after all unmap operations.

A small optimization for unmapping multiple regions. Since Microsoft lets you coalesce multiple placeholders at once, we can save doing any VirtualFreeEx calls for coalescing until after we unmap everything in the requested range.

* Separate VMA creation logic into a separate method, update MapFile to use it

MapFile is technically another "emulation" of MapMemory, both should follow similar logic.
To avoid duplicating code, move shared logic to a different function that both MapMemory and MapFile can call.

This fixes memory asserts in a couple of online-only apps I have.

* Clang

* Fix TryWriteBacking

This fixes a lot of regressions that got misattributed

Co-Authored-By: TheTurtle <47210458+raphaelthegreat@users.noreply.github.com>

* Fix again

Fixes device lost crashes with some games after my last commit.

* Oops

* Mutex cleanup

Avoided changing anything in MapMemory, UnmapMemory, PoolCommit, or PoolDecommit since those all need a little extra granularity to prevent GPU deadlocking.

Everything else now uses standard library locks to make things a little simpler.

* Swap MapMemory and PoolCommit to use scoped lock

GPU maps are safe, so this is fine. Unmaps are the primary issue.

---------

Co-authored-by: TheTurtle <47210458+raphaelthegreat@users.noreply.github.com>
2026-01-24 00:17:57 +02:00
2025-02-18 15:55:13 +02:00
2025-10-31 10:28:39 +02:00
2025-12-28 13:24:42 +02:00
2025-12-28 13:24:42 +02:00
2022-10-24 12:48:38 +03:00
2025-10-31 10:28:39 +02:00
2025-11-08 19:08:18 -08:00



shadPS4

Bloodborne by From Software Hatsune Miku Project DIVA Future Tone by SEGA
Bloodborne screenshot Project DIVA screenshot
Yakuza 0 by SEGA DRIVECLUB™ by Evolution Studios
Yakuza screenshot DRIVECLUB screenshot

General information

shadPS4 is an early PlayStation 4 emulator for Windows, Linux and macOS written in C++.

Important

This is the emulator core, which does not include a GUI. If you just want to use the emulator as an end user, download the QtLauncher instead.

If you encounter problems or have doubts, do not hesitate to look at the Quickstart.
To verify that a game works, you can look at shadPS4 Game Compatibility.
To discuss shadPS4 development, suggest ideas or to ask for help, join our Discord server.
To get the latest news, go to our X (Twitter) or our website.
You can donate to the project via our Kofi page.

Status

Important

shadPS4 is early in development, don't expect a flawless experience.

Currently, the emulator can successfully run games like Bloodborne, Dark Souls Remastered, Red Dead Redemption, and many other games.

Why

This project began for fun. Given our limited free time, it may take some time before shadPS4 can run more complex games, but we're committed to making small, regular updates.

Building

Windows

Check the build instructions for Windows.

Linux

Check the build instructions for Linux.

macOS

Check the build instructions for macOS.

Important

macOS users need at least macOS 15.4 to run shadPS4. Due to GPU issues there are currently heavy bugs on Intel Macs.

Usage examples

Important

For a user-friendly GUI, download the QtLauncher.

To get the list of all available commands and also a more detailed description of what each command does, please refer to the --help flag's output.

Below is a list of commonly used command patterns:

shadPS4 CUSA00001 # Searches for a game folder called CUSA00001 in the list of game install folders, and boots it.
shadPS4 --fullscreen true --config-clean CUSA00001    # the game argument is always the last one,
shadPS4 -g CUSA00001 --fullscreen true --config-clean # ...unless manually specified otherwise.
shadPS4 /path/to/game.elf # Boots a PS4 ELF file directly. Useful if you want to boot an executable that is not named eboot.bin.
shadPS4 CUSA00001 -- -flag1 -flag2 # Passes '-flag1' and '-flag2' to the game executable in argv.

Debugging and reporting issues

For more information on how to test, debug and report issues with the emulator or games, read the Debugging documentation.

Keyboard and Mouse Mappings

Note

Some keyboards may also require you to hold the Fn key to use the F* keys. Mac users should use the Command key instead of Control, and need to use Command+F11 for full screen to avoid conflicting with system key bindings.

Button Function
F10 FPS Counter
Ctrl+F10 Video Debug Info
F11 Fullscreen
F12 Trigger RenderDoc Capture

Note

Xbox and DualShock controllers work out of the box.

Controller button Keyboard equivalent
LEFT AXIS UP W
LEFT AXIS DOWN S
LEFT AXIS LEFT A
LEFT AXIS RIGHT D
RIGHT AXIS UP I
RIGHT AXIS DOWN K
RIGHT AXIS LEFT J
RIGHT AXIS RIGHT L
TRIANGLE Numpad 8 or C
CIRCLE Numpad 6 or B
CROSS Numpad 2 or N
SQUARE Numpad 4 or V
PAD UP UP
PAD DOWN DOWN
PAD LEFT LEFT
PAD RIGHT RIGHT
OPTIONS RETURN
BACK BUTTON / TOUCH PAD SPACE
L1 Q
R1 U
L2 E
R2 O
L3 X
R3 M

Keyboard and mouse inputs can be customized in the settings menu by clicking the Controller button, and further details and help on controls are also found there. Custom bindings are saved per-game. Inputs support up to three keys per binding, mouse buttons, mouse movement mapped to joystick input, and more.

Firmware files

shadPS4 can load some PlayStation 4 firmware files. The following firmware modules are supported and must be placed in shadPS4's sys_modules folder.

Modules Modules Modules Modules
libSceCesCs.sprx libSceFont.sprx libSceFontFt.sprx libSceFreeTypeOt.sprx
libSceJpegDec.sprx libSceJpegEnc.sprx libSceJson.sprx libSceJson2.sprx
libSceLibcInternal.sprx libSceNgs2.sprx libScePngEnc.sprx libSceRtc.sprx
libSceUlt.sprx libSceAudiodec.sprx

Caution

The above modules are required to run the games properly and must be dumped from your legally owned PlayStation 4 console.

Main team

Logo is done by Xphalnos

Contributing

If you want to contribute, please read the CONTRIBUTING.md file.
Open a PR and we'll check it :)

Special Thanks

A few noteworthy teams/projects who've helped us along the way are:

  • Panda3DS: A multiplatform 3DS emulator from our co-author wheremyfoodat. They have been incredibly helpful in understanding and solving problems that came up from natively executing the x64 code of PS4 binaries

  • fpPS4: The fpPS4 team has assisted massively with understanding some of the more complex parts of the PS4 operating system and libraries, by helping with reverse engineering work and research.

  • yuzu: Our shader compiler has been designed with yuzu's Hades compiler as a blueprint. This allowed us to focus on the challenges of emulating a modern AMD GPU while having a high-quality optimizing shader compiler implementation as a base.

  • felix86: A new x86-64 → RISC-V Linux userspace emulator

License

Description
⚠️ ARCHIVED: Original GitHub repository no longer exists. Preserved as backup on 2026-01-31T05:30:49.252Z
Readme GPL-2.0 92 MiB
Languages
C++ 98.1%
C 1.3%
CMake 0.3%
SourcePawn 0.3%