Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
77293cf
feat(relinker): hint at the MinGW runtime DLLs when a module fails to…
omurc4 Oct 13, 2026
17fc95c
fix(relinker): share guest modules between executables that need diff…
SandstromPL Oct 13, 2026
3d83482
feat(libc): implement swprintf_s
mohammad-alosta Oct 13, 2026
09a9e30
feat(tools): unwrap decrypted SELF containers into clean ELF
ryyReid Oct 14, 2026
a6f9436
feat(libkernel): export sceKernelGetSocPowerConsumption
babyhuey Oct 14, 2026
3a6e515
feat(libc): implement wcsnlen_s
Feuris Oct 14, 2026
3e08bbe
feat(libkernel): support fixed anonymous mmap
Dripl1x Oct 14, 2026
900c36a
feat(libkernel): implement setpriority
Nixitov Oct 13, 2026
9efa82d
feat(libkernel): count committed ranges in sceKernelGetPageTableStats
Oct 12, 2026
fea2f02
perf(relinker): stream scans and reuse executable buffers
sanxchep Oct 13, 2026
29b110d
feat(libkernel): map regular files with mmap on Linux
YossiYad Oct 13, 2026
b453536
test(libkernel): cover shared and private mappings of a regular file
YossiYad Oct 13, 2026
aafb249
docs(debt): note regular file mappings of mmap
YossiYad Oct 13, 2026
20ec58d
feat(libkernel): report RLIMIT_NOFILE through getrlimit
Oct 13, 2026
659c302
feat(libkernel): stop at start-up on a host CPU without the PS5's ext…
oneandonlydean Oct 14, 2026
199ff41
feat(libkernel): implement sysctlnametomib for the sysctl names AnyPS…
ahmad3a4 Oct 13, 2026
89dea3a
feat(relinker): report every unresolved ELF import before failing on …
tibzejoker Oct 13, 2026
f767809
feat(libc): implement fegetenv
karimibrahim07 Oct 13, 2026
9cce566
test(libc): cover fegetenv with a null environment and pending x87 flags
karimibrahim07 Oct 13, 2026
dac1976
refactor(libc): move fegetenv and its test out of the lines #5495 cha…
karimibrahim07 Oct 14, 2026
41caef7
docs(libc): move the fegetenv debt line off the end of its section
adriadam10 Oct 14, 2026
7aeca28
docs(debt): port the getrlimit, hw.model, host CPU check and fegetenv…
RINNECODER Oct 14, 2026
ed06a35
docs(debt): keep title names out of the ported debt lines
RINNECODER Oct 14, 2026
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ if(BUILD_TESTING)
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_progress_encoding.py)
add_test(NAME import_audit COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_import_audit.py)
add_test(NAME unwrap_self COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_unwrap_self.py)
add_test(NAME conventions_function_bodies COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_check_conventions_comments.py)
add_test(NAME test_registration COMMAND ${Python3_EXECUTABLE}
Expand Down
57 changes: 57 additions & 0 deletions core/libs/prx/libc/src/FormattingWide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,63 @@ int APS5_VABI snwprintf_s_nid_postfix(char16_t* buffer, std::size_t size, const
return result;
}

int APS5_VABI vswprintf_s_nid_postfix(char16_t* buffer, std::size_t size, const char16_t* format, VaList* args) {
constexpr std::size_t RsizeMax = (SIZE_MAX >> 1) / sizeof(char16_t);
int result = -1;
if (buffer != nullptr && format != nullptr && args != nullptr && size != 0 && size <= RsizeMax) {
try {
const std::u16string text = FormatWide(format, args, true);
if (text.size() + 1 <= size && text.size() <= static_cast<std::size_t>(INT_MAX)) {
std::memcpy(buffer, text.data(), text.size() * sizeof(char16_t));
buffer[text.size()] = 0;
result = static_cast<int>(text.size());
}
} catch (const std::invalid_argument&) {
}
}
if (result < 0 && buffer != nullptr && size != 0 && size <= RsizeMax) buffer[0] = 0;
return result;
}

int APS5_VABI swprintf_s_nid_postfix(char16_t* buffer, std::size_t size, const char16_t* format, ...) {
constexpr std::size_t RsizeMax = (SIZE_MAX >> 1) / sizeof(char16_t);
int result = -1;
if (buffer != nullptr && format != nullptr && size != 0 && size <= RsizeMax) {
APS5_VA_BEGIN(format);
try {
const std::u16string text = FormatWide(format, reinterpret_cast<VaList*>(args), true);
if (text.size() + 1 <= size && text.size() <= static_cast<std::size_t>(INT_MAX)) {
std::memcpy(buffer, text.data(), text.size() * sizeof(char16_t));
buffer[text.size()] = 0;
result = static_cast<int>(text.size());
}
} catch (const std::invalid_argument&) {
}
APS5_VA_END();
}
if (result < 0 && buffer != nullptr && size != 0 && size <= RsizeMax) buffer[0] = 0;
return result;
}

int APS5_VABI vsnwprintf_s_nid_postfix(char16_t* buffer, std::size_t size, const char16_t* format, VaList* args) {
constexpr std::size_t RsizeMax = (SIZE_MAX >> 1) / sizeof(char16_t);
int result = -1;
if (buffer != nullptr && format != nullptr && args != nullptr && size != 0 && size <= RsizeMax) {
try {
const std::u16string text = FormatWide(format, args, true);
if (text.size() <= static_cast<std::size_t>(INT_MAX)) {
const std::size_t copied = text.size() < size - 1 ? text.size() : size - 1;
std::memcpy(buffer, text.data(), copied * sizeof(char16_t));
buffer[copied] = 0;
result = static_cast<int>(text.size());
}
} catch (const std::invalid_argument&) {
}
}
if (result < 0 && buffer != nullptr && size != 0 && size <= RsizeMax) buffer[0] = 0;
return result;
}

int APS5_VABI wprintf_nid_postfix(const char16_t* format, ...) {
APS5_VA_BEGIN(format);
int result = -1;
Expand Down
18 changes: 18 additions & 0 deletions core/libs/prx/libc/src/Math.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mutex>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <cerrno>
#include <cfenv>
Expand All @@ -9,6 +10,7 @@
#include <cstring>
#include <limits>
#include <stdexcept>
#include <xmmintrin.h>

#include "prx/libc/include/General.hpp"
#include "prx/libc/include/SonyCrt.hpp"
Expand Down Expand Up @@ -534,6 +536,22 @@ int APS5_VABI _Fltrounds_nid_postfix(void) {
return SonyFltrounds();
}

struct GuestFloatingPointEnvironment {
std::uint32_t control;
std::uint32_t status;
std::uint32_t tag;
unsigned char other[16];
std::uint32_t mxcsr;
};
static_assert(sizeof(GuestFloatingPointEnvironment) == 32 && offsetof(GuestFloatingPointEnvironment, mxcsr) == 28);

int APS5_VABI fegetenv_nid_postfix(GuestFloatingPointEnvironment* environment) {
if (environment == nullptr) throw std::invalid_argument("fegetenv: null environment");
asm volatile("fnstenv %0\n\tfldcw %0" : "+m"(*environment));
environment->mxcsr = _mm_getcsr();
return 0;
}

union SonyDconst {
unsigned short _Word[8];
float _Float;
Expand Down
7 changes: 7 additions & 0 deletions core/libs/prx/libc/src/Strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ size_t APS5_VABI wcslen_nid_postfix(const char16_t* s) {
return Length(s);
}

size_t APS5_VABI wcsnlen_s_nid_postfix(const char16_t* s, size_t maxlen) {
if (!s) return 0;
size_t length = 0;
while (length < maxlen && s[length] != 0) ++length;
return length;
}

int APS5_VABI wcscmp_nid_postfix(const char16_t* s1, const char16_t* s2) {
for (; *s1 == *s2; ++s1, ++s2) {
if (*s1 == 0) return 0;
Expand Down
22 changes: 21 additions & 1 deletion core/libs/prx/libkernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_library(libkernel SHARED EXCLUDE_FROM_ALL
${CMAKE_CURRENT_SOURCE_DIR}/System/src/Rtld.cpp
${CMAKE_CURRENT_SOURCE_DIR}/System/src/Process.cpp
${CMAKE_CURRENT_SOURCE_DIR}/System/src/Sandbox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/System/src/HostCpu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/System/src/SystemConfiguration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/System/src/Login.cpp
${CMAKE_CURRENT_SOURCE_DIR}/System/src/SoftwareVersion.cpp
Expand Down Expand Up @@ -971,6 +972,15 @@ if(BUILD_TESTING)
set_tests_properties(guest_jit_shared_memory PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
endif()
add_test_executable(host_cpu_tests ${LIBS_INCLUDE_DIR}/tests/HostCpu.cpp)
target_include_directories(host_cpu_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(host_cpu_tests PRIVATE libkernel libc)
configure_windows_unwind(host_cpu_tests)
add_test(NAME host_cpu COMMAND host_cpu_tests)
if(WIN32)
set_tests_properties(host_cpu PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
endif()
add_test_executable(guest_system_configuration_tests ${LIBS_INCLUDE_DIR}/tests/GuestSystemConfiguration.cpp)
target_include_directories(guest_system_configuration_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_system_configuration_tests PRIVATE libkernel libc)
Expand Down Expand Up @@ -1167,8 +1177,9 @@ if(BUILD_TESTING)
add_dependencies(guest_memory_tests guest_memory_module)
target_compile_definitions(guest_memory_tests PRIVATE GUEST_MEMORY_MODULE="$<TARGET_FILE:guest_memory_module>")
add_test(NAME guest_memory COMMAND guest_memory_tests)
add_test(NAME guest_mmap_fixed_anonymous COMMAND guest_memory_tests fixed-anonymous)
if(WIN32)
set_tests_properties(guest_memory PROPERTIES ENVIRONMENT_MODIFICATION
set_tests_properties(guest_memory guest_mmap_fixed_anonymous PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
endif()
add_test_executable(guest_flexible_memory_budget_tests ${LIBS_INCLUDE_DIR}/tests/GuestFlexibleMemoryBudget.cpp)
Expand Down Expand Up @@ -1200,6 +1211,15 @@ if(BUILD_TESTING)
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
endif()
endforeach()
add_test_executable(guest_page_table_stats_tests ${LIBS_INCLUDE_DIR}/tests/GuestPageTableStats.cpp)
target_include_directories(guest_page_table_stats_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_page_table_stats_tests PRIVATE libkernel libc)
configure_windows_unwind(guest_page_table_stats_tests)
add_test(NAME guest_page_table_stats COMMAND guest_page_table_stats_tests)
if(WIN32)
set_tests_properties(guest_page_table_stats PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
endif()
add_test_executable(guest_mlock_tests ${LIBS_INCLUDE_DIR}/tests/GuestMlock.cpp)
target_include_directories(guest_mlock_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_mlock_tests PRIVATE libkernel libc)
Expand Down
17 changes: 16 additions & 1 deletion core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,13 +1012,14 @@ int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart,
return 0;
}

int DoMapAnon(void** addr, size_t len, int prot, int flags, size_t alignment) {
int DoMapAnon(void** addr, size_t len, int prot, int flags, size_t alignment, bool exclusive) {
ValidateOutput(addr);
#if defined(__APPLE__)
if (!DarwinRelocateFixed(addr, len, flags)) return SCE_KERNEL_ERROR_ENOMEM;
#endif
if (len == 0 || (len & (PS5_PAGE_SIZE - 1)) != 0) return SCE_KERNEL_ERROR_EINVAL;
GuestAllocations::Mutation mutation;
if (exclusive && mutation.Overlaps(*addr, len)) return SCE_KERNEL_ERROR_ENOMEM;
flags = PlaceHintInReservation(*addr, len, flags);
if (FixedNoOverwriteConflict(mutation, *addr, len, flags)) return SCE_KERNEL_ERROR_ENOMEM;
if (RemapFixedIntoRegistered(mutation, *addr, len, prot, flags)) {
Expand Down Expand Up @@ -1292,6 +1293,20 @@ bool GuestProtection(uintptr_t addr, int* prot) {
return true;
}

void GuestPageTableUsage(std::uint64_t granularity, std::uint64_t* cpuEntries, std::uint64_t* gpuEntries) {
std::uint64_t cpu = 0;
std::uint64_t gpu = 0;
std::lock_guard lock(g_protectionLock);
for (const auto& [start, range] : g_protections) {
if (range.end <= start) continue;
const auto entries = (range.end - 1) / granularity - start / granularity + 1;
if (range.prot & 0x7) cpu += entries;
if (range.prot & GuestProtGpuReadWrite) gpu += entries;
}
*cpuEntries = cpu;
*gpuEntries = gpu;
}

bool QueryDirectMapping(std::uintptr_t address, std::uintptr_t* start, std::uintptr_t* end, std::uint64_t* offset, int* memoryType) {
std::lock_guard lock(g_directLock);
const auto next = g_directMappings.upper_bound(address);
Expand Down
3 changes: 2 additions & 1 deletion core/libs/prx/libkernel/DirectMemory/DirectMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void DirectMemoryRetype(int64_t start, size_t len, int memoryType);
bool DirectMemoryLargestFree(int64_t searchStart, int64_t searchEnd, size_t alignment, int64_t* startOut, size_t* sizeOut);
size_t DirectMemoryFreeRun(uint64_t offset, uint64_t limit);
int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart, size_t alignment);
int DoMapAnon(void** addr, size_t len, int prot, int flags, size_t alignment = PS5_PAGE_SIZE);
int DoMapAnon(void** addr, size_t len, int prot, int flags, size_t alignment = PS5_PAGE_SIZE, bool exclusive = false);
int DoMapFileBacked_nid_no_patch(void** addr, size_t len, int prot, int flags, int descriptor, std::uint64_t offset, size_t alignment);
int DoMapShared(void** addr, size_t len, int prot, HostSharedMemory object);
int DoMprotect(const void* addr, size_t len, int prot);
Expand All @@ -51,5 +51,6 @@ bool GuestReservation(std::uintptr_t addr, std::uintptr_t* start, std::uintptr_t
bool GuestRangeMapped(std::uintptr_t start, std::uintptr_t end);
void ForgetJitSharedMemory(int descriptor);
void DuplicateJitSharedMemory(int from, int to);
void GuestPageTableUsage(std::uint64_t granularity, std::uint64_t* cpu_entries, std::uint64_t* gpu_entries);

#endif
14 changes: 9 additions & 5 deletions core/libs/prx/libkernel/DirectMemory/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,15 @@ int APS5_VABI sceKernelClearVirtualRangeName(const void* addr, uint64_t len) {

int APS5_VABI sceKernelGetPageTableStats(int* cpu_total, int* cpu_available, int* gpu_total, int* gpu_available) {
if (!cpu_total || !cpu_available || !gpu_total || !gpu_available) return SCE_KERNEL_ERROR_EFAULT;
constexpr int pageTableEntries = static_cast<int>((4ull << 30) / (2ull << 20));
*cpu_total = pageTableEntries;
*cpu_available = pageTableEntries;
*gpu_total = pageTableEntries;
*gpu_available = pageTableEntries;
constexpr std::uint64_t PageTableGranularity = 2ULL * 1024 * 1024;
constexpr std::uint64_t PageTablePoolEntries = 2048;
std::uint64_t cpuUsed = 0;
std::uint64_t gpuUsed = 0;
GuestPageTableUsage(PageTableGranularity, &cpuUsed, &gpuUsed);
*cpu_total = static_cast<int>(PageTablePoolEntries);
*gpu_total = static_cast<int>(PageTablePoolEntries);
*cpu_available = static_cast<int>(cpuUsed >= PageTablePoolEntries ? 0 : PageTablePoolEntries - cpuUsed);
*gpu_available = static_cast<int>(gpuUsed >= PageTablePoolEntries ? 0 : PageTablePoolEntries - gpuUsed);
return 0;
}

Expand Down
28 changes: 24 additions & 4 deletions core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "SceTypes.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include "prx/libc/include/General.hpp"
#include "prx/libc/include/GuestArena.hpp"
#include "prx/libkernel/File/include/SharedMemory.hpp"
#include <limits>
#include <cerrno>
Expand All @@ -10,6 +11,7 @@
#include <system_error>
#if defined(__linux__)
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#endif

Expand All @@ -30,6 +32,7 @@ constexpr int GuestShared = 0x1;
constexpr int GuestPrivate = 0x2;
constexpr int GuestAnonymous = 0x1000;
constexpr int GuestMapFixed = 0x10;
constexpr int GuestMapExclusive = 0x4000;
constexpr int GuestMapNoOverwrite = 0x80;
constexpr int GuestMapNoCoalesce = 0x400000;
constexpr int GuestSyncAsync = 0x1;
Expand Down Expand Up @@ -59,6 +62,11 @@ class ScopedDescriptor {
int descriptor = -1;
int error = 0;
};

bool RegularFile(int descriptor) {
struct stat status{};
return ::fstat(descriptor, &status) == 0 && S_ISREG(status.st_mode);
}
#endif

bool RoundLength(std::size_t length, std::size_t& rounded) {
Expand Down Expand Up @@ -90,14 +98,26 @@ void* APS5_VABI mmap_nid_postfix(void* address, std::size_t length, int protecti
std::size_t rounded;
if (!RoundLength(length, rounded) || (protection & ~7) != 0)
return failed(GuestInvalid);
if ((flags & (GuestMapExclusive | GuestMapFixed)) == GuestMapExclusive) return failed(GuestInvalid);
const int mappingFlags = flags & ~GuestAlignedSuper;
if (mappingFlags == (GuestPrivate | GuestAnonymous)) {
const bool fixedAnonymous = (mappingFlags & ~(GuestMapFixed | GuestMapExclusive)) == (GuestPrivate | GuestAnonymous)
&& (mappingFlags & GuestMapFixed) != 0;
if (mappingFlags == (GuestPrivate | GuestAnonymous) || fixedAnonymous) {
if (descriptor != -1 || offset != 0) return failed(GuestInvalid);
void* mapped = nullptr;
const auto start = reinterpret_cast<std::uintptr_t>(address);
if (fixedAnonymous && ((start & (PS5_PAGE_SIZE - 1)) != 0 ||
rounded > std::numeric_limits<std::uintptr_t>::max() - start ||
!GuestArena::GuestArenaContains_nid_postfix(address, rounded))) return failed(GuestInvalid);
const bool exclusive = fixedAnonymous && (mappingFlags & GuestMapExclusive) != 0;
const int placement = fixedAnonymous ? GuestMapFixed | (exclusive ? GuestMapNoOverwrite : 0) : 0;
void* mapped = fixedAnonymous ? address : nullptr;
const auto alignment = !fixedAnonymous && (flags & GuestAlignedSuper) != 0 ? SuperpageSize : PS5_PAGE_SIZE;
try {
const auto result = DoMapAnon(&mapped, rounded, protection, 0, (flags & GuestAlignedSuper) != 0 ? SuperpageSize : PS5_PAGE_SIZE);
const auto result = DoMapAnon(&mapped, rounded, protection, placement, alignment, exclusive);
if (result != 0) return failed(GuestNoMemory);
return mapped;
} catch (const std::invalid_argument&) {
return failed(fixedAnonymous ? GuestInvalid : GuestNoMemory);
} catch (const std::bad_alloc&) {
return failed(GuestNoMemory);
} catch (const std::exception&) {
Expand All @@ -124,7 +144,7 @@ void* APS5_VABI mmap_nid_postfix(void* address, std::size_t length, int protecti
const int accessMode = descriptorFlags & O_ACCMODE;
if ((protection & 1) != 0 && accessMode == O_WRONLY) return failed(GuestAccess);
if (kind == GuestShared && (protection & 2) != 0 && accessMode == O_RDONLY) return failed(GuestAccess);
if (!File::IsSharedMemoryDescriptor_nid_no_patch(mappingDescriptor)) return failed(GuestNotSupported);
if (!File::IsSharedMemoryDescriptor_nid_no_patch(mappingDescriptor) && !RegularFile(mappingDescriptor)) return failed(GuestNotSupported);
#else
const int mappingDescriptor = descriptor;
if (!File::IsSharedMemoryDescriptor_nid_no_patch(mappingDescriptor)) return failed(GuestNotSupported);
Expand Down
31 changes: 31 additions & 0 deletions core/libs/prx/libkernel/System/include/HostCpu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef CORE_LIBS_PRX_LIBKERNEL_SYSTEM_HOSTCPU_HPP
#define CORE_LIBS_PRX_LIBKERNEL_SYSTEM_HOSTCPU_HPP

#include <cstdint>
#include <string>
#include <vector>

struct HostCpuRegisters {
std::uint32_t Leaf1Ecx = 0;
std::uint32_t Leaf1Edx = 0;
std::uint32_t Leaf7Ebx = 0;
std::uint32_t Leaf7Ecx = 0;
std::uint32_t LeafDSub1Eax = 0;
std::uint32_t Leaf80000001Ecx = 0;
std::uint32_t Leaf80000008Ebx = 0;
std::uint64_t Xcr0 = 0;
};

struct HostCpuFeature {
const char* Name;
bool Required;
bool Present;
};

HostCpuRegisters ReadHostCpuRegisters();
std::string HostCpuModel();
std::vector<HostCpuFeature> HostCpuFeatures(const HostCpuRegisters& registers);
std::vector<std::string> MissingHostCpuFeatures(const HostCpuRegisters& registers);
void CheckHostCpu(const HostCpuRegisters& registers, const std::string& model);

#endif
Loading
Loading