kern: implement SvcSetMemoryAttribute

This commit is contained in:
Michael Scire 2020-07-22 18:46:28 -07:00 committed by SciresM
parent 185baa7c4d
commit ab96255a5d
5 changed files with 67 additions and 2 deletions

View file

@ -21,6 +21,26 @@ namespace ams::kern::svc {
namespace {
Result SetMemoryAttribute(uintptr_t address, size_t size, uint32_t mask, uint32_t attr) {
/* Validate address / size. */
R_UNLESS(util::IsAligned(address, PageSize), svc::ResultInvalidAddress());
R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize());
R_UNLESS(size > 0, svc::ResultInvalidSize());
R_UNLESS((address < address + size), svc::ResultInvalidCurrentMemory());
/* Validate the attribute and mask. */
constexpr u32 SupportedMask = ams::svc::MemoryAttribute_Uncached;
R_UNLESS((mask | attr) == mask, svc::ResultInvalidCombination());
R_UNLESS((mask | attr | SupportedMask) == SupportedMask, svc::ResultInvalidCombination());
/* Validate that the region is in range for the current process. */
auto &page_table = GetCurrentProcess().GetPageTable();
R_UNLESS(page_table.Contains(address, size), svc::ResultInvalidCurrentMemory());
/* Set the memory attribute. */
return page_table.SetMemoryAttribute(address, size, mask, attr);
}
Result MapMemory(uintptr_t dst_address, uintptr_t src_address, size_t size) {
/* Validate that addresses are page aligned. */
R_UNLESS(util::IsAligned(dst_address, PageSize), svc::ResultInvalidAddress());
@ -81,7 +101,7 @@ namespace ams::kern::svc {
}
Result SetMemoryAttribute64(ams::svc::Address address, ams::svc::Size size, uint32_t mask, uint32_t attr) {
MESOSPHERE_PANIC("Stubbed SvcSetMemoryAttribute64 was called.");
return SetMemoryAttribute(address, size, mask, attr);
}
Result MapMemory64(ams::svc::Address dst_address, ams::svc::Address src_address, ams::svc::Size size) {
@ -99,7 +119,7 @@ namespace ams::kern::svc {
}
Result SetMemoryAttribute64From32(ams::svc::Address address, ams::svc::Size size, uint32_t mask, uint32_t attr) {
MESOSPHERE_PANIC("Stubbed SvcSetMemoryAttribute64From32 was called.");
return SetMemoryAttribute(address, size, mask, attr);
}
Result MapMemory64From32(ams::svc::Address dst_address, ams::svc::Address src_address, ams::svc::Size size) {