summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-03-04 16:30:17 -0500
committerGravatar Lioncash2019-03-04 16:32:03 -0500
commit0be8fffc992e30da42004b4e640b7095e1040f53 (patch)
treed9827c3b2549658e220ee5bf78f26b6e021e83dc /src
parentMerge pull request #2165 from ReinUsesLisp/unbind-tex (diff)
downloadyuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.gz
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.xz
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.zip
svc: Migrate address range checking functions to VMManager
Provides a bit of a more proper interface for these functions.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/svc.cpp25
-rw-r--r--src/core/hle/kernel/vm_manager.cpp22
-rw-r--r--src/core/hle/kernel/vm_manager.h6
3 files changed, 30 insertions, 23 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index c5d399bab..223d717e2 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -47,23 +47,6 @@ constexpr bool IsValidAddressRange(VAddr address, u64 size) {
47 return address + size > address; 47 return address + size > address;
48} 48}
49 49
50// Checks if a given address range lies within a larger address range.
51constexpr bool IsInsideAddressRange(VAddr address, u64 size, VAddr address_range_begin,
52 VAddr address_range_end) {
53 const VAddr end_address = address + size - 1;
54 return address_range_begin <= address && end_address <= address_range_end - 1;
55}
56
57bool IsInsideAddressSpace(const VMManager& vm, VAddr address, u64 size) {
58 return IsInsideAddressRange(address, size, vm.GetAddressSpaceBaseAddress(),
59 vm.GetAddressSpaceEndAddress());
60}
61
62bool IsInsideNewMapRegion(const VMManager& vm, VAddr address, u64 size) {
63 return IsInsideAddressRange(address, size, vm.GetNewMapRegionBaseAddress(),
64 vm.GetNewMapRegionEndAddress());
65}
66
67// 8 GiB 50// 8 GiB
68constexpr u64 MAIN_MEMORY_SIZE = 0x200000000; 51constexpr u64 MAIN_MEMORY_SIZE = 0x200000000;
69 52
@@ -105,14 +88,14 @@ ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_add
105 return ERR_INVALID_ADDRESS_STATE; 88 return ERR_INVALID_ADDRESS_STATE;
106 } 89 }
107 90
108 if (!IsInsideAddressSpace(vm_manager, src_addr, size)) { 91 if (!vm_manager.IsWithinAddressSpace(src_addr, size)) {
109 LOG_ERROR(Kernel_SVC, 92 LOG_ERROR(Kernel_SVC,
110 "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", 93 "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}",
111 src_addr, size); 94 src_addr, size);
112 return ERR_INVALID_ADDRESS_STATE; 95 return ERR_INVALID_ADDRESS_STATE;
113 } 96 }
114 97
115 if (!IsInsideNewMapRegion(vm_manager, dst_addr, size)) { 98 if (!vm_manager.IsWithinNewMapRegion(dst_addr, size)) {
116 LOG_ERROR(Kernel_SVC, 99 LOG_ERROR(Kernel_SVC,
117 "Destination is not within the new map region, addr=0x{:016X}, size=0x{:016X}", 100 "Destination is not within the new map region, addr=0x{:016X}, size=0x{:016X}",
118 dst_addr, size); 101 dst_addr, size);
@@ -238,7 +221,7 @@ static ResultCode SetMemoryPermission(VAddr addr, u64 size, u32 prot) {
238 auto* const current_process = Core::CurrentProcess(); 221 auto* const current_process = Core::CurrentProcess();
239 auto& vm_manager = current_process->VMManager(); 222 auto& vm_manager = current_process->VMManager();
240 223
241 if (!IsInsideAddressSpace(vm_manager, addr, size)) { 224 if (!vm_manager.IsWithinAddressSpace(addr, size)) {
242 LOG_ERROR(Kernel_SVC, 225 LOG_ERROR(Kernel_SVC,
243 "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, 226 "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,
244 size); 227 size);
@@ -299,7 +282,7 @@ static ResultCode SetMemoryAttribute(VAddr address, u64 size, u32 mask, u32 attr
299 } 282 }
300 283
301 auto& vm_manager = Core::CurrentProcess()->VMManager(); 284 auto& vm_manager = Core::CurrentProcess()->VMManager();
302 if (!IsInsideAddressSpace(vm_manager, address, size)) { 285 if (!vm_manager.IsWithinAddressSpace(address, size)) {
303 LOG_ERROR(Kernel_SVC, 286 LOG_ERROR(Kernel_SVC,
304 "Given address (0x{:016X}) is outside the bounds of the address space.", address); 287 "Given address (0x{:016X}) is outside the bounds of the address space.", address);
305 return ERR_INVALID_ADDRESS_STATE; 288 return ERR_INVALID_ADDRESS_STATE;
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 10ad94aa6..56f3d1f79 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -17,8 +17,8 @@
17#include "core/memory_setup.h" 17#include "core/memory_setup.h"
18 18
19namespace Kernel { 19namespace Kernel {
20 20namespace {
21static const char* GetMemoryStateName(MemoryState state) { 21const char* GetMemoryStateName(MemoryState state) {
22 static constexpr const char* names[] = { 22 static constexpr const char* names[] = {
23 "Unmapped", "Io", 23 "Unmapped", "Io",
24 "Normal", "CodeStatic", 24 "Normal", "CodeStatic",
@@ -35,6 +35,14 @@ static const char* GetMemoryStateName(MemoryState state) {
35 return names[ToSvcMemoryState(state)]; 35 return names[ToSvcMemoryState(state)];
36} 36}
37 37
38// Checks if a given address range lies within a larger address range.
39constexpr bool IsInsideAddressRange(VAddr address, u64 size, VAddr address_range_begin,
40 VAddr address_range_end) {
41 const VAddr end_address = address + size - 1;
42 return address_range_begin <= address && end_address <= address_range_end - 1;
43}
44} // Anonymous namespace
45
38bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const { 46bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
39 ASSERT(base + size == next.base); 47 ASSERT(base + size == next.base);
40 if (permissions != next.permissions || state != next.state || attribute != next.attribute || 48 if (permissions != next.permissions || state != next.state || attribute != next.attribute ||
@@ -706,6 +714,11 @@ u64 VMManager::GetAddressSpaceWidth() const {
706 return address_space_width; 714 return address_space_width;
707} 715}
708 716
717bool VMManager::IsWithinAddressSpace(VAddr address, u64 size) const {
718 return IsInsideAddressRange(address, size, GetAddressSpaceBaseAddress(),
719 GetAddressSpaceEndAddress());
720}
721
709VAddr VMManager::GetASLRRegionBaseAddress() const { 722VAddr VMManager::GetASLRRegionBaseAddress() const {
710 return aslr_region_base; 723 return aslr_region_base;
711} 724}
@@ -786,6 +799,11 @@ u64 VMManager::GetNewMapRegionSize() const {
786 return new_map_region_end - new_map_region_base; 799 return new_map_region_end - new_map_region_base;
787} 800}
788 801
802bool VMManager::IsWithinNewMapRegion(VAddr address, u64 size) const {
803 return IsInsideAddressRange(address, size, GetNewMapRegionBaseAddress(),
804 GetNewMapRegionEndAddress());
805}
806
789VAddr VMManager::GetTLSIORegionBaseAddress() const { 807VAddr VMManager::GetTLSIORegionBaseAddress() const {
790 return tls_io_region_base; 808 return tls_io_region_base;
791} 809}
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 6091533bc..60f36a5b9 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -432,6 +432,9 @@ public:
432 /// Gets the address space width in bits. 432 /// Gets the address space width in bits.
433 u64 GetAddressSpaceWidth() const; 433 u64 GetAddressSpaceWidth() const;
434 434
435 /// Determines whether or not the given address range lies within the address space.
436 bool IsWithinAddressSpace(VAddr address, u64 size) const;
437
435 /// Gets the base address of the ASLR region. 438 /// Gets the base address of the ASLR region.
436 VAddr GetASLRRegionBaseAddress() const; 439 VAddr GetASLRRegionBaseAddress() const;
437 440
@@ -480,6 +483,9 @@ public:
480 /// Gets the total size of the new map region in bytes. 483 /// Gets the total size of the new map region in bytes.
481 u64 GetNewMapRegionSize() const; 484 u64 GetNewMapRegionSize() const;
482 485
486 /// Determines whether or not the given address range lies within the new map region
487 bool IsWithinNewMapRegion(VAddr address, u64 size) const;
488
483 /// Gets the base address of the TLS IO region. 489 /// Gets the base address of the TLS IO region.
484 VAddr GetTLSIORegionBaseAddress() const; 490 VAddr GetTLSIORegionBaseAddress() const;
485 491