summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-03-04 22:30:17 +0100
committerLioncash <mathew1800@gmail.com>2019-03-04 22:32:03 +0100
commit0be8fffc992e30da42004b4e640b7095e1040f53 (patch)
treed9827c3b2549658e220ee5bf78f26b6e021e83dc /src
parentMerge pull request #2165 from ReinUsesLisp/unbind-tex (diff)
downloadyuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.gz
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.bz2
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.lz
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.xz
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.tar.zst
yuzu-0be8fffc992e30da42004b4e640b7095e1040f53.zip
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) {
return address + size > address;
}
-// Checks if a given address range lies within a larger address range.
-constexpr bool IsInsideAddressRange(VAddr address, u64 size, VAddr address_range_begin,
- VAddr address_range_end) {
- const VAddr end_address = address + size - 1;
- return address_range_begin <= address && end_address <= address_range_end - 1;
-}
-
-bool IsInsideAddressSpace(const VMManager& vm, VAddr address, u64 size) {
- return IsInsideAddressRange(address, size, vm.GetAddressSpaceBaseAddress(),
- vm.GetAddressSpaceEndAddress());
-}
-
-bool IsInsideNewMapRegion(const VMManager& vm, VAddr address, u64 size) {
- return IsInsideAddressRange(address, size, vm.GetNewMapRegionBaseAddress(),
- vm.GetNewMapRegionEndAddress());
-}
-
// 8 GiB
constexpr u64 MAIN_MEMORY_SIZE = 0x200000000;
@@ -105,14 +88,14 @@ ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_add
return ERR_INVALID_ADDRESS_STATE;
}
- if (!IsInsideAddressSpace(vm_manager, src_addr, size)) {
+ if (!vm_manager.IsWithinAddressSpace(src_addr, size)) {
LOG_ERROR(Kernel_SVC,
"Source is not within the address space, addr=0x{:016X}, size=0x{:016X}",
src_addr, size);
return ERR_INVALID_ADDRESS_STATE;
}
- if (!IsInsideNewMapRegion(vm_manager, dst_addr, size)) {
+ if (!vm_manager.IsWithinNewMapRegion(dst_addr, size)) {
LOG_ERROR(Kernel_SVC,
"Destination is not within the new map region, addr=0x{:016X}, size=0x{:016X}",
dst_addr, size);
@@ -238,7 +221,7 @@ static ResultCode SetMemoryPermission(VAddr addr, u64 size, u32 prot) {
auto* const current_process = Core::CurrentProcess();
auto& vm_manager = current_process->VMManager();
- if (!IsInsideAddressSpace(vm_manager, addr, size)) {
+ if (!vm_manager.IsWithinAddressSpace(addr, size)) {
LOG_ERROR(Kernel_SVC,
"Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,
size);
@@ -299,7 +282,7 @@ static ResultCode SetMemoryAttribute(VAddr address, u64 size, u32 mask, u32 attr
}
auto& vm_manager = Core::CurrentProcess()->VMManager();
- if (!IsInsideAddressSpace(vm_manager, address, size)) {
+ if (!vm_manager.IsWithinAddressSpace(address, size)) {
LOG_ERROR(Kernel_SVC,
"Given address (0x{:016X}) is outside the bounds of the address space.", address);
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 @@
#include "core/memory_setup.h"
namespace Kernel {
-
-static const char* GetMemoryStateName(MemoryState state) {
+namespace {
+const char* GetMemoryStateName(MemoryState state) {
static constexpr const char* names[] = {
"Unmapped", "Io",
"Normal", "CodeStatic",
@@ -35,6 +35,14 @@ static const char* GetMemoryStateName(MemoryState state) {
return names[ToSvcMemoryState(state)];
}
+// Checks if a given address range lies within a larger address range.
+constexpr bool IsInsideAddressRange(VAddr address, u64 size, VAddr address_range_begin,
+ VAddr address_range_end) {
+ const VAddr end_address = address + size - 1;
+ return address_range_begin <= address && end_address <= address_range_end - 1;
+}
+} // Anonymous namespace
+
bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
ASSERT(base + size == next.base);
if (permissions != next.permissions || state != next.state || attribute != next.attribute ||
@@ -706,6 +714,11 @@ u64 VMManager::GetAddressSpaceWidth() const {
return address_space_width;
}
+bool VMManager::IsWithinAddressSpace(VAddr address, u64 size) const {
+ return IsInsideAddressRange(address, size, GetAddressSpaceBaseAddress(),
+ GetAddressSpaceEndAddress());
+}
+
VAddr VMManager::GetASLRRegionBaseAddress() const {
return aslr_region_base;
}
@@ -786,6 +799,11 @@ u64 VMManager::GetNewMapRegionSize() const {
return new_map_region_end - new_map_region_base;
}
+bool VMManager::IsWithinNewMapRegion(VAddr address, u64 size) const {
+ return IsInsideAddressRange(address, size, GetNewMapRegionBaseAddress(),
+ GetNewMapRegionEndAddress());
+}
+
VAddr VMManager::GetTLSIORegionBaseAddress() const {
return tls_io_region_base;
}
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:
/// Gets the address space width in bits.
u64 GetAddressSpaceWidth() const;
+ /// Determines whether or not the given address range lies within the address space.
+ bool IsWithinAddressSpace(VAddr address, u64 size) const;
+
/// Gets the base address of the ASLR region.
VAddr GetASLRRegionBaseAddress() const;
@@ -480,6 +483,9 @@ public:
/// Gets the total size of the new map region in bytes.
u64 GetNewMapRegionSize() const;
+ /// Determines whether or not the given address range lies within the new map region
+ bool IsWithinNewMapRegion(VAddr address, u64 size) const;
+
/// Gets the base address of the TLS IO region.
VAddr GetTLSIORegionBaseAddress() const;