mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-22 20:03:42 +00:00
Merge pull request 'kernel: Implement code address offset for Skyline compatibility' (#10) from kernel/skyline-32bit-code-offset into main
Reviewed-on: https://git.citron-emu.org/Citron/Emulator/pulls/10
This commit is contained in:
@@ -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 "common/scope_exit.h"
|
||||
@@ -1274,7 +1275,7 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
|
||||
|
||||
// Verify that the destination memory is aliasable code.
|
||||
size_t num_dst_allocator_blocks;
|
||||
R_TRY(this->CheckMemoryStateContiguous(
|
||||
R_TRY(this->CheckMemoryState(
|
||||
std::addressof(num_dst_allocator_blocks), dst_address, size, KMemoryState::FlagCanCodeAlias,
|
||||
KMemoryState::FlagCanCodeAlias, KMemoryPermission::None, KMemoryPermission::None,
|
||||
KMemoryAttribute::All & ~KMemoryAttribute::PermissionLocked, KMemoryAttribute::None));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
// This file is automatically generated using svc_generator.py.
|
||||
@@ -1825,6 +1826,10 @@ static void SvcWrap_SetProcessMemoryPermission64From32(Core::System& system, std
|
||||
uint64_t size{};
|
||||
MemoryPermission perm{};
|
||||
|
||||
LOG_DEBUG(Kernel_SVC, "Raw args, [0]={:#x} [1]={:#x} [2]={:#x} [3]={:#x} [4]={:#x} [5]={:#x}",
|
||||
GetArg32(args, 0), GetArg32(args, 1), GetArg32(args, 2),
|
||||
GetArg32(args, 3), GetArg32(args, 4), GetArg32(args, 5));
|
||||
|
||||
process_handle = Convert<Handle>(GetArg32(args, 0));
|
||||
std::array<uint32_t, 2> address_gather{};
|
||||
address_gather[0] = GetArg32(args, 2);
|
||||
@@ -1912,6 +1917,10 @@ static void SvcWrap_MapProcessCodeMemory64From32(Core::System& system, std::span
|
||||
uint64_t src_address{};
|
||||
uint64_t size{};
|
||||
|
||||
LOG_DEBUG(Kernel_SVC, "Raw args, [0]={:#x} [1]={:#x} [2]={:#x} [3]={:#x} [4]={:#x} [5]={:#x} [6]={:#x}",
|
||||
GetArg32(args, 0), GetArg32(args, 1), GetArg32(args, 2),
|
||||
GetArg32(args, 3), GetArg32(args, 4), GetArg32(args, 5), GetArg32(args, 6));
|
||||
|
||||
process_handle = Convert<Handle>(GetArg32(args, 0));
|
||||
std::array<uint32_t, 2> dst_address_gather{};
|
||||
dst_address_gather[0] = GetArg32(args, 2);
|
||||
@@ -1939,6 +1948,10 @@ static void SvcWrap_UnmapProcessCodeMemory64From32(Core::System& system, std::sp
|
||||
uint64_t src_address{};
|
||||
uint64_t size{};
|
||||
|
||||
LOG_DEBUG(Kernel_SVC, "Raw args, [0]={:#x} [1]={:#x} [2]={:#x} [3]={:#x} [4]={:#x} [5]={:#x} [6]={:#x}",
|
||||
GetArg32(args, 0), GetArg32(args, 1), GetArg32(args, 2),
|
||||
GetArg32(args, 3), GetArg32(args, 4), GetArg32(args, 5), GetArg32(args, 6));
|
||||
|
||||
process_handle = Convert<Handle>(GetArg32(args, 0));
|
||||
std::array<uint32_t, 2> dst_address_gather{};
|
||||
dst_address_gather[0] = GetArg32(args, 2);
|
||||
@@ -1953,6 +1966,9 @@ static void SvcWrap_UnmapProcessCodeMemory64From32(Core::System& system, std::sp
|
||||
size_gather[1] = GetArg32(args, 6);
|
||||
size = Convert<uint64_t>(size_gather);
|
||||
|
||||
LOG_DEBUG(Kernel_SVC, "Reconstructed, handle={:#x} dst={:#x} src={:#x} size={:#x}",
|
||||
process_handle, dst_address, src_address, size);
|
||||
|
||||
ret = UnmapProcessCodeMemory64From32(system, process_handle, dst_address, src_address, size);
|
||||
|
||||
SetArg32(args, 0, Convert<uint32_t>(ret));
|
||||
|
||||
Reference in New Issue
Block a user