summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
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/core/hle/kernel/svc.cpp
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/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp25
1 files changed, 4 insertions, 21 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;