* renderer_vulkan: Microoptimizations from profiling
* buffer_cache: Only use streaming path on cpu modified memory
If the pages arent cpu modified, then a gpu buffer with valid data exists that can be used instead
* clang format
* fix max num_layers
* Early memory regions setup
Needed to enable flexible allocations before mapping the eboot
* Improved accuracy of module mappings
To keep our current logic intact, reserve the full memory space, then perform fixed mappings for trampoline and segments. Segment mappings use type flexible, so they properly count toward flexible usage, while trampoline mappings use type code to bypass this.
* Asserts for failed offset finding
Always check before you leap.
* Hex logging for segment sizes
* Only map game modules to flex mem.
* Revert "Asserts for failed offset finding"
This reverts commit 38083f8cbb.
* Revert "Early memory regions setup"
This reverts commit da1552d4ac.
* Initialize memory regions in MemoryManager constructor
Much simpler approach to enabling the necessary flexible mappings on startup.
* fixed Unsynchronized free_threads.size()` Read in ThreadState::Free
* fixed data race in posix_pthread_key_create , allocated and seqno are atomic now
* fixed playtime thread
* argv array size fix
* destroy mutex on object deletion with pthread_mutex_destroy
* fixed object_pool
* used atomics for thread safety
* equeue: Save filter/ident before std:move since we access them out of the locked loop
* fixed kqueues memory leak
* clean storage objects effectively
* fixed memory leak
* fix some races
* fixed race condition
* using new emulator_settings
* the default user is now just player one
* transfer install, addon dirs
* fix load custom config issue
---------
Co-authored-by: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com>
* improve signal emulation
* make the sce function use the new posix ones
* ifdefing away the issues
* fix me being very tired yesterday night
* let macOS handle SIGRT signals with the native sigaction call instead of an early error return
* windows still has no clue what the fuck is going on
* the loathsome clang-formatter
* fix oact
* return the guest handler, not the host one
* Clear any existing signal mask for game threads.
* don't rely on implementation specific things
* Fix Windows support and sceKernelRaiseException bug
* Review suggestions
@kalaposfos13 suggested I push these.
---------
Co-authored-by: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com>
* Replace sysmodule enums with table
Dumped this from the 12.52 module, using a script I created.
* Better documentation
* Separate from system libraries
That system folder is going to be getting quite large if I left all the sysmodule stuff in there.
* More arrays from library
* Found another preload list
Ghidra really hates decompiling libSceSysmodule, so I didn't notice this one at first.
Also documented specific versions tied to each preload list.
* Start work on implementation
* Some basic implementations
* Initial stub for module loading
Just enough to see if the logic functions appropriately.
* Clang
* sceSysmoduleLoadModule
Now I need to get sceSysmodulePreloadModuleForLibkernel done so that we don't have bugs from not loading internal LLEs.
* sceSysmoduleLoadModuleInternal
* sceSysmodulePreloadModuleForLibkernel
I have successfully broken quite literally everything.
I shall debug this tomorrow.
* Slight fix
* Maybe fix?
* Change log
Enjoy the log spam 😄
* Increased defined stub count
Now that libc and libSceLibcInternal loads later, all the auto stubs are getting consumed by it.
* sceSysmoduleUnloadModule stub
Also a couple fixes. Sysmodule does pass argc and argv to game modules, but only after loading them once to check binaries.
Shouldn't matter for the most part.
* Clang
* Less stubs
2 thousand is seemingly enough.
* sceSysmoduleLoadModuleInternalWithArg
Doesn't hurt to have, since Apex Legends calls it.
* Oops
* Oops 2
* Rename isModuleLoaded to getModuleHandle
Review comment
* Remove debug game module loads
These cases only trigger when specific sceRegMgr key values are set, and for our purposes, we can treat that case as false.
* Allow preloading to fail
For kalaposfos
* Clang
* Remove dead code from EqueueInternal::WaitForEvents
No longer necessary now that we avoid using small timers when falling back on equeue logic.
* Refactor type names
Might as well
* Properly define OrbisKernelEqueue as a handle
Most of the functions using an "OrbisKernelEqueue" call directly into kevent. Therefore, OrbisKernelEqueue should be a equeue handle.
* Clang
* Widen OrbisKernelEqueue type
On real hardware, it's some value that contains the handle, as opposed to just the handle itself.
* kqueue implementation
The easy part
* Hardware-accurate timer data
Needed to make kevent simpler for these uses.
* Move callback scheduling to EqueueInternal::AddEvent
kevent would become excessively bloated if I needed to deal with that in there.
* posix_kevent
kevent is a bit of a pain, for now I've implemented as much as libkernel actually uses for it's wrappers, and left error logs to skip behavior when necessary.
* Log calls
* Apple, why are you calling fstat on an equeue?
* Change thread pausing to use SIGTRMIN on UNIX
* Allow handling of the rest of the signals
* Add orbis-native signal number conversion and fix a few bugs
* ifdefing away the issues
* add check for mac for the signal that's used for thread pausing there
* Add a few more registers
* Don't break HLE memory tracking
Now, if a guest app installs a handler for SIGSEGV/SIGBUS/SIGILL, that'll be handled by keeping the original signal handler, and if we can't handle the signal ourselves (as in it didn't come from HLE memory tracking), we pass it on to the guest
* copyright 2026
* +
* Fix vblank event data
* Various logical fixes for timer events
Store timer timeouts in nanoseconds now, properly handle event "replacement", avoid employing small timers when adding events to equeues, fix stored timer data
* Clang
* Don't clear events that don't need clearing
Unless the event has the clear flag, it will be returned multiple times after triggering.
* Fix event flags
As older code suggests, the PS4 kernel does append the clear flag to various event types internally. This is visible when observing the returned event data from sceKernelWaitEqueue (or kevent, if you're feeling ambitious)
Add flag is also removed from events internally.
* Initial definitions
* internal__Fofind
* Libcinternal threads
fopen stores a valid pthread mutex in the FILE struct. Since this is exposed to the game/app, we need to handle this accurately.
* internal__Foprep (and various other functions called in it)
* Actual fopen implementation
At long last, an actual function I'm supposed to implement.
* fflush + compile fixes
* fseek implementation
Comes with functions fseek calls, aside from fflush which I pushed earlier.
* fread, _Frprep
Also changed some parameter names a tad to match how I named things in my decomp.
And fixed some bugs with how I was handling the weird offseted mode thing
* fclose, _Fofree
Not confident on this one, but we'll see I guess.
* Bug fixing
No more crashes at least, fread seems to be broken though.
* fopen bugfixes
Behavior now matches LLE, at least in how LLE font seems to use it.
* Fix _Frprep
Seems like everything works now?
* Logging
Probably going to need to swap lseek and read logs to debug/trace later but this is for debugging.
* Remove alignment check
Seems I must've misinterpreted some of what Ghidra spat out, since libSceNgs2 is calling with size 1, nmemb 4.
* Reduce fseek, fread logs to trace
* Clang
* twos
* Fixes
Still can't test properly, but this seems to hide system libs, which I'm pretty sure is the necessary difference here.
* Clang
* Extra export for sceKernelGetModuleInfo2
* Fix assert
Just a typical day of me pushing something a month ago, nobody testing/reviewing it, then finding out it's broken when that code inevitably makes it into production.
* Remove unreachable in posix_pthread_mutex_timedlock
It's apparently something that was added during pthreads rewrite, but the actual code for this function seems to be fully implemented?
* 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