shadPS4/src/core
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
..
aerolib fix typo in LOG_INFO (#559) 2024-08-26 15:22:11 +03:00
devices fix: Add missing ctime includes. 2025-04-30 23:37:37 -07:00
devtools Devtools: Add Module Viewer (#2976) 2025-05-24 09:15:10 -03:00
file_format externals: Remove need for cryptopp build. (#2707) 2025-03-29 10:32:06 +02:00
file_sys Handle "-patch" as the suffix for game update folders (#2674) 2025-03-23 23:24:49 +02:00
libraries Core: More Memory Cleanup & Fixes (#2997) 2025-05-29 18:56:03 +03:00
loader Fix path bugs & wrap seeks in an if (#1154) 2024-09-30 12:42:59 +03:00
address_space.cpp address_space: Split macOS reserved memory region. (#2372) 2025-02-08 13:21:32 -08:00
address_space.h Core: Fix module load addresses (#2879) 2025-05-05 03:24:08 -07:00
cpu_patches.cpp Optimize games that hit unpatchable EXTRQ/INSERTQ (#2888) 2025-05-08 19:59:12 +03:00
cpu_patches.h cpu_patches: Remove CPU patches for macOS and bump minimum OS version to 15.4 (#2743) 2025-04-03 22:39:08 +03:00
debug_state.cpp Fix showing debug menu bar / Devtools (#2214) 2025-01-22 22:21:41 -03:00
debug_state.h FidelityFX FSR implementation (#2624) 2025-03-12 20:33:30 +02:00
linker.cpp Devtools: Add Module Viewer (#2976) 2025-05-24 09:15:10 -03:00
linker.h Implement sceKernelGetModuleInfo, sceKernelGetModuleInfoInternal, and sceKernelGetModuleList (#2850) 2025-04-27 09:32:01 +03:00
memory.cpp Core: More Memory Cleanup & Fixes (#2997) 2025-05-29 18:56:03 +03:00
memory.h Core: More Memory Cleanup & Fixes (#2997) 2025-05-29 18:56:03 +03:00
module.cpp Core: Fix module load addresses (#2879) 2025-05-05 03:24:08 -07:00
module.h libkernel: improve module finding in sceKernelLoadStartModule (#2541) 2025-03-09 23:44:17 +02:00
platform.h Support for Vulkan 1.4 (#1665) 2024-12-07 19:41:41 +02:00
signals.cpp Bump to Clang 19 (#2434) 2025-02-18 15:55:13 +02:00
signals.h Patch extrq (#943) 2024-09-23 19:19:52 +03:00
thread.cpp exception: Fix raising exceptions on POSIX systems (#1868) 2024-12-25 00:21:32 +02:00
thread.h Switch remaining CRLF terminated files to LF 2024-12-24 13:56:31 +01:00
tls.cpp cpu_patches: Remove CPU patches for macOS and bump minimum OS version to 15.4 (#2743) 2025-04-03 22:39:08 +03:00
tls.h Lower stack size to clear from 13 to 12 KB (#2967) 2025-05-21 16:22:38 -03:00