Memory: Implement sceKernelMemoryPoolGetBlockStats (#3646)

* Implement sceKernelMemoryPoolGetBlockStats

Not entirely sure on the logic behind the cached blocks work, but flushed blocks seems to just be based on committed direct memory.

* Fix comment
This commit is contained in:
Stephen Miller
2025-09-24 04:40:26 -05:00
committed by GitHub
parent 5d8027f0c0
commit eeee6ad0ee
4 changed files with 49 additions and 0 deletions

View File

@@ -555,6 +555,23 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolBatch(const OrbisKernelMemoryPoolBatchEntry*
return result;
}
s32 PS4_SYSV_ABI sceKernelMemoryPoolGetBlockStats(OrbisKernelMemoryPoolBlockStats* stats,
u64 size) {
LOG_WARNING(Kernel_Vmm, "called");
auto* memory = Core::Memory::Instance();
OrbisKernelMemoryPoolBlockStats local_stats;
memory->GetMemoryPoolStats(&local_stats);
u64 size_to_copy = size < sizeof(OrbisKernelMemoryPoolBlockStats)
? size
: sizeof(OrbisKernelMemoryPoolBlockStats);
// As of firmware 12.02, the kernel does not check if stats is null,
// this can cause crashes on real hardware, so have an assert for this case.
ASSERT_MSG(stats != nullptr || size == 0, "Block stats cannot be null");
std::memcpy(stats, &local_stats, size_to_copy);
return ORBIS_OK;
}
void* PS4_SYSV_ABI posix_mmap(void* addr, u64 len, s32 prot, s32 flags, s32 fd, s64 phys_addr) {
LOG_INFO(
Kernel_Vmm,
@@ -715,6 +732,7 @@ void RegisterMemory(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("Vzl66WmfLvk", "libkernel", 1, "libkernel", sceKernelMemoryPoolCommit);
LIB_FUNCTION("LXo1tpFqJGs", "libkernel", 1, "libkernel", sceKernelMemoryPoolDecommit);
LIB_FUNCTION("YN878uKRBbE", "libkernel", 1, "libkernel", sceKernelMemoryPoolBatch);
LIB_FUNCTION("bvD+95Q6asU", "libkernel", 1, "libkernel", sceKernelMemoryPoolGetBlockStats);
LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", posix_mmap);
LIB_FUNCTION("BPE9s9vQQXo", "libScePosix", 1, "libkernel", posix_mmap);

View File

@@ -126,6 +126,13 @@ struct OrbisKernelMemoryPoolBatchEntry {
};
};
struct OrbisKernelMemoryPoolBlockStats {
s32 available_flushed_blocks;
s32 available_cached_blocks;
s32 allocated_flushed_blocks;
s32 allocated_cached_blocks;
};
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize();
s32 PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
u64 alignment, s32 memoryType, s64* physAddrOut);
@@ -176,6 +183,7 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolCommit(void* addr, u64 len, s32 type, s32 pr
s32 PS4_SYSV_ABI sceKernelMemoryPoolDecommit(void* addr, u64 len, s32 flags);
s32 PS4_SYSV_ABI sceKernelMemoryPoolBatch(const OrbisKernelMemoryPoolBatchEntry* entries, s32 count,
s32* num_processed, s32 flags);
s32 PS4_SYSV_ABI sceKernelMemoryPoolGetBlockStats(OrbisKernelMemoryPoolBlockStats* stats, u64 size);
s32 PS4_SYSV_ABI sceKernelMunmap(void* addr, u64 len);