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 | |
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')
-rw-r--r-- | src/core/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_bitmap.h | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/k_system_control.cpp (renamed from src/core/hle/kernel/memory/system_control.cpp) | 13 | ||||
-rw-r--r-- | src/core/hle/kernel/k_system_control.h | 19 | ||||
-rw-r--r-- | src/core/hle/kernel/memory/page_table.cpp | 11 | ||||
-rw-r--r-- | src/core/hle/kernel/memory/system_control.h | 14 | ||||
-rw-r--r-- | src/core/hle/service/ldr/ldr.cpp | 4 |
7 files changed, 38 insertions, 31 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6604bc2c5..8aad9cb41 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -182,6 +182,8 @@ add_library(core STATIC hle/kernel/k_spin_lock.h hle/kernel/k_synchronization_object.cpp hle/kernel/k_synchronization_object.h + hle/kernel/k_system_control.cpp + hle/kernel/k_system_control.h hle/kernel/k_thread.cpp hle/kernel/k_thread.h hle/kernel/k_thread_queue.h @@ -204,8 +206,6 @@ add_library(core STATIC hle/kernel/memory/page_table.cpp hle/kernel/memory/page_table.h hle/kernel/memory/slab_heap.h - hle/kernel/memory/system_control.cpp - hle/kernel/memory/system_control.h hle/kernel/object.cpp hle/kernel/object.h hle/kernel/physical_core.cpp diff --git a/src/core/hle/kernel/k_page_bitmap.h b/src/core/hle/kernel/k_page_bitmap.h index da2d20032..c75d667c9 100644 --- a/src/core/hle/kernel/k_page_bitmap.h +++ b/src/core/hle/kernel/k_page_bitmap.h @@ -12,7 +12,7 @@ #include "common/bit_util.h" #include "common/common_types.h" #include "common/tiny_mt.h" -#include "core/hle/kernel/memory/system_control.h" +#include "core/hle/kernel/k_system_control.h" namespace Kernel { @@ -43,7 +43,7 @@ private: public: RandomBitGenerator() { - rng.Initialize(static_cast<u32>(Memory::SystemControl::GenerateRandomU64())); + rng.Initialize(static_cast<u32>(KSystemControl::GenerateRandomU64())); } std::size_t SelectRandomBit(u64 bitmap) { diff --git a/src/core/hle/kernel/memory/system_control.cpp b/src/core/hle/kernel/k_system_control.cpp index e855696ad..aa1682f69 100644 --- a/src/core/hle/kernel/memory/system_control.cpp +++ b/src/core/hle/kernel/k_system_control.cpp @@ -1,12 +1,13 @@ -// Copyright 2020 yuzu Emulator Project +// Copyright 2021 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" +#include "core/hle/kernel/k_system_control.h" + +namespace Kernel { -namespace Kernel::Memory::SystemControl { namespace { template <typename F> u64 GenerateUniformRange(u64 min, u64 max, F f) { @@ -27,15 +28,15 @@ u64 GenerateUniformRange(u64 min, u64 max, F f) { } // Anonymous namespace -u64 GenerateRandomU64() { +u64 KSystemControl::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) { +u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) { return GenerateUniformRange(min, max, GenerateRandomU64); } -} // namespace Kernel::Memory::SystemControl +} // namespace Kernel diff --git a/src/core/hle/kernel/k_system_control.h b/src/core/hle/kernel/k_system_control.h new file mode 100644 index 000000000..1d5b64ffa --- /dev/null +++ b/src/core/hle/kernel/k_system_control.h @@ -0,0 +1,19 @@ +// Copyright 2021 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 { + +class KSystemControl { +public: + KSystemControl() = default; + + static u64 GenerateRandomRange(u64 min, u64 max); + static u64 GenerateRandomU64(); +}; + +} // namespace Kernel 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.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 diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index c724d2554..d3cd25ff8 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -11,8 +11,8 @@ #include "common/scope_exit.h" #include "core/core.h" #include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/k_system_control.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/hle/service/ldr/ldr.h" @@ -315,7 +315,7 @@ public: Kernel::Memory::PageBits}; do { addr = page_table.GetAliasCodeRegionStart() + - (Kernel::Memory::SystemControl::GenerateRandomRange(0, end_pages) + (Kernel::KSystemControl::GenerateRandomRange(0, end_pages) << Kernel::Memory::PageBits); } while (!page_table.IsInsideAddressSpace(addr, size) || page_table.IsInsideHeapRegion(addr, size) || |