diff options
| author | lizzie <lizzie@eden-emu.dev> | 2025-11-04 22:35:34 +0100 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2025-11-04 22:35:34 +0100 |
| commit | 504df4856d85dba6c04a172f60259f9e71217d9e (patch) | |
| tree | 8b717a3a47bfeaeabaed86731984037fcc0f1e83 /src/core/hle/kernel/k_process.cpp | |
| parent | 6abaee94a61b1cc07cf1eab6cc838b908d6c0a5b (diff) | |
[core/loader] Implement a bit improper ASLR (#2945)
A bit improper of an ASLR - it does something but something good? Who knows...
All I know is that there is a non-uniform distrobution for rand() and that rng_seed is likely a better solution?
I don't know
Signed-off-by: lizzie lizzie@eden-emu.dev
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2945
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/core/hle/kernel/k_process.cpp')
| -rw-r--r-- | src/core/hle/kernel/k_process.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 355a2a5f3b..322f971ba3 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -28,9 +28,6 @@ namespace Kernel { namespace { -// TODO: Remove this workaround when proper ASLR is implemented for all address spaces. -constexpr u64 CodeStartOffset = 0x500000UL; - Result TerminateChildren(KernelCore& kernel, KProcess* process, const KThread* thread_to_not_terminate) { // Request that all children threads terminate. @@ -1157,7 +1154,7 @@ KProcess::KProcess(KernelCore& kernel) KProcess::~KProcess() = default; Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size, - KProcessAddress aslr_space_start, bool is_hbl) { + KProcessAddress aslr_space_start, size_t aslr_space_offset, bool is_hbl) { // Create a resource limit for the process. const auto pool = static_cast<KMemoryManager::Pool>(metadata.GetPoolPartition()); const auto physical_memory_size = m_kernel.MemoryManager().GetSize(pool); @@ -1187,25 +1184,24 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: // Set the address space type and code address. switch (metadata.GetAddressSpaceType()) { case FileSys::ProgramAddressSpaceType::Is39Bit: - flag |= Svc::CreateProcessFlag::AddressSpace64Bit; - // For 39-bit processes, the ASLR region starts at 0x800'0000 and is ~512GiB large. // However, some (buggy) programs/libraries like skyline incorrectly depend on the // existence of ASLR pages before the entry point, so we will adjust the load address // to point to about 2GiB into the ASLR region. - code_address = 0x8000'0000; + flag |= Svc::CreateProcessFlag::AddressSpace64Bit; + code_address = 0x8000'0000 + aslr_space_offset; break; case FileSys::ProgramAddressSpaceType::Is36Bit: flag |= Svc::CreateProcessFlag::AddressSpace64BitDeprecated; - code_address = 0x800'0000; + code_address = 0x800'0000 + aslr_space_offset; break; case FileSys::ProgramAddressSpaceType::Is32Bit: flag |= Svc::CreateProcessFlag::AddressSpace32Bit; - code_address = 0x20'0000 + CodeStartOffset; + code_address = 0x20'0000 + aslr_space_offset; break; case FileSys::ProgramAddressSpaceType::Is32BitNoMap: flag |= Svc::CreateProcessFlag::AddressSpace32BitWithoutAlias; - code_address = 0x20'0000 + CodeStartOffset; + code_address = 0x20'0000 + aslr_space_offset; break; } |
