kern: add InfoType_TransferMemoryHint

This commit is contained in:
Michael Scire 2024-10-09 11:04:43 -07:00 committed by SciresM
parent 77d17dc4ff
commit 5de551db29
3 changed files with 31 additions and 0 deletions

View File

@ -48,6 +48,22 @@ namespace ams::kern {
KProcess *GetOwner() const { return m_owner; } KProcess *GetOwner() const { return m_owner; }
KProcessAddress GetSourceAddress() { return m_address; } KProcessAddress GetSourceAddress() { return m_address; }
size_t GetSize() const { return m_is_initialized ? GetReference(m_page_group).GetNumPages() * PageSize : 0; } size_t GetSize() const { return m_is_initialized ? GetReference(m_page_group).GetNumPages() * PageSize : 0; }
constexpr uintptr_t GetHint() const {
/* Get memory size. */
const size_t size = this->GetSize();
/* TODO: Is this architecture specific? */
if (size >= 2_MB) {
return GetInteger(m_address) & (2_MB - 1);
} else if (size >= 64_KB) {
return GetInteger(m_address) & (64_KB - 1);
} else if (size >= 4_KB) {
return GetInteger(m_address) & (4_KB - 1);
} else {
return 0;
}
}
}; };
} }

View File

@ -314,6 +314,19 @@ namespace ams::kern::svc {
*out = io_region->GetHint(); *out = io_region->GetHint();
} }
break; break;
case ams::svc::InfoType_TransferMemoryHint:
{
/* Verify the sub-type is valid. */
R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination());
/* Get the transfer memory from its handle. */
KScopedAutoObject transfer_memory = GetCurrentProcess().GetHandleTable().GetObject<KTransferMemory>(handle);
R_UNLESS(transfer_memory.IsNotNull(), svc::ResultInvalidHandle());
/* Get the transfer memory's address hint. */
*out = transfer_memory->GetHint();
}
break;
case ams::svc::InfoType_MesosphereMeta: case ams::svc::InfoType_MesosphereMeta:
{ {
/* Verify the handle is invalid. */ /* Verify the handle is invalid. */

View File

@ -191,6 +191,8 @@ namespace ams::svc {
InfoType_IsSvcPermitted = 26, InfoType_IsSvcPermitted = 26,
InfoType_IoRegionHint = 27, InfoType_IoRegionHint = 27,
InfoType_AliasRegionExtraSize = 28, InfoType_AliasRegionExtraSize = 28,
/* ... */
InfoType_TransferMemoryHint = 34,
InfoType_MesosphereMeta = 65000, InfoType_MesosphereMeta = 65000,
InfoType_MesosphereCurrentProcess = 65001, InfoType_MesosphereCurrentProcess = 65001,