diff options
author | bunnei <bunneidev@gmail.com> | 2021-02-12 03:55:22 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-02-19 01:16:24 +0100 |
commit | f7a008d77f8aa47baf4c874c508b38af4965a145 (patch) | |
tree | 3a11b865d5f49be8fa0588ee5187f1b6c12022fb /src/core/hle/kernel/memory | |
parent | hle: kernel: memory: PageHeap: Migrate to KPageBitmap class. (diff) | |
download | yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.tar yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.tar.gz yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.tar.bz2 yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.tar.lz yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.tar.xz yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.tar.zst yuzu-f7a008d77f8aa47baf4c874c508b38af4965a145.zip |
Diffstat (limited to 'src/core/hle/kernel/memory')
-rw-r--r-- | src/core/hle/kernel/memory/page_table.cpp | 11 | ||||
-rw-r--r-- | src/core/hle/kernel/memory/system_control.cpp | 41 | ||||
-rw-r--r-- | src/core/hle/kernel/memory/system_control.h | 14 |
3 files changed, 6 insertions, 60 deletions
diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp index 00ed9b881..034d43ecd 100644 --- a/src/core/hle/kernel/memory/page_table.cpp +++ b/src/core/hle/kernel/memory/page_table.cpp @@ -6,14 +6,15 @@ #include "common/assert.h" #include "common/scope_exit.h" #include "core/core.h" +#include "core/hle/kernel/k_resource_limit.h" #include "core/hle/kernel/k_scoped_resource_reservation.h" +#include "core/hle/kernel/k_system_control.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/memory/address_space_info.h" #include "core/hle/kernel/memory/memory_block.h" #include "core/hle/kernel/memory/memory_block_manager.h" #include "core/hle/kernel/memory/page_linked_list.h" #include "core/hle/kernel/memory/page_table.h" -#include "core/hle/kernel/memory/system_control.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/svc_results.h" #include "core/memory.h" @@ -149,13 +150,13 @@ ResultCode PageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_t // Determine random placements for each region std::size_t alias_rnd{}, heap_rnd{}, stack_rnd{}, kmap_rnd{}; if (enable_aslr) { - alias_rnd = SystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * + alias_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment; - heap_rnd = SystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * + heap_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment; - stack_rnd = SystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * + stack_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment; - kmap_rnd = SystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * + kmap_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment; } diff --git a/src/core/hle/kernel/memory/system_control.cpp b/src/core/hle/kernel/memory/system_control.cpp deleted file mode 100644 index e855696ad..000000000 --- a/src/core/hle/kernel/memory/system_control.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2020 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include <random> - -#include "core/hle/kernel/memory/system_control.h" - -namespace Kernel::Memory::SystemControl { -namespace { -template <typename F> -u64 GenerateUniformRange(u64 min, u64 max, F f) { - // Handle the case where the difference is too large to represent. - if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) { - return f(); - } - - // Iterate until we get a value in range. - const u64 range_size = ((max + 1) - min); - const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size; - while (true) { - if (const u64 rnd = f(); rnd < effective_max) { - return min + (rnd % range_size); - } - } -} - -} // Anonymous namespace - -u64 GenerateRandomU64() { - static std::random_device device; - static std::mt19937 gen(device()); - static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); - return distribution(gen); -} - -u64 GenerateRandomRange(u64 min, u64 max) { - return GenerateUniformRange(min, max, GenerateRandomU64); -} - -} // namespace Kernel::Memory::SystemControl diff --git a/src/core/hle/kernel/memory/system_control.h b/src/core/hle/kernel/memory/system_control.h deleted file mode 100644 index a01b6b014..000000000 --- a/src/core/hle/kernel/memory/system_control.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2020 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "common/common_types.h" - -namespace Kernel::Memory::SystemControl { - -u64 GenerateRandomRange(u64 min, u64 max); -u64 GenerateRandomU64(); - -} // namespace Kernel::Memory::SystemControl |