feat(libkernel): implement sceKernelGetDirectMemoryType

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Adrià Franch
2026-10-06 07:44:18 +02:00
parent 481c85e7c9
commit 6d2713cbdd
2 changed files with 46 additions and 0 deletions
@@ -148,6 +148,18 @@ int APS5_VABI sceKernelDirectMemoryQuery(int64_t offset, int flags, void* info,
return 0;
}
int APS5_VABI sceKernelGetDirectMemoryType(int64_t offset, int* memory_type, int64_t* start, int64_t* end) {
if (!memory_type || !start || !end) return SCE_KERNEL_ERROR_EINVAL;
int64_t blockStart = 0;
int64_t blockEnd = 0;
int blockType = 0;
if (!DirectMemoryFind(offset, false, &blockStart, &blockEnd, &blockType)) return SCE_KERNEL_ERROR_ENOENT;
*memory_type = blockType;
*start = blockStart;
*end = blockEnd;
return 0;
}
size_t APS5_VABI sceKernelGetDirectMemorySize(void) {
return DIRECT_MEMORY_SIZE;
}
+34
View File
@@ -59,6 +59,7 @@ int APS5_VABI sceKernelAioSubmitReadCommands(KernelAioRwRequest*, std::int32_t,
int APS5_VABI sceKernelAioWaitRequest(std::int32_t, std::int32_t*, std::uint32_t*);
int APS5_VABI sceKernelAioDeleteRequest(std::int32_t, std::int32_t*);
int APS5_VABI sceKernelMlock_nid_postfix(void*, std::uint64_t);
int APS5_VABI sceKernelGetDirectMemoryType(std::int64_t, int*, std::int64_t*, std::int64_t*);
}
static void Require(bool condition, std::source_location location = std::source_location::current()) {
@@ -191,6 +192,38 @@ static void CheckReleaseDirectMemoryClearsMappings() {
Require(sceKernelMunmap(mapped, page * 2) == 0);
}
static void CheckGetDirectMemoryType() {
constexpr std::size_t page = 0x4000;
std::int64_t first = 0;
Require(sceKernelAllocateDirectMemory(0, 0x7fffffffffll, page * 2, 0, 3, &first) == 0);
std::int64_t second = 0;
Require(sceKernelAllocateDirectMemory(first + page * 2, first + page * 3, page, 0, 1, &second) == 0 && second == first + page * 2);
int type = -1;
std::int64_t start = -1;
std::int64_t end = -1;
Require(sceKernelGetDirectMemoryType(first, &type, &start, &end) == 0);
Require(type == 3 && start == first && end == first + page * 2);
type = -1;
Require(sceKernelGetDirectMemoryType(first + page * 2 - 1, &type, &start, &end) == 0);
Require(type == 3 && start == first && end == first + page * 2);
Require(sceKernelGetDirectMemoryType(first + page * 2, &type, &start, &end) == 0);
Require(type == 1 && start == second && end == second + page);
Require(sceKernelGetDirectMemoryType(first, nullptr, &start, &end) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelGetDirectMemoryType(first, &type, nullptr, &end) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelGetDirectMemoryType(first, &type, &start, nullptr) == SCE_KERNEL_ERROR_EINVAL);
Require(sceKernelReleaseDirectMemory(first, page) == 0);
type = -1;
start = -1;
end = -1;
Require(sceKernelGetDirectMemoryType(first, &type, &start, &end) == SCE_KERNEL_ERROR_ENOENT);
Require(type == -1 && start == -1 && end == -1);
Require(sceKernelGetDirectMemoryType(-1, &type, &start, &end) == SCE_KERNEL_ERROR_ENOENT);
Require(sceKernelGetDirectMemoryType(first + page, &type, &start, &end) == 0);
Require(type == 3 && start == first + page && end == first + page * 2);
Require(sceKernelReleaseDirectMemory(first + page, page * 2) == 0);
Require(sceKernelGetDirectMemoryType(second, &type, &start, &end) == SCE_KERNEL_ERROR_ENOENT);
}
static void CheckFixedVirtualReservation() {
constexpr std::size_t page = 0x4000;
void* probe = nullptr;
@@ -727,6 +760,7 @@ int main() {
CheckFixedVirtualReservation();
CheckMlock();
CheckSharedDirectMemoryLifecycle();
CheckGetDirectMemoryType();
CheckHeapAfterMappingReuse();
#ifdef _WIN32
CheckNoOverwriteRejectsHostOccupiedMapping();