mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-18 08:22:04 +00:00
svc: refactor/rename MemoryInfo fields
This commit is contained in:
parent
d9159f81d2
commit
4866e80769
21 changed files with 138 additions and 138 deletions
|
@ -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;
|
||||
|
|
|
@ -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<ams::svc::MemoryState>(m_state & KMemoryState_Mask),
|
||||
.attr = static_cast<ams::svc::MemoryAttribute>(m_attribute & KMemoryAttribute_UserMask),
|
||||
.perm = static_cast<ams::svc::MemoryPermission>(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<ams::svc::MemoryState>(m_state & KMemoryState_Mask),
|
||||
.attribute = static_cast<ams::svc::MemoryAttribute>(m_attribute & KMemoryAttribute_UserMask),
|
||||
.permission = static_cast<ams::svc::MemoryPermission>(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<KMemoryAttribute>(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<KMemoryBlockDisableMergeAttribute>(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<KMemoryPermission>((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<KMemoryPermission>((new_perm & KMemoryPermission_IpcLockChangeMask) | (m_original_permission & ~KMemoryPermission_IpcLockChangeMask));
|
||||
}
|
||||
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 (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<KMemoryAttribute>(m_attribute & ~KMemoryAttribute_IpcLocked);
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -242,16 +242,16 @@ namespace ams::kern::svc {
|
|||
} else {
|
||||
/* Convert the 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)>);
|
||||
|
||||
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)));
|
||||
|
|
|
@ -47,16 +47,16 @@ namespace ams::kern::svc {
|
|||
} else {
|
||||
/* Convert the 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)>);
|
||||
|
||||
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)));
|
||||
|
|
|
@ -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<void *>(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<size_t>(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<size_t>(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<void *>(ams_ctx.sp), copy_size);
|
||||
} else {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<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. */
|
||||
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<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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue