Emulate sceKernelInternalMemory mapping (#2726)
Some checks are pending
Build and Release / macos-sdl (push) Blocked by required conditions
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-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

* Emulate sceKernelInternalMemory mapping

This fixes the early crash in CUSA07820 (The Last of Us™ Part II).

* Fix name
This commit is contained in:
Stephen Miller 2025-03-30 16:27:12 -05:00 committed by GitHub
parent f85d8df71e
commit 374b66ad8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -101,6 +101,17 @@ void Linker::Execute(const std::vector<std::string> args) {
memory->SetupMemoryRegions(fmem_size, use_extended_mem1, use_extended_mem2);
// Simulate sceKernelInternalMemory mapping, a mapping usually performed during libkernel init.
// Due to the large size of this mapping, failing to emulate it causes issues in some titles.
// This mapping belongs in the system reserved area, which starts at address 0x880000000.
static constexpr VAddr KernelAllocBase = 0x880000000ULL;
static constexpr s64 InternalMemorySize = 0x1000000;
void* addr_out{reinterpret_cast<void*>(KernelAllocBase)};
const s32 ret = Libraries::Kernel::sceKernelMapNamedFlexibleMemory(
&addr_out, InternalMemorySize, 3, 0, "SceKernelInternalMemory");
ASSERT_MSG(ret == 0, "Unable to perform sceKernelInternalMemory mapping");
main_thread.Run([this, module, args](std::stop_token) {
Common::SetCurrentThreadName("GAME_MainThread");
LoadSharedLibraries();
@ -372,7 +383,8 @@ void* Linker::AllocateTlsForThread(bool is_primary) {
// If sceKernelMapNamedFlexibleMemory is being called from libkernel and addr = 0
// it automatically places mappings in system reserved area instead of managed.
static constexpr VAddr KernelAllocBase = 0x880000000ULL;
// Since the system reserved area already has a mapping in it, this address is slightly higher.
static constexpr VAddr KernelAllocBase = 0x881000000ULL;
// The kernel module has a few different paths for TLS allocation.
// For SDK < 1.7 it allocates both main and secondary thread blocks using libc mspace/malloc.