shadPS4/src/core/libraries/kernel
Stephen Miller 6c5a84dc99
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Core: Handle various edge cases related to executable permissions. (#3660)
* Fix flag handling on Windows

Fixes a weird homebrew kalaposfos made

* Fix backing protects

Windows requires that protections on areas committed through MapViewOfFile functions are less than the original mapping.
The best way to make sure everything works is to VirtualProtect the code area with the requested protection instead of applying prot directly.

* Fix error code for sceKernelMapDirectMemory2

Real hardware returns EINVAL instead of EACCES here

* Fix prot setting in ProtectBytes

* Handle some extra protection-related edge cases.

Real hardware treats read and write as separate perms, but appends read if you call with write-only (this is visible in VirtualQuery calls)

Additionally, execute permissions are ignored when protecting dmem mappings.

* Properly handle exec permission behavior for memory pools

Calling sceKernelMemoryPoolCommit with executable permissions returns EINVAL, mprotect on pooled mappings ignores the exec protection.

* Clang

* Allow execution protection for direct memory

Further hardware tests show that the dmem area is actually executable, this permission is just hidden from the end user.

* Clang

* More descriptive assert message

* Align address and size in mmap

Like most POSIX functions, mmap aligns address down to the nearest page boundary, and aligns address up to the nearest page boundary.
Since mmap is the only memory mapping function that doesn't error early on misaligned length or size, handle the alignment in the libkernel code.

* Clang

* Fix valid flags

After changing the value, games that specify just CpuWrite would hit the error return.

* Fix prot conversion functions

The True(bool) function returns true whenever value is greater than 0. While this rarely manifested before because of our wrongly defined CpuReadWrite prot, it's now causing trouble with the corrected values.
Technically this could've also caused trouble with games mapping GpuRead permissions, but that seems to be a rare enough use case that I guess it never happened?

I've also added a warning for the case where `write & !read`, since we don't properly handle write-only permissions, and I'm not entirely sure what it would take to deal with that.

* Fix some lingering dmem issues

ReleaseDirectMemory was always unmapping with the size parameter, which could cause it to unmap too much. Since multiple mappings can reference the same dmem area, I've calculated how much of each VMA we're supposed to unmap.
Additionally, I've adjusted the logic for carving out the free dmem area to properly work if ReleaseDirectMemory is called over multiple dmem areas.

Finally, I've patched a bug with my code in UnmapMemory.
2025-09-28 11:36:12 +03:00
..
sync kernel: Improvements to condvars. (#3592) 2025-09-13 08:41:26 -07:00
threads Fix Pthread memset warning and add comment. (#3625) 2025-09-19 02:17:30 -07:00
aio.cpp Core: Remove checks for symbol version_major and version_minor (#3540) 2025-09-08 19:30:03 -07:00
aio.h sceKernelAio* implementation (#2160) 2025-01-16 18:27:52 +02:00
debug.cpp Core: Remove checks for symbol version_major and version_minor (#3540) 2025-09-08 19:30:03 -07:00
debug.h Minor libkernel changes (#2721) 2025-03-30 01:27:33 +02:00
equeue.cpp equeue: Few fixes for sceKernelWaitEqueue (#3548) 2025-09-08 19:47:12 -07:00
equeue.h equeue: Few fixes for sceKernelWaitEqueue (#3548) 2025-09-08 19:47:12 -07:00
file_system.cpp Epolls are file descriptors (#3622) 2025-09-22 22:57:51 +03:00
file_system.h Filesystem: Abstract handling of directory files (#3455) 2025-08-25 23:41:24 +03:00
kernel.cpp Add missing ioctl export (#3579) 2025-09-12 00:44:02 -07:00
kernel.h Implement getargc and getargv (#3562) 2025-09-09 14:58:22 -07:00
memory.cpp Core: Handle various edge cases related to executable permissions. (#3660) 2025-09-28 11:36:12 +03:00
memory.h Core: Memory code cleanup and further direct memory fixes (#3655) 2025-09-26 02:28:32 -07:00
orbis_error.h core: Library cleanup (#1631) 2024-11-30 22:37:36 +02:00
posix_error.h core: Library cleanup (#1631) 2024-11-30 22:37:36 +02:00
process.cpp Core: Remove checks for symbol version_major and version_minor (#3540) 2025-09-08 19:30:03 -07:00
process.h Libraries: Implement sceKernelIsInSandbox, update OrbisSysModule enum (#3546) 2025-09-07 13:11:15 -07:00
threads.cpp kernel: Rewrite pthread emulation (#1440) 2024-11-21 22:59:38 +02:00
threads.h kernel: Implement scePthreadGetaffinity (#2916) 2025-05-12 10:46:53 -07:00
time.cpp kernel: Improvements to condvars. (#3592) 2025-09-13 08:41:26 -07:00
time.h Make libSceRtc fully HLE (#3330) 2025-08-06 20:08:26 +03:00