diff options
| -rw-r--r-- | src/common/alignment.h | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 16 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h index 225770fab..b3f103c07 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h | |||
| @@ -19,4 +19,10 @@ constexpr T AlignDown(T value, std::size_t size) { | |||
| 19 | return static_cast<T>(value - value % size); | 19 | return static_cast<T>(value - value % size); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | template <typename T> | ||
| 23 | constexpr bool Is4KBAligned(T value) { | ||
| 24 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | ||
| 25 | return (value & 0xFFF) == 0; | ||
| 26 | } | ||
| 27 | |||
| 22 | } // namespace Common | 28 | } // namespace Common |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index d08b84bde..b0bdd822e 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | 10 | ||
| 11 | #include "common/alignment.h" | ||
| 11 | #include "common/assert.h" | 12 | #include "common/assert.h" |
| 12 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 13 | #include "common/microprofile.h" | 14 | #include "common/microprofile.h" |
| @@ -36,9 +37,6 @@ | |||
| 36 | 37 | ||
| 37 | namespace Kernel { | 38 | namespace Kernel { |
| 38 | namespace { | 39 | namespace { |
| 39 | constexpr bool Is4KBAligned(VAddr address) { | ||
| 40 | return (address & 0xFFF) == 0; | ||
| 41 | } | ||
| 42 | 40 | ||
| 43 | // Checks if address + size is greater than the given address | 41 | // Checks if address + size is greater than the given address |
| 44 | // This can return false if the size causes an overflow of a 64-bit type | 42 | // This can return false if the size causes an overflow of a 64-bit type |
| @@ -69,11 +67,11 @@ bool IsInsideNewMapRegion(const VMManager& vm, VAddr address, u64 size) { | |||
| 69 | // in the same order. | 67 | // in the same order. |
| 70 | ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_addr, VAddr src_addr, | 68 | ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_addr, VAddr src_addr, |
| 71 | u64 size) { | 69 | u64 size) { |
| 72 | if (!Is4KBAligned(dst_addr) || !Is4KBAligned(src_addr)) { | 70 | if (!Common::Is4KBAligned(dst_addr) || !Common::Is4KBAligned(src_addr)) { |
| 73 | return ERR_INVALID_ADDRESS; | 71 | return ERR_INVALID_ADDRESS; |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | if (size == 0 || !Is4KBAligned(size)) { | 74 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 77 | return ERR_INVALID_SIZE; | 75 | return ERR_INVALID_SIZE; |
| 78 | } | 76 | } |
| 79 | 77 | ||
| @@ -570,11 +568,11 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 570 | "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}", | 568 | "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}", |
| 571 | shared_memory_handle, addr, size, permissions); | 569 | shared_memory_handle, addr, size, permissions); |
| 572 | 570 | ||
| 573 | if (!Is4KBAligned(addr)) { | 571 | if (!Common::Is4KBAligned(addr)) { |
| 574 | return ERR_INVALID_ADDRESS; | 572 | return ERR_INVALID_ADDRESS; |
| 575 | } | 573 | } |
| 576 | 574 | ||
| 577 | if (size == 0 || !Is4KBAligned(size)) { | 575 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 578 | return ERR_INVALID_SIZE; | 576 | return ERR_INVALID_SIZE; |
| 579 | } | 577 | } |
| 580 | 578 | ||
| @@ -599,11 +597,11 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 599 | LOG_WARNING(Kernel_SVC, "called, shared_memory_handle=0x{:08X}, addr=0x{:X}, size=0x{:X}", | 597 | LOG_WARNING(Kernel_SVC, "called, shared_memory_handle=0x{:08X}, addr=0x{:X}, size=0x{:X}", |
| 600 | shared_memory_handle, addr, size); | 598 | shared_memory_handle, addr, size); |
| 601 | 599 | ||
| 602 | if (!Is4KBAligned(addr)) { | 600 | if (!Common::Is4KBAligned(addr)) { |
| 603 | return ERR_INVALID_ADDRESS; | 601 | return ERR_INVALID_ADDRESS; |
| 604 | } | 602 | } |
| 605 | 603 | ||
| 606 | if (size == 0 || !Is4KBAligned(size)) { | 604 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 607 | return ERR_INVALID_SIZE; | 605 | return ERR_INVALID_SIZE; |
| 608 | } | 606 | } |
| 609 | 607 | ||