From 4866e80769c5020dc46e2c685a7505429b82759e Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 5 Oct 2021 15:16:54 -0700 Subject: [PATCH] svc: refactor/rename MemoryInfo fields --- .../include/mesosphere/kern_k_io_region.hpp | 2 +- .../mesosphere/kern_k_memory_block.hpp | 94 +++++++++---------- .../libmesosphere/source/kern_k_io_region.cpp | 4 +- .../source/kern_k_memory_block_manager.cpp | 2 +- .../source/kern_k_page_table_base.cpp | 14 +-- .../source/svc/kern_svc_debug.cpp | 16 ++-- .../source/svc/kern_svc_query_memory.cpp | 16 ++-- .../source/ams/ams_environment.cpp | 8 +- .../diag/impl/diag_module_impl.os.horizon.cpp | 2 +- ...ddress_space_allocator_impl.os.horizon.hpp | 2 +- .../os_memory_permission_impl.os.horizon.cpp | 4 +- .../source/ro/impl/ro_ro_exception_info.cpp | 12 +-- .../include/vapours/svc/svc_types_base.hpp | 20 ++-- .../creport/source/creport_modules.cpp | 30 +++--- .../creport/source/creport_threads.cpp | 6 +- .../dmnt.gen2/source/dmnt2_debug_process.cpp | 8 +- .../dmnt/source/cheat/impl/dmnt_cheat_api.cpp | 8 +- stratosphere/fatal/source/fatal_debug.cpp | 8 +- .../loader/source/ldr_process_creation.cpp | 8 +- stratosphere/ro/source/impl/ro_map_utils.cpp | 8 +- stratosphere/ro/source/impl/ro_map_utils.hpp | 4 +- 21 files changed, 138 insertions(+), 138 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp index 58cad7f4f..4d9d7b2b0 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp @@ -34,7 +34,7 @@ namespace ams::kern { KPhysicalAddress m_physical_address; size_t m_size; ams::svc::MemoryMapping m_mapping; - ams::svc::MemoryPermission m_perm; + ams::svc::MemoryPermission m_permission; bool m_is_initialized; bool m_is_mapped; util::IntrusiveListNode m_process_list_node; diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_memory_block.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_memory_block.hpp index 557616327..9700a80f3 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_memory_block.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_memory_block.hpp @@ -200,21 +200,21 @@ namespace ams::kern { u16 m_ipc_lock_count; u16 m_device_use_count; u16 m_ipc_disable_merge_count; - KMemoryPermission m_perm; + KMemoryPermission m_permission; KMemoryAttribute m_attribute; - KMemoryPermission m_original_perm; + KMemoryPermission m_original_permission; KMemoryBlockDisableMergeAttribute m_disable_merge_attribute; constexpr ams::svc::MemoryInfo GetSvcMemoryInfo() const { return { - .addr = m_address, - .size = m_size, - .state = static_cast(m_state & KMemoryState_Mask), - .attr = static_cast(m_attribute & KMemoryAttribute_UserMask), - .perm = static_cast(m_perm & KMemoryPermission_UserMask), - .ipc_refcount = m_ipc_lock_count, - .device_refcount = m_device_use_count, - .padding = {}, + .base_address = m_address, + .size = m_size, + .state = static_cast(m_state & KMemoryState_Mask), + .attribute = static_cast(m_attribute & KMemoryAttribute_UserMask), + .permission = static_cast(m_permission & KMemoryPermission_UserMask), + .ipc_count = m_ipc_lock_count, + .device_count = m_device_use_count, + .padding = {}, }; } @@ -251,11 +251,11 @@ namespace ams::kern { } constexpr KMemoryPermission GetPermission() const { - return m_perm; + return m_permission; } constexpr KMemoryPermission GetOriginalPermission() const { - return m_original_perm; + return m_original_permission; } constexpr KMemoryAttribute GetAttribute() const { @@ -277,8 +277,8 @@ namespace ams::kern { u16 m_ipc_lock_count; u16 m_device_use_count; u16 m_ipc_disable_merge_count; - KMemoryPermission m_perm; - KMemoryPermission m_original_perm; + KMemoryPermission m_permission; + KMemoryPermission m_original_permission; KMemoryAttribute m_attribute; KMemoryBlockDisableMergeAttribute m_disable_merge_attribute; public: @@ -321,11 +321,11 @@ namespace ams::kern { } constexpr KMemoryPermission GetPermission() const { - return m_perm; + return m_permission; } constexpr KMemoryPermission GetOriginalPermission() const { - return m_original_perm; + return m_original_permission; } constexpr KMemoryAttribute GetAttribute() const { @@ -342,52 +342,52 @@ namespace ams::kern { .m_ipc_lock_count = m_ipc_lock_count, .m_device_use_count = m_device_use_count, .m_ipc_disable_merge_count = m_ipc_disable_merge_count, - .m_perm = m_perm, + .m_permission = m_permission, .m_attribute = m_attribute, - .m_original_perm = m_original_perm, + .m_original_permission = m_original_permission, .m_disable_merge_attribute = m_disable_merge_attribute, }; } public: constexpr KMemoryBlock() - : m_device_disable_merge_left_count(), m_device_disable_merge_right_count(), m_address(), m_num_pages(), m_memory_state(KMemoryState_None), m_ipc_lock_count(), m_device_use_count(), m_ipc_disable_merge_count(), m_perm(), m_original_perm(), m_attribute(), m_disable_merge_attribute() + : m_device_disable_merge_left_count(), m_device_disable_merge_right_count(), m_address(), m_num_pages(), m_memory_state(KMemoryState_None), m_ipc_lock_count(), m_device_use_count(), m_ipc_disable_merge_count(), m_permission(), m_original_permission(), m_attribute(), m_disable_merge_attribute() { /* ... */ } constexpr KMemoryBlock(KProcessAddress addr, size_t np, KMemoryState ms, KMemoryPermission p, KMemoryAttribute attr) - : m_device_disable_merge_left_count(), m_device_disable_merge_right_count(), m_address(addr), m_num_pages(np), m_memory_state(ms), m_ipc_lock_count(0), m_device_use_count(0), m_ipc_disable_merge_count(), m_perm(p), m_original_perm(KMemoryPermission_None), m_attribute(attr), m_disable_merge_attribute() + : m_device_disable_merge_left_count(), m_device_disable_merge_right_count(), m_address(addr), m_num_pages(np), m_memory_state(ms), m_ipc_lock_count(0), m_device_use_count(0), m_ipc_disable_merge_count(), m_permission(p), m_original_permission(KMemoryPermission_None), m_attribute(attr), m_disable_merge_attribute() { /* ... */ } constexpr void Initialize(KProcessAddress addr, size_t np, KMemoryState ms, KMemoryPermission p, KMemoryAttribute attr) { MESOSPHERE_ASSERT_THIS(); - m_address = addr; - m_num_pages = np; - m_memory_state = ms; - m_ipc_lock_count = 0; - m_device_use_count = 0; - m_perm = p; - m_original_perm = KMemoryPermission_None; - m_attribute = attr; + m_address = addr; + m_num_pages = np; + m_memory_state = ms; + m_ipc_lock_count = 0; + m_device_use_count = 0; + m_permission = p; + m_original_permission = KMemoryPermission_None; + m_attribute = attr; } constexpr bool HasProperties(KMemoryState s, KMemoryPermission p, KMemoryAttribute a) const { MESOSPHERE_ASSERT_THIS(); constexpr auto AttributeIgnoreMask = KMemoryAttribute_IpcLocked | KMemoryAttribute_DeviceShared; - return m_memory_state == s && m_perm == p && (m_attribute | AttributeIgnoreMask) == (a | AttributeIgnoreMask); + return m_memory_state == s && m_permission == p && (m_attribute | AttributeIgnoreMask) == (a | AttributeIgnoreMask); } constexpr bool HasSameProperties(const KMemoryBlock &rhs) const { MESOSPHERE_ASSERT_THIS(); - return m_memory_state == rhs.m_memory_state && - m_perm == rhs.m_perm && - m_original_perm == rhs.m_original_perm && - m_attribute == rhs.m_attribute && - m_ipc_lock_count == rhs.m_ipc_lock_count && - m_device_use_count == rhs.m_device_use_count; + return m_memory_state == rhs.m_memory_state && + m_permission == rhs.m_permission && + m_original_permission == rhs.m_original_permission && + m_attribute == rhs.m_attribute && + m_ipc_lock_count == rhs.m_ipc_lock_count && + m_device_use_count == rhs.m_device_use_count; } constexpr bool CanMergeWith(const KMemoryBlock &rhs) const { @@ -414,11 +414,11 @@ namespace ams::kern { constexpr void Update(KMemoryState s, KMemoryPermission p, KMemoryAttribute a, bool set_disable_merge_attr, u8 set_mask, u8 clear_mask) { MESOSPHERE_ASSERT_THIS(); - MESOSPHERE_ASSERT(m_original_perm == KMemoryPermission_None); + MESOSPHERE_ASSERT(m_original_permission == KMemoryPermission_None); MESOSPHERE_ASSERT((m_attribute & KMemoryAttribute_IpcLocked) == 0); m_memory_state = s; - m_perm = p; + m_permission = p; m_attribute = static_cast(a | (m_attribute & (KMemoryAttribute_IpcLocked | KMemoryAttribute_DeviceShared))); if (set_disable_merge_attr && set_mask != 0) { @@ -440,8 +440,8 @@ namespace ams::kern { block->m_memory_state = m_memory_state; block->m_ipc_lock_count = m_ipc_lock_count; block->m_device_use_count = m_device_use_count; - block->m_perm = m_perm; - block->m_original_perm = m_original_perm; + block->m_permission = m_permission; + block->m_original_permission = m_original_permission; block->m_attribute = m_attribute; block->m_disable_merge_attribute = static_cast(m_disable_merge_attribute & KMemoryBlockDisableMergeAttribute_AllLeft); block->m_ipc_disable_merge_count = m_ipc_disable_merge_count; @@ -581,11 +581,11 @@ namespace ams::kern { /* If this is our first lock, update our permissions. */ if (new_lock_count == 1) { - MESOSPHERE_ASSERT(m_original_perm == KMemoryPermission_None); - MESOSPHERE_ASSERT((m_perm | new_perm | KMemoryPermission_NotMapped) == (m_perm | KMemoryPermission_NotMapped)); - MESOSPHERE_ASSERT((m_perm & KMemoryPermission_UserExecute) != KMemoryPermission_UserExecute || (new_perm == KMemoryPermission_UserRead)); - m_original_perm = m_perm; - m_perm = static_cast((new_perm & KMemoryPermission_IpcLockChangeMask) | (m_original_perm & ~KMemoryPermission_IpcLockChangeMask)); + MESOSPHERE_ASSERT(m_original_permission == KMemoryPermission_None); + MESOSPHERE_ASSERT((m_permission | new_perm | KMemoryPermission_NotMapped) == (m_permission | KMemoryPermission_NotMapped)); + MESOSPHERE_ASSERT((m_permission & KMemoryPermission_UserExecute) != KMemoryPermission_UserExecute || (new_perm == KMemoryPermission_UserRead)); + m_original_permission = m_permission; + m_permission = static_cast((new_perm & KMemoryPermission_IpcLockChangeMask) | (m_original_permission & ~KMemoryPermission_IpcLockChangeMask)); } m_attribute = static_cast(m_attribute | KMemoryAttribute_IpcLocked); @@ -610,9 +610,9 @@ namespace ams::kern { /* If this is our last unlock, update our permissions. */ if (old_lock_count == 1) { - MESOSPHERE_ASSERT(m_original_perm != KMemoryPermission_None); - m_perm = m_original_perm; - m_original_perm = KMemoryPermission_None; + MESOSPHERE_ASSERT(m_original_permission != KMemoryPermission_None); + m_permission = m_original_permission; + m_original_permission = KMemoryPermission_None; m_attribute = static_cast(m_attribute & ~KMemoryAttribute_IpcLocked); } diff --git a/libraries/libmesosphere/source/kern_k_io_region.cpp b/libraries/libmesosphere/source/kern_k_io_region.cpp index e243b8496..25cf7e204 100644 --- a/libraries/libmesosphere/source/kern_k_io_region.cpp +++ b/libraries/libmesosphere/source/kern_k_io_region.cpp @@ -24,7 +24,7 @@ namespace ams::kern { m_physical_address = phys_addr; m_size = size; m_mapping = mapping; - m_perm = perm; + m_permission = perm; m_pool = pool; m_is_mapped = false; @@ -52,7 +52,7 @@ namespace ams::kern { MESOSPHERE_ASSERT_THIS(); /* Check that the desired perm is allowable. */ - R_UNLESS((m_perm | map_perm) == m_perm, svc::ResultInvalidNewMemoryPermission()); + R_UNLESS((m_permission | map_perm) == m_permission, svc::ResultInvalidNewMemoryPermission()); /* Check that the size is correct. */ R_UNLESS(size == m_size, svc::ResultInvalidSize()); diff --git a/libraries/libmesosphere/source/kern_k_memory_block_manager.cpp b/libraries/libmesosphere/source/kern_k_memory_block_manager.cpp index 6fa43c8a5..c10643c18 100644 --- a/libraries/libmesosphere/source/kern_k_memory_block_manager.cpp +++ b/libraries/libmesosphere/source/kern_k_memory_block_manager.cpp @@ -56,7 +56,7 @@ namespace ams::kern { if (info.m_state == KMemoryState_Free) { return " "; } else { - switch (info.m_perm) { + switch (info.m_permission) { case KMemoryPermission_UserReadExecute: return "r-x"; case KMemoryPermission_UserRead: diff --git a/libraries/libmesosphere/source/kern_k_page_table_base.cpp b/libraries/libmesosphere/source/kern_k_page_table_base.cpp index 61491f498..5afc9ac84 100644 --- a/libraries/libmesosphere/source/kern_k_page_table_base.cpp +++ b/libraries/libmesosphere/source/kern_k_page_table_base.cpp @@ -468,9 +468,9 @@ namespace ams::kern { Result KPageTableBase::CheckMemoryState(const KMemoryInfo &info, u32 state_mask, u32 state, u32 perm_mask, u32 perm, u32 attr_mask, u32 attr) const { /* Validate the states match expectation. */ - R_UNLESS((info.m_state & state_mask) == state, svc::ResultInvalidCurrentMemory()); - R_UNLESS((info.m_perm & perm_mask) == perm, svc::ResultInvalidCurrentMemory()); - R_UNLESS((info.m_attribute & attr_mask) == attr, svc::ResultInvalidCurrentMemory()); + R_UNLESS((info.m_state & state_mask) == state, svc::ResultInvalidCurrentMemory()); + R_UNLESS((info.m_permission & perm_mask) == perm, svc::ResultInvalidCurrentMemory()); + R_UNLESS((info.m_attribute & attr_mask) == attr, svc::ResultInvalidCurrentMemory()); return ResultSuccess(); } @@ -524,12 +524,12 @@ namespace ams::kern { /* Validate all blocks in the range have correct state. */ const KMemoryState first_state = info.m_state; - const KMemoryPermission first_perm = info.m_perm; + const KMemoryPermission first_perm = info.m_permission; const KMemoryAttribute first_attr = info.m_attribute; while (true) { /* Validate the current block. */ R_UNLESS(info.m_state == first_state, svc::ResultInvalidCurrentMemory()); - R_UNLESS(info.m_perm == first_perm, svc::ResultInvalidCurrentMemory()); + R_UNLESS(info.m_permission == first_perm, svc::ResultInvalidCurrentMemory()); R_UNLESS((info.m_attribute | ignore_attr) == (first_attr | ignore_attr), svc::ResultInvalidCurrentMemory()); /* Validate against the provided masks. */ @@ -1720,9 +1720,9 @@ namespace ams::kern { .m_ipc_lock_count = 0, .m_device_use_count = 0, .m_ipc_disable_merge_count = 0, - .m_perm = KMemoryPermission_None, + .m_permission = KMemoryPermission_None, .m_attribute = KMemoryAttribute_None, - .m_original_perm = KMemoryPermission_None, + .m_original_permission = KMemoryPermission_None, .m_disable_merge_attribute = KMemoryBlockDisableMergeAttribute_None, }; out_page_info->flags = 0; diff --git a/libraries/libmesosphere/source/svc/kern_svc_debug.cpp b/libraries/libmesosphere/source/svc/kern_svc_debug.cpp index 5b1b8f9b2..eb4c04845 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_debug.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_debug.cpp @@ -242,16 +242,16 @@ namespace ams::kern::svc { } else { /* Convert the info. */ T converted_info = {}; - static_assert(std::same_as); + static_assert(std::same_as); static_assert(std::same_as); - converted_info.addr = info.addr; - converted_info.size = info.size; - converted_info.state = info.state; - converted_info.attr = info.attr; - converted_info.perm = info.perm; - converted_info.ipc_refcount = info.ipc_refcount; - converted_info.device_refcount = info.device_refcount; + converted_info.base_address = info.base_address; + converted_info.size = info.size; + converted_info.state = info.state; + converted_info.attribute = info.attribute; + converted_info.permission = info.permission; + converted_info.ipc_count = info.ipc_count; + converted_info.device_count = info.device_count; /* Copy it. */ R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info))); diff --git a/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp b/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp index 40e6d3343..8fbe98694 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp @@ -47,16 +47,16 @@ namespace ams::kern::svc { } else { /* Convert the info. */ T converted_info = {}; - static_assert(std::same_as); + static_assert(std::same_as); static_assert(std::same_as); - converted_info.addr = info.addr; - converted_info.size = info.size; - converted_info.state = info.state; - converted_info.attr = info.attr; - converted_info.perm = info.perm; - converted_info.ipc_refcount = info.ipc_refcount; - converted_info.device_refcount = info.device_refcount; + converted_info.base_address = info.base_address; + converted_info.size = info.size; + converted_info.state = info.state; + converted_info.attribute = info.attribute; + converted_info.permission = info.permission; + converted_info.ipc_count = info.ipc_count; + converted_info.device_count = info.device_count; /* Copy it. */ R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info))); diff --git a/libraries/libstratosphere/source/ams/ams_environment.cpp b/libraries/libstratosphere/source/ams/ams_environment.cpp index d63aaf0f0..7cbb5be88 100644 --- a/libraries/libstratosphere/source/ams/ams_environment.cpp +++ b/libraries/libstratosphere/source/ams/ams_environment.cpp @@ -95,7 +95,7 @@ namespace ams { svc::lp64::MemoryInfo mem_info; svc::PageInfo page_info; if (R_SUCCEEDED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), GetPc()))) { - ams_ctx.module_base = mem_info.addr; + ams_ctx.module_base = mem_info.base_address; } else { ams_ctx.module_base = 0; } @@ -112,7 +112,7 @@ namespace ams { StackFrame cur_frame; svc::lp64::MemoryInfo mem_info; svc::PageInfo page_info; - if (R_SUCCEEDED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_fp)) && (mem_info.perm & svc::MemoryPermission_Read) == svc::MemoryPermission_Read) { + if (R_SUCCEEDED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_fp)) && (mem_info.permission & svc::MemoryPermission_Read) == svc::MemoryPermission_Read) { std::memcpy(&cur_frame, reinterpret_cast(cur_fp), sizeof(cur_frame)); } else { break; @@ -131,8 +131,8 @@ namespace ams { { svc::lp64::MemoryInfo mem_info; svc::PageInfo page_info; - if (R_SUCCEEDED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), ams_ctx.sp)) && (mem_info.perm & svc::MemoryPermission_Read) == svc::MemoryPermission_Read) { - size_t copy_size = std::min(FatalErrorContext::MaxStackDumpSize, static_cast(mem_info.addr + mem_info.size - ams_ctx.sp)); + if (R_SUCCEEDED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), ams_ctx.sp)) && (mem_info.permission & svc::MemoryPermission_Read) == svc::MemoryPermission_Read) { + size_t copy_size = std::min(FatalErrorContext::MaxStackDumpSize, static_cast(mem_info.base_address + mem_info.size - ams_ctx.sp)); ams_ctx.stack_dump_size = copy_size; std::memcpy(ams_ctx.stack_dump, reinterpret_cast(ams_ctx.sp), copy_size); } else { diff --git a/libraries/libstratosphere/source/diag/impl/diag_module_impl.os.horizon.cpp b/libraries/libstratosphere/source/diag/impl/diag_module_impl.os.horizon.cpp index 8f1d79c00..0aebd2b46 100644 --- a/libraries/libstratosphere/source/diag/impl/diag_module_impl.os.horizon.cpp +++ b/libraries/libstratosphere/source/diag/impl/diag_module_impl.os.horizon.cpp @@ -44,7 +44,7 @@ namespace ams::diag::impl { if (R_FAILED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_address))) { return 0; } - if (mem_info.perm != svc::MemoryPermission_ReadExecute) { + if (mem_info.permission != svc::MemoryPermission_ReadExecute) { break; } cur_address += mem_info.size; diff --git a/libraries/libstratosphere/source/os/impl/os_address_space_allocator_impl.os.horizon.hpp b/libraries/libstratosphere/source/os/impl/os_address_space_allocator_impl.os.horizon.hpp index 055e823da..9ba15af43 100644 --- a/libraries/libstratosphere/source/os/impl/os_address_space_allocator_impl.os.horizon.hpp +++ b/libraries/libstratosphere/source/os/impl/os_address_space_allocator_impl.os.horizon.hpp @@ -32,7 +32,7 @@ namespace ams::os::impl { R_ASSERT(result); AMS_UNUSED(result); - return memory_info.state == svc::MemoryState_Free && address + size <= memory_info.addr + memory_info.size; + return memory_info.state == svc::MemoryState_Free && address + size <= memory_info.base_address + memory_info.size; } }; diff --git a/libraries/libstratosphere/source/os/impl/os_memory_permission_impl.os.horizon.cpp b/libraries/libstratosphere/source/os/impl/os_memory_permission_impl.os.horizon.cpp index b2af6d24b..bd258b8df 100644 --- a/libraries/libstratosphere/source/os/impl/os_memory_permission_impl.os.horizon.cpp +++ b/libraries/libstratosphere/source/os/impl/os_memory_permission_impl.os.horizon.cpp @@ -27,9 +27,9 @@ namespace ams::os::impl { svc::PageInfo page_info; R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_address)); - size_t cur_size = std::min(mem_info.addr + mem_info.size - cur_address, remaining_size); + size_t cur_size = std::min(mem_info.base_address + mem_info.size - cur_address, remaining_size); - if (mem_info.perm != perm) { + if (mem_info.permission != perm) { R_ABORT_UNLESS(svc::SetMemoryPermission(cur_address, cur_size, perm)); } diff --git a/libraries/libstratosphere/source/ro/impl/ro_ro_exception_info.cpp b/libraries/libstratosphere/source/ro/impl/ro_ro_exception_info.cpp index bf70d87cf..03956139d 100644 --- a/libraries/libstratosphere/source/ro/impl/ro_ro_exception_info.cpp +++ b/libraries/libstratosphere/source/ro/impl/ro_ro_exception_info.cpp @@ -24,14 +24,14 @@ namespace ams::ro::impl { svc::PageInfo page_info; bool success = false; - for (uintptr_t cur = target; cur <= target; cur = mem_info.addr - 1) { + for (uintptr_t cur = target; cur <= target; cur = mem_info.base_address - 1) { R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur)); - if (mem_info.state != state || mem_info.perm != svc::MemoryPermission_ReadExecute) { + if (mem_info.state != state || mem_info.permission != svc::MemoryPermission_ReadExecute) { break; } - *out = mem_info.addr; + *out = mem_info.base_address; success = true; } @@ -43,14 +43,14 @@ namespace ams::ro::impl { svc::PageInfo page_info; bool success = false; - for (uintptr_t cur = target; cur >= target; cur = mem_info.addr + mem_info.size) { + for (uintptr_t cur = target; cur >= target; cur = mem_info.base_address + mem_info.size) { R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur)); if (mem_info.state != state) { break; } - *out = mem_info.addr + mem_info.size - 1; + *out = mem_info.base_address + mem_info.size - 1; success = true; } @@ -64,7 +64,7 @@ namespace ams::ro::impl { R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), pc)); /* Check memory info. */ - if (mem_info.perm != svc::MemoryPermission_ReadExecute) { + if (mem_info.permission != svc::MemoryPermission_ReadExecute) { return false; } diff --git a/libraries/libvapours/include/vapours/svc/svc_types_base.hpp b/libraries/libvapours/include/vapours/svc/svc_types_base.hpp index e0a22ab28..0fee68102 100644 --- a/libraries/libvapours/include/vapours/svc/svc_types_base.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_types_base.hpp @@ -21,13 +21,13 @@ namespace ams::svc { namespace lp64 { struct MemoryInfo { - u64 addr; + u64 base_address; u64 size; MemoryState state; - MemoryAttribute attr; - MemoryPermission perm; - u32 ipc_refcount; - u32 device_refcount; + MemoryAttribute attribute; + MemoryPermission permission; + u32 ipc_count; + u32 device_count; u32 padding; }; @@ -43,13 +43,13 @@ namespace ams::svc { namespace ilp32 { struct MemoryInfo { - u64 addr; + u64 base_address; u64 size; MemoryState state; - MemoryAttribute attr; - MemoryPermission perm; - u32 ipc_refcount; - u32 device_refcount; + MemoryAttribute attribute; + MemoryPermission permission; + u32 ipc_count; + u32 device_count; u32 padding; }; diff --git a/stratosphere/creport/source/creport_modules.cpp b/stratosphere/creport/source/creport_modules.cpp index 1f3007767..a8e4bfd53 100644 --- a/stratosphere/creport/source/creport_modules.cpp +++ b/stratosphere/creport/source/creport_modules.cpp @@ -99,10 +99,10 @@ namespace ams::creport { } /* Parse module. */ - if (mi.perm == svc::MemoryPermission_ReadExecute) { + if (mi.permission == svc::MemoryPermission_ReadExecute) { auto& module = this->modules[this->num_modules++]; - module.start_address = mi.addr; - module.end_address = mi.addr + mi.size; + module.start_address = mi.base_address; + module.end_address = mi.base_address + mi.size; GetModuleName(module.name, module.start_address, module.end_address); GetModuleBuildId(module.build_id, module.end_address); /* Some homebrew won't have a name. Add a fake one for readability. */ @@ -134,34 +134,34 @@ namespace ams::creport { } /* If we fall into a RW region, it may be rwdata. Query the region before it, which may be rodata or text. */ - if (mi.perm == svc::MemoryPermission_ReadWrite) { - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) { + if (mi.permission == svc::MemoryPermission_ReadWrite) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address - 4))) { return false; } } /* If we fall into an RO region, it may be rodata. Query the region before it, which should be text. */ - if (mi.perm == svc::MemoryPermission_Read) { - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) { + if (mi.permission == svc::MemoryPermission_Read) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address - 4))) { return false; } } /* We should, at this point, be looking at an executable region (text). */ - if (mi.perm != svc::MemoryPermission_ReadExecute) { + if (mi.permission != svc::MemoryPermission_ReadExecute) { return false; } /* Modules are a series of contiguous (text/rodata/rwdata) regions. */ /* Iterate backwards until we find unmapped memory, to find the start of the set of modules loaded here. */ - while (mi.addr > 0) { - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) { + while (mi.base_address > 0) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address - 4))) { return false; } if (mi.state == svc::MemoryState_Free) { /* We've found unmapped memory, so output the mapped memory afterwards. */ - *out_address = mi.addr + mi.size; + *out_address = mi.base_address + mi.size; return true; } } @@ -181,12 +181,12 @@ namespace ams::creport { svc::PageInfo pi; /* Verify .rodata is read-only. */ - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.perm != svc::MemoryPermission_Read) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.permission != svc::MemoryPermission_Read) { return; } /* Calculate start of rwdata. */ - const u64 rw_start_address = mi.addr + mi.size; + const u64 rw_start_address = mi.base_address + mi.size; /* Read start of .rodata. */ if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast(std::addressof(rodata_start)), this->debug_handle, ro_start_address, sizeof(rodata_start)))) { @@ -228,13 +228,13 @@ namespace ams::creport { /* Verify .rodata is read-only. */ svc::MemoryInfo mi; svc::PageInfo pi; - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.perm != svc::MemoryPermission_Read) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.permission != svc::MemoryPermission_Read) { return; } /* We want to read the last two pages of .rodata. */ const size_t read_size = mi.size >= sizeof(g_last_rodata_pages) ? sizeof(g_last_rodata_pages) : (sizeof(g_last_rodata_pages) / 2); - if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast(g_last_rodata_pages), this->debug_handle, mi.addr + mi.size - read_size, read_size))) { + if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast(g_last_rodata_pages), this->debug_handle, mi.base_address + mi.size - read_size, read_size))) { return; } diff --git a/stratosphere/creport/source/creport_threads.cpp b/stratosphere/creport/source/creport_threads.cpp index 78d92cc5b..17bd19d8d 100644 --- a/stratosphere/creport/source/creport_threads.cpp +++ b/stratosphere/creport/source/creport_threads.cpp @@ -198,14 +198,14 @@ namespace ams::creport { /* Check if sp points into the stack. */ if (mi.state != svc::MemoryState_Stack) { /* It's possible that sp is below the stack... */ - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr + mi.size)) || mi.state != svc::MemoryState_Stack) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address + mi.size)) || mi.state != svc::MemoryState_Stack) { return; } } /* Save stack extents. */ - this->stack_bottom = mi.addr; - this->stack_top = mi.addr + mi.size; + this->stack_bottom = mi.base_address; + this->stack_top = mi.base_address + mi.size; /* We always want to dump 0x100 of stack, starting from the lowest 0x10-byte aligned address below the stack pointer. */ /* Note: if the stack pointer is below the stack bottom, we will start dumping from the stack bottom. */ diff --git a/stratosphere/dmnt.gen2/source/dmnt2_debug_process.cpp b/stratosphere/dmnt.gen2/source/dmnt2_debug_process.cpp index 887466225..7801b2d7f 100644 --- a/stratosphere/dmnt.gen2/source/dmnt2_debug_process.cpp +++ b/stratosphere/dmnt.gen2/source/dmnt2_debug_process.cpp @@ -166,7 +166,7 @@ namespace ams::dmnt { svc::MemoryInfo memory_info; svc::PageInfo page_info; if (R_SUCCEEDED(svc::QueryDebugProcessMemory(std::addressof(memory_info), std::addressof(page_info), m_debug_handle, address))) { - if (memory_info.perm == svc::MemoryPermission_ReadExecute && (memory_info.state == svc::MemoryState_Code || memory_info.state == svc::MemoryState_AliasCode)) { + if (memory_info.permission == svc::MemoryPermission_ReadExecute && (memory_info.state == svc::MemoryState_Code || memory_info.state == svc::MemoryState_AliasCode)) { /* Check that we can add the module. */ AMS_ABORT_UNLESS(m_module_count < ModuleCountMax); @@ -174,7 +174,7 @@ namespace ams::dmnt { auto &module = m_module_definitions[m_module_count++]; /* Set module address/size. */ - module.SetAddressSize(memory_info.addr, memory_info.size); + module.SetAddressSize(memory_info.base_address, memory_info.size); /* Get module name buffer. */ char *module_name = module.GetNameBuffer(); @@ -186,7 +186,7 @@ namespace ams::dmnt { s32 path_length; char path[ModuleDefinition::PathLengthMax]; } module_path; - if (R_SUCCEEDED(this->ReadMemory(std::addressof(module_path), memory_info.addr + memory_info.size, sizeof(module_path)))) { + if (R_SUCCEEDED(this->ReadMemory(std::addressof(module_path), memory_info.base_address + memory_info.size, sizeof(module_path)))) { if (module_path.zero == 0 && module_path.path_length == util::Strnlen(module_path.path, sizeof(module_path.path))) { std::memcpy(module_name, module_path.path, ModuleDefinition::PathLengthMax); } @@ -198,7 +198,7 @@ namespace ams::dmnt { } /* Check if we're done. */ - const uintptr_t next_address = memory_info.addr + memory_info.size; + const uintptr_t next_address = memory_info.base_address + memory_info.size; if (memory_info.state == svc::MemoryState_Inaccessible) { break; } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp index 57919ac72..2e2fdc274 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp @@ -360,11 +360,11 @@ namespace ams::dmnt::cheat::impl { break; } - if (mem_info.perm != svc::MemoryPermission_None) { + if (mem_info.permission != svc::MemoryPermission_None) { count++; } - address = mem_info.addr + mem_info.size; + address = mem_info.base_address + mem_info.size; } while (address != 0); *out_count = count; @@ -384,14 +384,14 @@ namespace ams::dmnt::cheat::impl { break; } - if (mem_info.perm != svc::MemoryPermission_None) { + if (mem_info.permission != svc::MemoryPermission_None) { if (offset <= total_count && written_count < max_count) { mappings[written_count++] = mem_info; } total_count++; } - address = mem_info.addr + mem_info.size; + address = mem_info.base_address + mem_info.size; } while (address != 0 && written_count < max_count); *out_count = written_count; diff --git a/stratosphere/fatal/source/fatal_debug.cpp b/stratosphere/fatal/source/fatal_debug.cpp index 9761ea97d..a29d6a1c0 100644 --- a/stratosphere/fatal/source/fatal_debug.cpp +++ b/stratosphere/fatal/source/fatal_debug.cpp @@ -159,23 +159,23 @@ namespace ams::fatal::srv { bool TryGuessBaseAddress(u64 *out_base_address, os::NativeHandle debug_handle, u64 guess) { svc::MemoryInfo mi; svc::PageInfo pi; - if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, guess)) || mi.perm != svc::MemoryPermission_ReadExecute) { + if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, guess)) || mi.permission != svc::MemoryPermission_ReadExecute) { return false; } /* Iterate backwards until we find the memory before the code region. */ - while (mi.addr > 0) { + while (mi.base_address > 0) { if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, guess))) { return false; } if (mi.state == svc::MemoryState_Free) { /* Code region will be at the end of the unmapped region preceding it. */ - *out_base_address = mi.addr + mi.size; + *out_base_address = mi.base_address + mi.size; return true; } - guess = mi.addr - 4; + guess = mi.base_address - 4; } return false; diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index e89897a5c..744098ac9 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -411,17 +411,17 @@ namespace ams::ldr { R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), address)); /* If the memory range is free and big enough, use it. */ - if (mem_info.state == svc::MemoryState_Free && mapping_size <= ((mem_info.addr + mem_info.size) - address)) { + if (mem_info.state == svc::MemoryState_Free && mapping_size <= ((mem_info.base_address + mem_info.size) - address)) { *out = address; return ResultSuccess(); } /* Check that we can advance. */ - R_UNLESS(address < mem_info.addr + mem_info.size, svc::ResultOutOfMemory()); - R_UNLESS(mem_info.addr + mem_info.size - 1 < aslr_start + aslr_size - 1, svc::ResultOutOfMemory()); + R_UNLESS(address < mem_info.base_address + mem_info.size, svc::ResultOutOfMemory()); + R_UNLESS(mem_info.base_address + mem_info.size - 1 < aslr_start + aslr_size - 1, svc::ResultOutOfMemory()); /* Advance. */ - address = mem_info.addr + mem_info.size; + address = mem_info.base_address + mem_info.size; } } diff --git a/stratosphere/ro/source/impl/ro_map_utils.cpp b/stratosphere/ro/source/impl/ro_map_utils.cpp index 335e62211..4db96e8b0 100644 --- a/stratosphere/ro/source/impl/ro_map_utils.cpp +++ b/stratosphere/ro/source/impl/ro_map_utils.cpp @@ -66,17 +66,17 @@ namespace ams::ro::impl { R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), address)); /* If the memory range is free and big enough, use it. */ - if (mem_info.state == svc::MemoryState_Free && mapping_size <= ((mem_info.addr + mem_info.size) - address)) { + if (mem_info.state == svc::MemoryState_Free && mapping_size <= ((mem_info.base_address + mem_info.size) - address)) { *out = address; return ResultSuccess(); } /* Check that we can advance. */ - R_UNLESS(address < mem_info.addr + mem_info.size, ro::ResultOutOfAddressSpace()); - R_UNLESS(mem_info.addr + mem_info.size - 1 < aslr_start + aslr_size - 1, ro::ResultOutOfAddressSpace()); + R_UNLESS(address < mem_info.base_address + mem_info.size, ro::ResultOutOfAddressSpace()); + R_UNLESS(mem_info.base_address + mem_info.size - 1 < aslr_start + aslr_size - 1, ro::ResultOutOfAddressSpace()); /* Advance. */ - address = mem_info.addr + mem_info.size; + address = mem_info.base_address + mem_info.size; } } diff --git a/stratosphere/ro/source/impl/ro_map_utils.hpp b/stratosphere/ro/source/impl/ro_map_utils.hpp index e6b2777c4..75cbe5337 100644 --- a/stratosphere/ro/source/impl/ro_map_utils.hpp +++ b/stratosphere/ro/source/impl/ro_map_utils.hpp @@ -77,13 +77,13 @@ namespace ams::ro::impl { /* Check for guard availability before the region. */ R_ABORT_UNLESS(svc::QueryProcessMemory(std::addressof(mem_info), std::addressof(page_info), process, address - 1)); - if (!(mem_info.state == svc::MemoryState_Free && mem_info.addr <= address - StackGuardSize)) { + if (!(mem_info.state == svc::MemoryState_Free && mem_info.base_address <= address - StackGuardSize)) { return false; } /* Check for guard availability after the region. */ R_ABORT_UNLESS(svc::QueryProcessMemory(std::addressof(mem_info), std::addressof(page_info), process, address + size)); - if (!(mem_info.state == svc::MemoryState_Free && address + size + StackGuardSize <= mem_info.addr + mem_info.size)) { + if (!(mem_info.state == svc::MemoryState_Free && address + size + StackGuardSize <= mem_info.base_address + mem_info.size)) { return false; }