Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/libs/prx/libkernel/DirectMemory/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ int APS5_VABI sceKernelReleaseFlexibleMemory(void* addr, size_t len) {

int APS5_VABI sceKernelReleaseDirectMemory(int64_t start, size_t len) {
if (start < 0 || len == 0) return SCE_KERNEL_ERROR_EINVAL;
if ((static_cast<std::uint64_t>(start) & (PS5_PAGE_SIZE - 1)) != 0 || (len & (PS5_PAGE_SIZE - 1)) != 0 ||
len > DIRECT_MEMORY_SIZE || static_cast<std::uint64_t>(start) > DIRECT_MEMORY_SIZE - len)
return SCE_KERNEL_ERROR_EINVAL;
const auto views = DirectMemoryViews(start, len);
DirectMemoryFree(start, len);
UnmapDirectMemoryViews(views);
Expand Down
15 changes: 15 additions & 0 deletions core/libs/tests/GuestMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "prx/libc/include/GuestWriteWatch.hpp"
#include "prx/libkernel/File/include/FileFlags.hpp"
#include "prx/libkernel/KernelErrors.hpp"
#include "prx/libkernel/DirectMemory/DirectMemory.hpp"
#include <array>
#include "SceTypes.hpp"
#include <chrono>
Expand Down Expand Up @@ -293,6 +294,19 @@ static void CheckReleaseDirectMemoryClearsMappings() {
}
}

static void CheckReleaseDirectMemoryRejectsInvalidRanges() {
constexpr std::size_t page = 0x4000;
Require(sceKernelReleaseDirectMemory(-1, page) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(0, 0) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(0, 1) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(0, page - 1) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(1, page) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(0, std::numeric_limits<std::size_t>::max()) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(0, DIRECT_MEMORY_SIZE + page) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(DIRECT_MEMORY_SIZE - page, page * 2) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(DIRECT_MEMORY_SIZE, page) == SCE_KERNEL_ERROR_EINVAL);
}

static void CheckFixedMappingReplacesPartialOverlap() {
constexpr std::size_t page = 0x4000;
std::int64_t phys = 0;
Expand Down Expand Up @@ -1238,6 +1252,7 @@ int main() {
CheckAudioCoprocessorProtection();
CheckDirectMemoryFollowsPhysicalPages();
CheckReleaseDirectMemoryClearsMappings();
CheckReleaseDirectMemoryRejectsInvalidRanges();
CheckFixedMappingReplacesPartialOverlap();
CheckDirectMemoryGpuProtBits();
CheckFixedVirtualReservation();
Expand Down
Loading