Browse Source
[core] Finalize AliasRegionExtraSize (#291 )
The previous implementation was based on assumptions for the baseline.
The new implementation is based on calculations, and should be more robust for DRAM values beyond 8GB as well.
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/291
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: Shinmegumi <shinmegumi@eden-emu.dev>
Co-authored-by: SDK-Chan <sdkchan@eden-emu.dev>
Co-committed-by: SDK-Chan <sdkchan@eden-emu.dev>
pull/297/head
SDK-Chan
6 months ago
committed by
crueter
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
4 changed files with
35 additions and
14 deletions
src/core/hle/kernel/k_page_table_base.cpp
src/core/hle/kernel/k_page_table_base.h
src/core/hle/kernel/k_process_page_table.h
src/core/hle/kernel/svc_types.h
@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -290,6 +293,23 @@ Result KPageTableBase::InitializeForProcess(Svc::CreateProcessFlag as_type, bool
alloc_start = process_code_end ;
alloc_size = GetInteger ( end ) - GetInteger ( process_code_end ) ;
}
// FW 18+: Apply extra region size calculations for already available region size
const auto as_mask = Svc : : CreateProcessFlag : : AddressSpaceMask ;
const bool is_64bit_as = ( as_type & as_mask ) = = Svc : : CreateProcessFlag : : AddressSpace64Bit ;
if ( is_64bit_as & & ( as_type & Svc : : CreateProcessFlag : : EnableAliasRegionExtraSize )
! = Svc : : CreateProcessFlag { 0 } & & alias_region_size ) {
const size_t address_space_size = ( GetInteger ( end ) - GetInteger ( start ) ) ;
// Same as address_space_size/8 but faster due to bit shifting operation
const size_t alias_region_extra_size = address_space_size > > 3 ;
alias_region_size + = alias_region_extra_size ;
// Store for later processing
m_alias_region_extra_size = alias_region_extra_size ;
}
const size_t needed_size =
( alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size ) ;
R_UNLESS ( alloc_size > = needed_size , ResultOutOfMemory ) ;
@ -211,6 +211,7 @@ private:
size_t m_mapped_unsafe_physical_memory { } ;
size_t m_mapped_insecure_memory { } ;
size_t m_mapped_ipc_server_memory { } ;
size_t m_alias_region_extra_size { } ;
mutable KLightLock m_general_lock ;
mutable KLightLock m_map_physical_memory_lock ;
KLightLock m_device_map_lock ;
@ -698,6 +699,10 @@ public:
return m_alias_code_region_end - m_alias_code_region_start ;
}
size_t GetAliasRegionExtraSize ( ) const {
return m_alias_region_extra_size ;
}
size_t GetNormalMemorySize ( ) const {
/ / Lock the table .
KScopedLightLock lk ( m_general_lock ) ;
@ -718,17 +723,6 @@ public:
return m_address_space_width ;
}
size_t CalculateAliasRegionExtraSize ( ) const {
const size_t baseline = 64ull < < 30 ; / / Mostly appropriate for DRAM values < = 8 GB
const size_t region = GetAliasRegionSize ( ) ;
if ( region > baseline ) {
return region - baseline ;
}
return 0 ;
}
public :
/ / Linear mapped
static u8 * GetLinearMappedVirtualPointer ( KernelCore & kernel , KPhysicalAddress addr ) {
@ -414,7 +414,7 @@ public:
return m_page_table . GetAliasRegionSize ( ) ;
}
size_t GetAliasRegionExtraSize ( ) const {
return m_page_table . Calculate AliasRegionExtraSize( ) ;
return m_page_table . Get AliasRegionExtraSize( ) ;
}
size_t GetStackRegionSize ( ) const {
return m_page_table . GetStackRegionSize ( ) ;
@ -1,3 +1,6 @@
/ / SPDX - FileCopyrightText : Copyright 2025 Eden Emulator Project
/ / SPDX - License - Identifier : GPL - 3.0 - or - later
/ / SPDX - FileCopyrightText : Copyright 2020 yuzu Emulator Project
/ / SPDX - License - Identifier : GPL - 2.0 - or - later
@ -153,7 +156,7 @@ enum class InfoType : u32 {
ThreadTickCount = 25 ,
IsSvcPermitted = 26 ,
IoRegionHint = 27 ,
AliasRegionExtraSize = 28 ,
AliasRegionExtraSize = 28 ,
MesosphereMeta = 65000 ,
MesosphereCurrentProcess = 65001 ,
@ -643,9 +646,13 @@ enum class CreateProcessFlag : u32 {
/ / 11. x + DisableDeviceAddressSpaceMerge .
DisableDeviceAddressSpaceMerge = ( 1 < < 12 ) ,
/ / 18. x + Add extra size to the already available AliasRegionSize
EnableAliasRegionExtraSize = ( 1 < < 13 ) ,
/ / Mask of all flags .
All = Is64Bit | AddressSpaceMask | EnableDebug | EnableAslr | IsApplication |
PoolPartitionMask | OptimizeMemoryAllocation | DisableDeviceAddressSpaceMerge ,
PoolPartitionMask | OptimizeMemoryAllocation | DisableDeviceAddressSpaceMerge |
EnableAliasRegionExtraSize ,
} ;
DECLARE_ENUM_FLAG_OPERATORS ( CreateProcessFlag ) ;