* Fixed sceCompanionUtilGetEvent stub
Previously we effectively stubbed with ORBIS_COMPANION_UTIL_INVALID_POINTER, which makes no sense and caused issues in games.
* Check for null issuer_id in libSceNpAuth's GetAuthorizationCode
Comes up in Mirror's Edge Catalyst, according to some debugging done by a community member.
Given the library didn't have any null checks for that value, this is probably allowed.
* PngEnc hle
* format
* formatting + fix scePngEncDelete
* fix cmake + misc improvements
i think the setjmp is right according to the libpng manual, works fine from my testing
* fixes
fix an issue with how alpha was handled, and PngEncode() now properly sets the processed_height in outputInfo.
* format
* Update pngenc.cpp
* set outputInfo->processed_height during png write
i assume some games will use this for error handling
This issue would cause memory leaks in some EA titles, also just generally makes it harder to debug stuff when the fd table is flooded with closed sockets and epolls.
* 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>
* Initial work
* Bug fixing
deadlocks and broken unmaps
* Fix more bugs
broken memory pools
* More bug fixing
Still plenty more to fix though
* Even more bug fixing
Finally got Final Fantasy XV back to running, haven't found anymore bugs yet.
* More bugfixing
* Update memory.cpp
* Rewrite start
* Fix for oversized unmaps
* Oops
* Update address_space.cpp
* Clang
* Mac fix?
* Track VMA physical areas based on start in VMA
Allows me to simplify some logic, and should (finally) allow merging VMAs in memory code.
* Merge VMAs, fix some bugs
Finally possible thanks to address space + phys tracking changes
* Clang
* Oops
* Oops2
* Oops3
* Bugfixing
* SDK check for coalescing
Just to rule out any issues from games that wouldn't see coalescing in the first place.
* More ReleaseDirectMemory fixes
I really suck at logic some days
* Merge physical areas within VMAs
In games that perform a lot of similar mappings, you can wind up with 1000+ phys areas in one vma.
This should reduce some of the overhead that might cause.
* Hopefully fix Mac compile
Why must their uint64_t be different?
* Mac pt.2
Oops
* added libSceAudiodec to lle modules list
* crappy float resample , use it at your own risk
* clang
* adjustments to aac
---------
Co-authored-by: Vladislav Mikhalin <mikhalinvlad@gmail.com>
* OrbisAudio3dOpenParameters struct fix
Not sure why we have the extra filler, but decomp suggests it shouldn't exist.
This fixes stack_chk_fail issues in audio3d using titles.
* Bring back filler, only copy 0x20 bytes.
The library accepts variations on struct size, with the maximum size being the 0x28 size our current struct has.
This fixes the issue without potentially breaking the struct.
* Fix memcpy
Prevent OOB read
* Run libSceRtc LLE
The more we've used our HLE, the more issues we've had with it.
While we debug these bugs, re-enabling LLE will address any regressions the swap caused.
* libSceJpegDec LLE
Needed for Trackmania until we implement HLE for this library
* libScePngEnc LLE
Needed for Minecraft until we implement HLE for this library
* Update documentation appropriately
* libSceJpegEnc LLE
By @georgemoralis's request
* Avoid storing the Tcb pointer on the stack
* Just return the already stored pointer in GetTcbBase
* Replace uses of GetTcbBase with g_curthread->tcb
* copyright 2025
* sir clang offnir, the all-formatting
* Earlier initialization of elf info.
Everything used for elf info initialization comes from the param.sfo, so we can initialize this earlier to have this information accessible during memory init.
* Extract compiled SDK version from pubtoolinfo string
Up until now, we've been using the game's reported "firmware version" as our compiled SDK version. This behavior is inaccurate, and is something that has come up in my hardware tests before.
For the actual compiled SDK version, we should use the SDK version in the PUBTOOLINFO string of the param.sfo, only falling back on the firmware version when that the sdk_ver component isn't present.
* Store compiled SDK version in ElfInfo
* Limit address space for compiled SDK version at or above FW 3
Sony placed a hard cap at 0xfc00000000, with a slight extension for stack mappings. For now, though stack mappings aren't implemented, there's no harm in keeping a slightly extended address space (since this cap is lower than our old user max).
Limiting the max through address space is necessary for Windows due to performance issues, in the future I plan to properly implement checks in memory manager code to properly handle this behavior for all platforms.
* Use compiled SDK version for sceKernelGetCompiledSdkVersion
I think this is pretty self explanatory.
* Log SDK version
Since this value is what most internal firmware version checks are against, logging the value will help with debugging.
* Update address_space.cpp
* Update emulator.cpp
* Backwards compatible logging
Because that's apparently an issue now