svc: refactor/rename MemoryInfo fields

This commit is contained in:
Michael Scire 2021-10-05 15:16:54 -07:00
parent d9159f81d2
commit 4866e80769
21 changed files with 138 additions and 138 deletions

View file

@ -34,7 +34,7 @@ namespace ams::kern {
KPhysicalAddress m_physical_address; KPhysicalAddress m_physical_address;
size_t m_size; size_t m_size;
ams::svc::MemoryMapping m_mapping; ams::svc::MemoryMapping m_mapping;
ams::svc::MemoryPermission m_perm; ams::svc::MemoryPermission m_permission;
bool m_is_initialized; bool m_is_initialized;
bool m_is_mapped; bool m_is_mapped;
util::IntrusiveListNode m_process_list_node; util::IntrusiveListNode m_process_list_node;

View file

@ -200,20 +200,20 @@ namespace ams::kern {
u16 m_ipc_lock_count; u16 m_ipc_lock_count;
u16 m_device_use_count; u16 m_device_use_count;
u16 m_ipc_disable_merge_count; u16 m_ipc_disable_merge_count;
KMemoryPermission m_perm; KMemoryPermission m_permission;
KMemoryAttribute m_attribute; KMemoryAttribute m_attribute;
KMemoryPermission m_original_perm; KMemoryPermission m_original_permission;
KMemoryBlockDisableMergeAttribute m_disable_merge_attribute; KMemoryBlockDisableMergeAttribute m_disable_merge_attribute;
constexpr ams::svc::MemoryInfo GetSvcMemoryInfo() const { constexpr ams::svc::MemoryInfo GetSvcMemoryInfo() const {
return { return {
.addr = m_address, .base_address = m_address,
.size = m_size, .size = m_size,
.state = static_cast<ams::svc::MemoryState>(m_state & KMemoryState_Mask), .state = static_cast<ams::svc::MemoryState>(m_state & KMemoryState_Mask),
.attr = static_cast<ams::svc::MemoryAttribute>(m_attribute & KMemoryAttribute_UserMask), .attribute = static_cast<ams::svc::MemoryAttribute>(m_attribute & KMemoryAttribute_UserMask),
.perm = static_cast<ams::svc::MemoryPermission>(m_perm & KMemoryPermission_UserMask), .permission = static_cast<ams::svc::MemoryPermission>(m_permission & KMemoryPermission_UserMask),
.ipc_refcount = m_ipc_lock_count, .ipc_count = m_ipc_lock_count,
.device_refcount = m_device_use_count, .device_count = m_device_use_count,
.padding = {}, .padding = {},
}; };
} }
@ -251,11 +251,11 @@ namespace ams::kern {
} }
constexpr KMemoryPermission GetPermission() const { constexpr KMemoryPermission GetPermission() const {
return m_perm; return m_permission;
} }
constexpr KMemoryPermission GetOriginalPermission() const { constexpr KMemoryPermission GetOriginalPermission() const {
return m_original_perm; return m_original_permission;
} }
constexpr KMemoryAttribute GetAttribute() const { constexpr KMemoryAttribute GetAttribute() const {
@ -277,8 +277,8 @@ namespace ams::kern {
u16 m_ipc_lock_count; u16 m_ipc_lock_count;
u16 m_device_use_count; u16 m_device_use_count;
u16 m_ipc_disable_merge_count; u16 m_ipc_disable_merge_count;
KMemoryPermission m_perm; KMemoryPermission m_permission;
KMemoryPermission m_original_perm; KMemoryPermission m_original_permission;
KMemoryAttribute m_attribute; KMemoryAttribute m_attribute;
KMemoryBlockDisableMergeAttribute m_disable_merge_attribute; KMemoryBlockDisableMergeAttribute m_disable_merge_attribute;
public: public:
@ -321,11 +321,11 @@ namespace ams::kern {
} }
constexpr KMemoryPermission GetPermission() const { constexpr KMemoryPermission GetPermission() const {
return m_perm; return m_permission;
} }
constexpr KMemoryPermission GetOriginalPermission() const { constexpr KMemoryPermission GetOriginalPermission() const {
return m_original_perm; return m_original_permission;
} }
constexpr KMemoryAttribute GetAttribute() const { constexpr KMemoryAttribute GetAttribute() const {
@ -342,21 +342,21 @@ namespace ams::kern {
.m_ipc_lock_count = m_ipc_lock_count, .m_ipc_lock_count = m_ipc_lock_count,
.m_device_use_count = m_device_use_count, .m_device_use_count = m_device_use_count,
.m_ipc_disable_merge_count = m_ipc_disable_merge_count, .m_ipc_disable_merge_count = m_ipc_disable_merge_count,
.m_perm = m_perm, .m_permission = m_permission,
.m_attribute = m_attribute, .m_attribute = m_attribute,
.m_original_perm = m_original_perm, .m_original_permission = m_original_permission,
.m_disable_merge_attribute = m_disable_merge_attribute, .m_disable_merge_attribute = m_disable_merge_attribute,
}; };
} }
public: public:
constexpr KMemoryBlock() 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) 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()
{ {
/* ... */ /* ... */
} }
@ -368,23 +368,23 @@ namespace ams::kern {
m_memory_state = ms; m_memory_state = ms;
m_ipc_lock_count = 0; m_ipc_lock_count = 0;
m_device_use_count = 0; m_device_use_count = 0;
m_perm = p; m_permission = p;
m_original_perm = KMemoryPermission_None; m_original_permission = KMemoryPermission_None;
m_attribute = attr; m_attribute = attr;
} }
constexpr bool HasProperties(KMemoryState s, KMemoryPermission p, KMemoryAttribute a) const { constexpr bool HasProperties(KMemoryState s, KMemoryPermission p, KMemoryAttribute a) const {
MESOSPHERE_ASSERT_THIS(); MESOSPHERE_ASSERT_THIS();
constexpr auto AttributeIgnoreMask = KMemoryAttribute_IpcLocked | KMemoryAttribute_DeviceShared; 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 { constexpr bool HasSameProperties(const KMemoryBlock &rhs) const {
MESOSPHERE_ASSERT_THIS(); MESOSPHERE_ASSERT_THIS();
return m_memory_state == rhs.m_memory_state && return m_memory_state == rhs.m_memory_state &&
m_perm == rhs.m_perm && m_permission == rhs.m_permission &&
m_original_perm == rhs.m_original_perm && m_original_permission == rhs.m_original_permission &&
m_attribute == rhs.m_attribute && m_attribute == rhs.m_attribute &&
m_ipc_lock_count == rhs.m_ipc_lock_count && m_ipc_lock_count == rhs.m_ipc_lock_count &&
m_device_use_count == rhs.m_device_use_count; m_device_use_count == rhs.m_device_use_count;
@ -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) { 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_THIS();
MESOSPHERE_ASSERT(m_original_perm == KMemoryPermission_None); MESOSPHERE_ASSERT(m_original_permission == KMemoryPermission_None);
MESOSPHERE_ASSERT((m_attribute & KMemoryAttribute_IpcLocked) == 0); MESOSPHERE_ASSERT((m_attribute & KMemoryAttribute_IpcLocked) == 0);
m_memory_state = s; m_memory_state = s;
m_perm = p; m_permission = p;
m_attribute = static_cast<KMemoryAttribute>(a | (m_attribute & (KMemoryAttribute_IpcLocked | KMemoryAttribute_DeviceShared))); m_attribute = static_cast<KMemoryAttribute>(a | (m_attribute & (KMemoryAttribute_IpcLocked | KMemoryAttribute_DeviceShared)));
if (set_disable_merge_attr && set_mask != 0) { if (set_disable_merge_attr && set_mask != 0) {
@ -440,8 +440,8 @@ namespace ams::kern {
block->m_memory_state = m_memory_state; block->m_memory_state = m_memory_state;
block->m_ipc_lock_count = m_ipc_lock_count; block->m_ipc_lock_count = m_ipc_lock_count;
block->m_device_use_count = m_device_use_count; block->m_device_use_count = m_device_use_count;
block->m_perm = m_perm; block->m_permission = m_permission;
block->m_original_perm = m_original_perm; block->m_original_permission = m_original_permission;
block->m_attribute = m_attribute; block->m_attribute = m_attribute;
block->m_disable_merge_attribute = static_cast<KMemoryBlockDisableMergeAttribute>(m_disable_merge_attribute & KMemoryBlockDisableMergeAttribute_AllLeft); block->m_disable_merge_attribute = static_cast<KMemoryBlockDisableMergeAttribute>(m_disable_merge_attribute & KMemoryBlockDisableMergeAttribute_AllLeft);
block->m_ipc_disable_merge_count = m_ipc_disable_merge_count; 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 this is our first lock, update our permissions. */
if (new_lock_count == 1) { if (new_lock_count == 1) {
MESOSPHERE_ASSERT(m_original_perm == KMemoryPermission_None); MESOSPHERE_ASSERT(m_original_permission == KMemoryPermission_None);
MESOSPHERE_ASSERT((m_perm | new_perm | KMemoryPermission_NotMapped) == (m_perm | KMemoryPermission_NotMapped)); MESOSPHERE_ASSERT((m_permission | new_perm | KMemoryPermission_NotMapped) == (m_permission | KMemoryPermission_NotMapped));
MESOSPHERE_ASSERT((m_perm & KMemoryPermission_UserExecute) != KMemoryPermission_UserExecute || (new_perm == KMemoryPermission_UserRead)); MESOSPHERE_ASSERT((m_permission & KMemoryPermission_UserExecute) != KMemoryPermission_UserExecute || (new_perm == KMemoryPermission_UserRead));
m_original_perm = m_perm; m_original_permission = m_permission;
m_perm = static_cast<KMemoryPermission>((new_perm & KMemoryPermission_IpcLockChangeMask) | (m_original_perm & ~KMemoryPermission_IpcLockChangeMask)); m_permission = static_cast<KMemoryPermission>((new_perm & KMemoryPermission_IpcLockChangeMask) | (m_original_permission & ~KMemoryPermission_IpcLockChangeMask));
} }
m_attribute = static_cast<KMemoryAttribute>(m_attribute | KMemoryAttribute_IpcLocked); m_attribute = static_cast<KMemoryAttribute>(m_attribute | KMemoryAttribute_IpcLocked);
@ -610,9 +610,9 @@ namespace ams::kern {
/* If this is our last unlock, update our permissions. */ /* If this is our last unlock, update our permissions. */
if (old_lock_count == 1) { if (old_lock_count == 1) {
MESOSPHERE_ASSERT(m_original_perm != KMemoryPermission_None); MESOSPHERE_ASSERT(m_original_permission != KMemoryPermission_None);
m_perm = m_original_perm; m_permission = m_original_permission;
m_original_perm = KMemoryPermission_None; m_original_permission = KMemoryPermission_None;
m_attribute = static_cast<KMemoryAttribute>(m_attribute & ~KMemoryAttribute_IpcLocked); m_attribute = static_cast<KMemoryAttribute>(m_attribute & ~KMemoryAttribute_IpcLocked);
} }

View file

@ -24,7 +24,7 @@ namespace ams::kern {
m_physical_address = phys_addr; m_physical_address = phys_addr;
m_size = size; m_size = size;
m_mapping = mapping; m_mapping = mapping;
m_perm = perm; m_permission = perm;
m_pool = pool; m_pool = pool;
m_is_mapped = false; m_is_mapped = false;
@ -52,7 +52,7 @@ namespace ams::kern {
MESOSPHERE_ASSERT_THIS(); MESOSPHERE_ASSERT_THIS();
/* Check that the desired perm is allowable. */ /* 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. */ /* Check that the size is correct. */
R_UNLESS(size == m_size, svc::ResultInvalidSize()); R_UNLESS(size == m_size, svc::ResultInvalidSize());

View file

@ -56,7 +56,7 @@ namespace ams::kern {
if (info.m_state == KMemoryState_Free) { if (info.m_state == KMemoryState_Free) {
return " "; return " ";
} else { } else {
switch (info.m_perm) { switch (info.m_permission) {
case KMemoryPermission_UserReadExecute: case KMemoryPermission_UserReadExecute:
return "r-x"; return "r-x";
case KMemoryPermission_UserRead: case KMemoryPermission_UserRead:

View file

@ -469,7 +469,7 @@ 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 { 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. */ /* Validate the states match expectation. */
R_UNLESS((info.m_state & state_mask) == state, svc::ResultInvalidCurrentMemory()); R_UNLESS((info.m_state & state_mask) == state, svc::ResultInvalidCurrentMemory());
R_UNLESS((info.m_perm & perm_mask) == perm, svc::ResultInvalidCurrentMemory()); R_UNLESS((info.m_permission & perm_mask) == perm, svc::ResultInvalidCurrentMemory());
R_UNLESS((info.m_attribute & attr_mask) == attr, svc::ResultInvalidCurrentMemory()); R_UNLESS((info.m_attribute & attr_mask) == attr, svc::ResultInvalidCurrentMemory());
return ResultSuccess(); return ResultSuccess();
@ -524,12 +524,12 @@ namespace ams::kern {
/* Validate all blocks in the range have correct state. */ /* Validate all blocks in the range have correct state. */
const KMemoryState first_state = info.m_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; const KMemoryAttribute first_attr = info.m_attribute;
while (true) { while (true) {
/* Validate the current block. */ /* Validate the current block. */
R_UNLESS(info.m_state == first_state, svc::ResultInvalidCurrentMemory()); 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()); R_UNLESS((info.m_attribute | ignore_attr) == (first_attr | ignore_attr), svc::ResultInvalidCurrentMemory());
/* Validate against the provided masks. */ /* Validate against the provided masks. */
@ -1720,9 +1720,9 @@ namespace ams::kern {
.m_ipc_lock_count = 0, .m_ipc_lock_count = 0,
.m_device_use_count = 0, .m_device_use_count = 0,
.m_ipc_disable_merge_count = 0, .m_ipc_disable_merge_count = 0,
.m_perm = KMemoryPermission_None, .m_permission = KMemoryPermission_None,
.m_attribute = KMemoryAttribute_None, .m_attribute = KMemoryAttribute_None,
.m_original_perm = KMemoryPermission_None, .m_original_permission = KMemoryPermission_None,
.m_disable_merge_attribute = KMemoryBlockDisableMergeAttribute_None, .m_disable_merge_attribute = KMemoryBlockDisableMergeAttribute_None,
}; };
out_page_info->flags = 0; out_page_info->flags = 0;

View file

@ -242,16 +242,16 @@ namespace ams::kern::svc {
} else { } else {
/* Convert the info. */ /* Convert the info. */
T converted_info = {}; T converted_info = {};
static_assert(std::same_as<decltype(T{}.addr), decltype(ams::svc::MemoryInfo{}.addr)>); static_assert(std::same_as<decltype(T{}.base_address), decltype(ams::svc::MemoryInfo{}.base_address)>);
static_assert(std::same_as<decltype(T{}.size), decltype(ams::svc::MemoryInfo{}.size)>); static_assert(std::same_as<decltype(T{}.size), decltype(ams::svc::MemoryInfo{}.size)>);
converted_info.addr = info.addr; converted_info.base_address = info.base_address;
converted_info.size = info.size; converted_info.size = info.size;
converted_info.state = info.state; converted_info.state = info.state;
converted_info.attr = info.attr; converted_info.attribute = info.attribute;
converted_info.perm = info.perm; converted_info.permission = info.permission;
converted_info.ipc_refcount = info.ipc_refcount; converted_info.ipc_count = info.ipc_count;
converted_info.device_refcount = info.device_refcount; converted_info.device_count = info.device_count;
/* Copy it. */ /* Copy it. */
R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info))); R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info)));

View file

@ -47,16 +47,16 @@ namespace ams::kern::svc {
} else { } else {
/* Convert the info. */ /* Convert the info. */
T converted_info = {}; T converted_info = {};
static_assert(std::same_as<decltype(T{}.addr), decltype(ams::svc::MemoryInfo{}.addr)>); static_assert(std::same_as<decltype(T{}.base_address), decltype(ams::svc::MemoryInfo{}.base_address)>);
static_assert(std::same_as<decltype(T{}.size), decltype(ams::svc::MemoryInfo{}.size)>); static_assert(std::same_as<decltype(T{}.size), decltype(ams::svc::MemoryInfo{}.size)>);
converted_info.addr = info.addr; converted_info.base_address = info.base_address;
converted_info.size = info.size; converted_info.size = info.size;
converted_info.state = info.state; converted_info.state = info.state;
converted_info.attr = info.attr; converted_info.attribute = info.attribute;
converted_info.perm = info.perm; converted_info.permission = info.permission;
converted_info.ipc_refcount = info.ipc_refcount; converted_info.ipc_count = info.ipc_count;
converted_info.device_refcount = info.device_refcount; converted_info.device_count = info.device_count;
/* Copy it. */ /* Copy it. */
R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info))); R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info)));

View file

@ -95,7 +95,7 @@ namespace ams {
svc::lp64::MemoryInfo mem_info; svc::lp64::MemoryInfo mem_info;
svc::PageInfo page_info; svc::PageInfo page_info;
if (R_SUCCEEDED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), GetPc()))) { 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 { } else {
ams_ctx.module_base = 0; ams_ctx.module_base = 0;
} }
@ -112,7 +112,7 @@ namespace ams {
StackFrame cur_frame; StackFrame cur_frame;
svc::lp64::MemoryInfo mem_info; svc::lp64::MemoryInfo mem_info;
svc::PageInfo page_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<void *>(cur_fp), sizeof(cur_frame)); std::memcpy(&cur_frame, reinterpret_cast<void *>(cur_fp), sizeof(cur_frame));
} else { } else {
break; break;
@ -131,8 +131,8 @@ namespace ams {
{ {
svc::lp64::MemoryInfo mem_info; svc::lp64::MemoryInfo mem_info;
svc::PageInfo page_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) { 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<size_t>(mem_info.addr + mem_info.size - ams_ctx.sp)); size_t copy_size = std::min(FatalErrorContext::MaxStackDumpSize, static_cast<size_t>(mem_info.base_address + mem_info.size - ams_ctx.sp));
ams_ctx.stack_dump_size = copy_size; ams_ctx.stack_dump_size = copy_size;
std::memcpy(ams_ctx.stack_dump, reinterpret_cast<void *>(ams_ctx.sp), copy_size); std::memcpy(ams_ctx.stack_dump, reinterpret_cast<void *>(ams_ctx.sp), copy_size);
} else { } else {

View file

@ -44,7 +44,7 @@ namespace ams::diag::impl {
if (R_FAILED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_address))) { if (R_FAILED(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_address))) {
return 0; return 0;
} }
if (mem_info.perm != svc::MemoryPermission_ReadExecute) { if (mem_info.permission != svc::MemoryPermission_ReadExecute) {
break; break;
} }
cur_address += mem_info.size; cur_address += mem_info.size;

View file

@ -32,7 +32,7 @@ namespace ams::os::impl {
R_ASSERT(result); R_ASSERT(result);
AMS_UNUSED(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;
} }
}; };

View file

@ -27,9 +27,9 @@ namespace ams::os::impl {
svc::PageInfo page_info; svc::PageInfo page_info;
R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur_address)); 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)); R_ABORT_UNLESS(svc::SetMemoryPermission(cur_address, cur_size, perm));
} }

View file

@ -24,14 +24,14 @@ namespace ams::ro::impl {
svc::PageInfo page_info; svc::PageInfo page_info;
bool success = false; 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)); 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; break;
} }
*out = mem_info.addr; *out = mem_info.base_address;
success = true; success = true;
} }
@ -43,14 +43,14 @@ namespace ams::ro::impl {
svc::PageInfo page_info; svc::PageInfo page_info;
bool success = false; 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)); R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), cur));
if (mem_info.state != state) { if (mem_info.state != state) {
break; break;
} }
*out = mem_info.addr + mem_info.size - 1; *out = mem_info.base_address + mem_info.size - 1;
success = true; success = true;
} }
@ -64,7 +64,7 @@ namespace ams::ro::impl {
R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), pc)); R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), pc));
/* Check memory info. */ /* Check memory info. */
if (mem_info.perm != svc::MemoryPermission_ReadExecute) { if (mem_info.permission != svc::MemoryPermission_ReadExecute) {
return false; return false;
} }

View file

@ -21,13 +21,13 @@ namespace ams::svc {
namespace lp64 { namespace lp64 {
struct MemoryInfo { struct MemoryInfo {
u64 addr; u64 base_address;
u64 size; u64 size;
MemoryState state; MemoryState state;
MemoryAttribute attr; MemoryAttribute attribute;
MemoryPermission perm; MemoryPermission permission;
u32 ipc_refcount; u32 ipc_count;
u32 device_refcount; u32 device_count;
u32 padding; u32 padding;
}; };
@ -43,13 +43,13 @@ namespace ams::svc {
namespace ilp32 { namespace ilp32 {
struct MemoryInfo { struct MemoryInfo {
u64 addr; u64 base_address;
u64 size; u64 size;
MemoryState state; MemoryState state;
MemoryAttribute attr; MemoryAttribute attribute;
MemoryPermission perm; MemoryPermission permission;
u32 ipc_refcount; u32 ipc_count;
u32 device_refcount; u32 device_count;
u32 padding; u32 padding;
}; };

View file

@ -99,10 +99,10 @@ namespace ams::creport {
} }
/* Parse module. */ /* Parse module. */
if (mi.perm == svc::MemoryPermission_ReadExecute) { if (mi.permission == svc::MemoryPermission_ReadExecute) {
auto& module = this->modules[this->num_modules++]; auto& module = this->modules[this->num_modules++];
module.start_address = mi.addr; module.start_address = mi.base_address;
module.end_address = mi.addr + mi.size; module.end_address = mi.base_address + mi.size;
GetModuleName(module.name, module.start_address, module.end_address); GetModuleName(module.name, module.start_address, module.end_address);
GetModuleBuildId(module.build_id, module.end_address); GetModuleBuildId(module.build_id, module.end_address);
/* Some homebrew won't have a name. Add a fake one for readability. */ /* 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 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 (mi.permission == svc::MemoryPermission_ReadWrite) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) { if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address - 4))) {
return false; return false;
} }
} }
/* If we fall into an RO region, it may be rodata. Query the region before it, which should be text. */ /* 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 (mi.permission == svc::MemoryPermission_Read) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) { if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address - 4))) {
return false; return false;
} }
} }
/* We should, at this point, be looking at an executable region (text). */ /* 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; return false;
} }
/* Modules are a series of contiguous (text/rodata/rwdata) regions. */ /* 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. */ /* Iterate backwards until we find unmapped memory, to find the start of the set of modules loaded here. */
while (mi.addr > 0) { while (mi.base_address > 0) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) { if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.base_address - 4))) {
return false; return false;
} }
if (mi.state == svc::MemoryState_Free) { if (mi.state == svc::MemoryState_Free) {
/* We've found unmapped memory, so output the mapped memory afterwards. */ /* 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; return true;
} }
} }
@ -181,12 +181,12 @@ namespace ams::creport {
svc::PageInfo pi; svc::PageInfo pi;
/* Verify .rodata is read-only. */ /* 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; return;
} }
/* Calculate start of rwdata. */ /* 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. */ /* Read start of .rodata. */
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(rodata_start)), this->debug_handle, ro_start_address, sizeof(rodata_start)))) { if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(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. */ /* Verify .rodata is read-only. */
svc::MemoryInfo mi; svc::MemoryInfo mi;
svc::PageInfo pi; 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; return;
} }
/* We want to read the last two pages of .rodata. */ /* 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); 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<uintptr_t>(g_last_rodata_pages), this->debug_handle, mi.addr + mi.size - read_size, read_size))) { if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(g_last_rodata_pages), this->debug_handle, mi.base_address + mi.size - read_size, read_size))) {
return; return;
} }

View file

@ -198,14 +198,14 @@ namespace ams::creport {
/* Check if sp points into the stack. */ /* Check if sp points into the stack. */
if (mi.state != svc::MemoryState_Stack) { if (mi.state != svc::MemoryState_Stack) {
/* It's possible that sp is below the 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; return;
} }
} }
/* Save stack extents. */ /* Save stack extents. */
this->stack_bottom = mi.addr; this->stack_bottom = mi.base_address;
this->stack_top = mi.addr + mi.size; 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. */ /* 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. */ /* Note: if the stack pointer is below the stack bottom, we will start dumping from the stack bottom. */

View file

@ -166,7 +166,7 @@ namespace ams::dmnt {
svc::MemoryInfo memory_info; svc::MemoryInfo memory_info;
svc::PageInfo page_info; svc::PageInfo page_info;
if (R_SUCCEEDED(svc::QueryDebugProcessMemory(std::addressof(memory_info), std::addressof(page_info), m_debug_handle, address))) { 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. */ /* Check that we can add the module. */
AMS_ABORT_UNLESS(m_module_count < ModuleCountMax); AMS_ABORT_UNLESS(m_module_count < ModuleCountMax);
@ -174,7 +174,7 @@ namespace ams::dmnt {
auto &module = m_module_definitions[m_module_count++]; auto &module = m_module_definitions[m_module_count++];
/* Set module address/size. */ /* 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. */ /* Get module name buffer. */
char *module_name = module.GetNameBuffer(); char *module_name = module.GetNameBuffer();
@ -186,7 +186,7 @@ namespace ams::dmnt {
s32 path_length; s32 path_length;
char path[ModuleDefinition::PathLengthMax]; char path[ModuleDefinition::PathLengthMax];
} module_path; } 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))) { 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); std::memcpy(module_name, module_path.path, ModuleDefinition::PathLengthMax);
} }
@ -198,7 +198,7 @@ namespace ams::dmnt {
} }
/* Check if we're done. */ /* 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) { if (memory_info.state == svc::MemoryState_Inaccessible) {
break; break;
} }

View file

@ -360,11 +360,11 @@ namespace ams::dmnt::cheat::impl {
break; break;
} }
if (mem_info.perm != svc::MemoryPermission_None) { if (mem_info.permission != svc::MemoryPermission_None) {
count++; count++;
} }
address = mem_info.addr + mem_info.size; address = mem_info.base_address + mem_info.size;
} while (address != 0); } while (address != 0);
*out_count = count; *out_count = count;
@ -384,14 +384,14 @@ namespace ams::dmnt::cheat::impl {
break; break;
} }
if (mem_info.perm != svc::MemoryPermission_None) { if (mem_info.permission != svc::MemoryPermission_None) {
if (offset <= total_count && written_count < max_count) { if (offset <= total_count && written_count < max_count) {
mappings[written_count++] = mem_info; mappings[written_count++] = mem_info;
} }
total_count++; total_count++;
} }
address = mem_info.addr + mem_info.size; address = mem_info.base_address + mem_info.size;
} while (address != 0 && written_count < max_count); } while (address != 0 && written_count < max_count);
*out_count = written_count; *out_count = written_count;

View file

@ -159,23 +159,23 @@ namespace ams::fatal::srv {
bool TryGuessBaseAddress(u64 *out_base_address, os::NativeHandle debug_handle, u64 guess) { bool TryGuessBaseAddress(u64 *out_base_address, os::NativeHandle debug_handle, u64 guess) {
svc::MemoryInfo mi; svc::MemoryInfo mi;
svc::PageInfo pi; 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; return false;
} }
/* Iterate backwards until we find the memory before the code region. */ /* 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))) { if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, guess))) {
return false; return false;
} }
if (mi.state == svc::MemoryState_Free) { if (mi.state == svc::MemoryState_Free) {
/* Code region will be at the end of the unmapped region preceding it. */ /* 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; return true;
} }
guess = mi.addr - 4; guess = mi.base_address - 4;
} }
return false; return false;

View file

@ -411,17 +411,17 @@ namespace ams::ldr {
R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), address)); 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 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; *out = address;
return ResultSuccess(); return ResultSuccess();
} }
/* Check that we can advance. */ /* Check that we can advance. */
R_UNLESS(address < mem_info.addr + mem_info.size, svc::ResultOutOfMemory()); R_UNLESS(address < mem_info.base_address + mem_info.size, svc::ResultOutOfMemory());
R_UNLESS(mem_info.addr + mem_info.size - 1 < aslr_start + aslr_size - 1, svc::ResultOutOfMemory()); R_UNLESS(mem_info.base_address + mem_info.size - 1 < aslr_start + aslr_size - 1, svc::ResultOutOfMemory());
/* Advance. */ /* Advance. */
address = mem_info.addr + mem_info.size; address = mem_info.base_address + mem_info.size;
} }
} }

View file

@ -66,17 +66,17 @@ namespace ams::ro::impl {
R_ABORT_UNLESS(svc::QueryMemory(std::addressof(mem_info), std::addressof(page_info), address)); 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 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; *out = address;
return ResultSuccess(); return ResultSuccess();
} }
/* Check that we can advance. */ /* Check that we can advance. */
R_UNLESS(address < mem_info.addr + mem_info.size, ro::ResultOutOfAddressSpace()); R_UNLESS(address < mem_info.base_address + mem_info.size, ro::ResultOutOfAddressSpace());
R_UNLESS(mem_info.addr + mem_info.size - 1 < aslr_start + aslr_size - 1, ro::ResultOutOfAddressSpace()); R_UNLESS(mem_info.base_address + mem_info.size - 1 < aslr_start + aslr_size - 1, ro::ResultOutOfAddressSpace());
/* Advance. */ /* Advance. */
address = mem_info.addr + mem_info.size; address = mem_info.base_address + mem_info.size;
} }
} }

View file

@ -77,13 +77,13 @@ namespace ams::ro::impl {
/* Check for guard availability before the region. */ /* Check for guard availability before the region. */
R_ABORT_UNLESS(svc::QueryProcessMemory(std::addressof(mem_info), std::addressof(page_info), process, address - 1)); 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; return false;
} }
/* Check for guard availability after the region. */ /* Check for guard availability after the region. */
R_ABORT_UNLESS(svc::QueryProcessMemory(std::addressof(mem_info), std::addressof(page_info), process, address + size)); 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; return false;
} }