PlayStation 4 emulator for Windows, Linux and macOS written in C++
Find a file
Stephen Miller d8204641fa
libkernel: Filesystem code cleanup (#2554)
* sceKernelOpen: Clean up flag handling

* sceKernelOpen: fix params

Based on decompilation, the second parameter of _open should be flags.
Additionally swaps the return and parameter types to align with our current standards.

* sceKernelOpen: Fix errors

Based on POSIX spec, if part of the path is missing, ENOENT is the correct return.
Additionally, decompilation suggests that open sets errno too.

* Fix exports

Fixes function exports to align with what they should be, based on what I've seen from decompilation and our module generator.

* Proper errno behavior on open

Since sceKernelOpen calls posix_open, errno should be set during this process.
Simplest way to handle that is to move the actual open code to posix_open and adjust error cases accordingly.

* Reorganize open calls, add error log

* Improve close

Removes the EPERM return, as it makes no sense, and swaps sceKernelClose with posix_close to properly emulate errno behavior.

* Fix log on close

* posix_open fixups

* Readd hack in posix_close

It's either this, or removing LLE DiscMap.
Or shadow implements posix sockets.

* Missing exports

Commented out while I gradually work through them all

* Remaining placeholder exports

* Swap some stuff around

I see nothing that suggests "open" only takes two parameters, so this should be completely safe.
It's also more accurate to how these are handled in libkernel, and means I won't need to reorganize anything for readv and writev.

* Update file_system.cpp

* Implement write and posix_write

* Oops

* Implement posix_readv and sceKernelReadv

Also fixes error behavior on readv, as that function shouldn't be returning any kernel error codes.

* Move sceKernelUnlink

Will deal with this one later, was just annoyed by how it's location doesn't align with the export order.

* Cleanup readv

* Implement posix_writev and sceKernelWritev

Also fixes error behavior on writev, since it shouldn't ever return kernel errors (since our device files return those)

* More cleanup on older functions

* Swap around sceKernelLseek and posix_lseek

This ensures that these have the correct error behavior, and makes their behavior align with the updated implementations for earlier functions.

* Update file_system.cpp

* Implement read

Also fixes error behavior

* Swap sceKernelMkdir and posix_mkdir

Fixes errno behavior on kernel calls, also fixed some incorrect error returns.

* Fix errno behavior on sceKernelRmdir

Also reduces function logging to bring it closer to the level of logging seen in other filesystem functions.

* Slight clean up of sceKernelStat

Fixes error behavior and changes some of the old data types.

* Refactor fstat

Fixes errno behavior, implements fstat, and shifts exports around based on file position.
Might reorganize function locations later though.

* Implement posix_ftruncate

Implements posix_ftruncate and fixes errno behavior for sceKernelFtruncate

* Add missing error conversions for more device functions

* Implement posix_rename, fix sceKernelRename errno behavior

* Add posix_preadv and posix_pread

Also fixes some incorrect error returns, fixes errno behavior, and removes an unnecessary hack.

* Fix compile

* Implement posix_getdents, getdirentries, and posix_getdirentries

Also fixes errno behavior for the kernel variants of these functions.

* Fix errno behavior of sceKernelFsync

* Implement posix_pwrite and posix_unlink

Also fixes errno behavior in related functions.

* Update file_system.cpp

* Remove SetPosixErrno

Ideally, we've handled all possible error conditions before calling these functions, so treat errors in platform-specific code as IO errors and return POSIX_EIO instead.

* Update header exports

Not sure where these get used, but might as well keep them consistent with the rest of this.

* Check if file exists before calling platform-specific code

Bloodborne checks if a file doesn't exist using open, checking if it specifically failed with error code ENOENT. To avoid working with platform-specific errnos, add a proper error return for if the file doesn't exist.
Fixes a regression in Bloodborne.

* Clang

Out of all the changes, this is apparently the only thing Clang-Format doesn't like.
I'm honestly surprised.

* Improve error checks on posix_unlink

Just because a file isn't opened doesn't mean the file doesn't exist.
Fixes the error returned if host_path.empty(), and removes the error return for when GetFile fails.

* Fix the Bloodborne fix

* Limit exports to tested functions

* More confirmed working exports

* Remaining stuff my games can test

* FS exports from firmware tests

* Bring back missing exports from main

I don't have any bootable things that call these, but since they were working well enough on main, they should be fine to readd.

* Add export for posix_pread

Spotted in Dreams a while back, might as well add it.

* Revert "Remove SetPosixErrno"

This reverts commit bdfc0c246c.

* Revert SetPosixErrno changes

shadow's using it for posix sockets, so significant modifications would introduce unnecessary merge conflicts.

* Update comment

* Add EACCES errno to SetPosixErrno

Seen in Gravity Rush.
Also reorganizes the switch case based on the posix errno value, since ordering by errno makes no sense on some OSes.

* More export fixups

Missed these during my initial pass through FS stuff because they were in kernel.cpp for some reason.

* Symbols from FS tests

Tested by messing around with firmware elfs, these atleast don't cause any crashes.

* Remove inaccurate error behavior

Seek can have offsets past the end of a file.
Also add logging for two valid whence values that are unsupported on Windows.
I'll need to verify that SEEK_HOLE and SEEK_DATA correspond to 3 and 4 respectively, I've yet to check source to verify.

* Fix error log

Oops

* Clang

Clang

* Remove close hack

Since LLE libSceDiscMap is no longer a concern, this hack shouldn't be needed.
Since sockets are still stubbed, and close can be used on sockets, I've added a warning log just in case this still occurs in some titles.

* Change SetPosixErrno unreachable to warning

I changed it to an unreachable in an earlier commit to make testing easier.
At this point, having an unreachable for this seems unnecessary, so change it to a warning instead.

* Remove Bloodborne hack

Games should be able to unlink files that aren't opened file descriptors. As far as I've tested, this doesn't break Bloodborne.
2025-03-26 18:03:35 +02:00
.ci Bump to Clang 19 (#2434) 2025-02-18 15:55:13 +02:00
.github CI: Use Qt 6.9.0 + Update CMake Cache (#2487) 2025-02-21 08:29:09 +02:00
cmake Trophy pop-up and viewer enhancements (#2493) 2025-02-23 10:00:24 +02:00
dist tagged v0.7.0 2025-03-23 00:14:04 +02:00
documents docs: add qt6-tools to Arch build guide (#2495) 2025-02-23 02:09:53 -08:00
externals fix debug version for cryptopp (#2664) 2025-03-21 16:12:14 +02:00
LICENSES audio: Accurate audio output timing. (#1986) 2024-12-31 12:38:52 +02:00
scripts Rewrite Save Data & Impl Save Data Dialog (#824) 2024-09-20 12:34:19 +03:00
src libkernel: Filesystem code cleanup (#2554) 2025-03-26 18:03:35 +02:00
.gitignore misc: Add JetBrains build directories to gitignore. (#1573) 2024-11-22 17:36:31 +02:00
.gitmodules build: Compile for Sandy Bridge CPU target. (#2651) 2025-03-18 16:02:34 -07:00
CMakeLists.txt shader_recompiler: Improve divergence handling and readlane elimintation (#2667) 2025-03-23 00:35:42 +02:00
CMakeSettings.json fix VS intellisense (#1104) 2024-09-27 09:03:42 +03:00
CONTRIBUTING.md Fix typo in CONTRIBUTING.md comment 2024-08-23 18:29:00 -07:00
crowdin.yml Update Crowdin configuration file 2025-02-13 14:50:02 +02:00
LICENSE Initial commit 2022-10-24 12:48:38 +03:00
README.md Update README.md (#2488) 2025-02-21 00:30:40 +02:00
REUSE.toml Trophy Viewer - Select Game (#2678) 2025-03-24 10:25:51 +02:00
shell.nix Update linux build docs (#2474) 2025-02-19 13:29:31 +02:00



shadPS4

General information

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

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.
For those who'd like to donate to the project, we now have a 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 as a fun project. 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

Important

If you want to use shadPS4 to play your games, you don't have to follow the build instructions, you can simply download the emulator from either the release tab or the action tab.

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 on Apple Silicon-based Mac devices and at least macOS 14 on Intel-based Mac devices.

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.

Main team

Logo is done by Xphalnos

Contributing

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

Translations

If you want to translate shadPS4 to your language we use crowdin.

Contributors

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