mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-10 06:01:52 +00:00
kern: Implement QueryIoMapping logic for < 8.0.0
This commit is contained in:
parent
ff022115ca
commit
d9e9fbe3c2
1 changed files with 40 additions and 25 deletions
|
@ -32,7 +32,7 @@ namespace ams::kern::svc {
|
||||||
/* Check whether the address is aligned. */
|
/* Check whether the address is aligned. */
|
||||||
const bool aligned = util::IsAligned(phys_addr, PageSize);
|
const bool aligned = util::IsAligned(phys_addr, PageSize);
|
||||||
|
|
||||||
if (aligned) {
|
auto QueryIoMappingFromPageTable = [&] ALWAYS_INLINE_LAMBDA (uint64_t phys_addr, size_t size) -> Result {
|
||||||
/* The size must be non-zero. */
|
/* The size must be non-zero. */
|
||||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||||
|
|
||||||
|
@ -44,8 +44,22 @@ namespace ams::kern::svc {
|
||||||
|
|
||||||
/* Use the size as the found size. */
|
/* Use the size as the found size. */
|
||||||
found_size = size;
|
found_size = size;
|
||||||
|
|
||||||
|
return ResultSuccess();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (aligned) {
|
||||||
|
/* Query the input. */
|
||||||
|
R_TRY(QueryIoMappingFromPageTable(phys_addr, size));
|
||||||
|
} else {
|
||||||
|
if (kern::GetTargetFirmware() < TargetFirmware_8_0_0 && phys_addr >= PageSize) {
|
||||||
|
/* Query the aligned-down page. */
|
||||||
|
const size_t offset = phys_addr & (PageSize - 1);
|
||||||
|
R_TRY(QueryIoMappingFromPageTable(phys_addr - offset, size + offset));
|
||||||
|
|
||||||
|
/* Adjust the output address. */
|
||||||
|
found_address += offset;
|
||||||
} else {
|
} else {
|
||||||
/* TODO: Older kernel ABI compatibility. */
|
|
||||||
/* Newer kernel only allows unaligned addresses when they're special enum members. */
|
/* Newer kernel only allows unaligned addresses when they're special enum members. */
|
||||||
R_UNLESS(phys_addr < PageSize, svc::ResultNotFound());
|
R_UNLESS(phys_addr < PageSize, svc::ResultNotFound());
|
||||||
|
|
||||||
|
@ -72,6 +86,7 @@ namespace ams::kern::svc {
|
||||||
R_TRY(pt.QueryStaticMapping(std::addressof(found_address), region->GetAddress(), region->GetSize()));
|
R_TRY(pt.QueryStaticMapping(std::addressof(found_address), region->GetAddress(), region->GetSize()));
|
||||||
found_size = region->GetSize();
|
found_size = region->GetSize();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* We succeeded. */
|
/* We succeeded. */
|
||||||
MESOSPHERE_ASSERT(found_address != Null<KProcessAddress>);
|
MESOSPHERE_ASSERT(found_address != Null<KProcessAddress>);
|
||||||
|
|
Loading…
Reference in a new issue