shadPS4/src
Stephen Miller 6cdc52cdde
Core: More Memory Cleanup & Fixes (#2997)
* Only perform GPU memory mapping when GPU can access it

This better aligns with hardware observations, and should also speed up unmaps and decommits, since they don't need to be compared with the GPU max address anymore.

* Reserve fixes

ReserveVirtualRange seems to follow the 0x200000000 base address like MemoryPoolReserve does.
Both also need checks in their flags Fixed path to ensure we're mapping in-bounds. If we're not in mapping to our address space, we'll end up reserving and returning the wrong address, which could lead to weird memory issues in games.

I'll need to test on real hardware to verify if such changes are appropriate.

* Better sceKernelMmap

Handles errors where we would previously throw exceptions. Also moves the file logic to MapFile, since that way all the possible errors are in one place.
Also fixes some function parameters to align with our current standards.

* Major refactor

MapDirectMemory, MapFlexibleMemory, ReserveVirtualRange, and MemoryPoolReserve all internally use mmap to perform their mappings. Naturally, this means that all functions have similar behaviors, and a lot of duplicate code.
This add necessary conditional behavior to MapMemory so MemoryPoolReserve and ReserveVirtualRange can use it, without disrupting the behavior of MapDirectMemory or MapFlexibleMemory calls.

* Accurate phys_addr for non-direct mappings

* Properly handle GPU access rights

Since my first commit restricts GPU mappings to memory areas with GPU access permissions, we also need to be updating the GPU mappings appropriately during Protect calls too.

* Update memory.cpp

* Update memory.h

* Update memory.cpp

* Update memory.cpp

* Update memory.cpp

* Revert "Update memory.cpp"

This reverts commit 2c55d014c0.

* Coalesce dmem map

Aligns with hardware observations, hopefully shouldn't break anything since nothing should change hardware-wise when release dmem calls and unmap calls are performed?
Either that or Windows breaks because Windows, will need to test.

* Implement posix_mprotect

Unity calls this
Also fixes the names of sceKernelMprotect and sceKernelMtypeprotect, though that's more of a style change and can be reverted if requested.

* Fix sceKernelSetVirtualRangeName

Partially addresses a "regression" introduced when I fixed up some asserts.
As noted in the code, this implementation is still slightly inaccurate, as handling this properly could cause regressions on Windows.

* Unconditional assert in MapFile

* Remove protect warning

This is expected behavior, shouldn't need any logging.

* Respect alignment

Forgot to properly do this when updating ReserveVirtualRange and MemoryPoolReserve

* Fix Mprotect on free memory

On real hardware, this just does nothing. If something did get protected, there's no way to query that information.
Therefore, it seems pretty safe to just behave like munmap and return size here.

* Minor tidy-up

No functional difference, but looks better.
2025-05-29 18:56:03 +03:00
..
common Libs: CompanionUtil (#2963) 2025-05-29 12:33:56 +03:00
core Core: More Memory Cleanup & Fixes (#2997) 2025-05-29 18:56:03 +03:00
images New kbm icon (#2898) 2025-05-17 11:39:35 +03:00
imgui devtools: persist fsr configs (#2852) 2025-04-27 13:32:29 -03:00
input fix rough mouse movement due to incorrect check (#2911) 2025-05-12 21:39:50 +02:00
qt_gui New Crowdin updates (#2982) 2025-05-29 12:42:52 +03:00
shader_recompiler Fix float on f64 (#2985) 2025-05-25 03:49:39 -07:00
video_core Stub PM4 0x8E opcode (#2998) 2025-05-27 12:09:03 -07:00
.clang-format chore: Make shadps4 REUSE compliant 2024-02-23 23:33:43 +02:00
emulator.cpp Devtools: Add Module Viewer (#2976) 2025-05-24 09:15:10 -03:00
emulator.h CLI: Add argument to pass an argument to the game (#2135) 2025-01-18 15:21:08 +03:00
main.cpp VideoOut event cleanup (#2849) 2025-04-27 09:04:17 +03:00
sdl_window.cpp build: Move versioning to CMake file. (#2752) 2025-04-07 12:22:51 +03:00
sdl_window.h Gui: Adding Pause button working, full screen button and labels to buttons on main window gui (#2634) 2025-03-26 23:50:52 +02:00
shadps4.qrc misc: Few small fixes. (#2780) 2025-04-13 12:10:24 -07:00
shadps4.rc [Windows] Adding Properties to the Executable (#2789) 2025-04-17 09:43:14 +03:00