kernel: Implement code address offset for Skyline compatibility

Add support for the Skyline 32-bit modding framework by implementing
a code address offset and improving memory state verification.

Changes:
- Add CodeStartOffset constant (0x500000) applied to 32-bit code
  address space types (Is32Bit and Is32BitNoMap) in KProcess::LoadFromMetadata
- Add debug logging for 32-bit syscall argument tracking in
  SetProcessMemoryPermission, MapProcessCodeMemory, and
  UnmapProcessCodeMemory wrapper functions
- Replace CheckMemoryStateContiguous with CheckMemoryState in
  KPageTableBase::UnmapCodeMemory for more flexible memory state
  verification

This implementation enables compatibility with:
- Skyline 32-bit modding framework
- CTGP-DX (Mario Kart 8 Deluxe mod)
- Other homebrew using 32-bit Skyline

Based on similar fixes in Ryujinx (commit 5e9678c8fe) and Eden emulator.

Co-authored-by: JPikachu <jpikachu.eden@gmail.com>
Co-authored-by: JPikachu <jpikachu@eden-emu.dev>
Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-11-01 15:44:21 +10:00
parent 5b3a7301a9
commit 76e963bfe7
3 changed files with 27 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <random>
@@ -25,6 +26,12 @@ namespace Kernel {
namespace {
// Code offset for 32-bit processes to ensure compatibility with Skyline modding framework.
// Skyline assumes memory exists before the entry point. This matches the approach used for
// 39-bit processes (which load at 0x8000'0000 instead of 0x800'0000 for the same reason).
// This can only be removed if Skyline is updated to not depend on pre-entry-point memory.
constexpr u64 CodeStartOffset = 0x500000UL;
Result TerminateChildren(KernelCore& kernel, KProcess* process,
const KThread* thread_to_not_terminate) {
// Request that all children threads terminate.
@@ -1195,11 +1202,11 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
break;
case FileSys::ProgramAddressSpaceType::Is32Bit:
flag |= Svc::CreateProcessFlag::AddressSpace32Bit;
code_address = 0x20'0000;
code_address = 0x20'0000 + CodeStartOffset;
break;
case FileSys::ProgramAddressSpaceType::Is32BitNoMap:
flag |= Svc::CreateProcessFlag::AddressSpace32BitWithoutAlias;
code_address = 0x20'0000;
code_address = 0x20'0000 + CodeStartOffset;
break;
}