kern: KMemoryManager/KPageGroup use physical addresses instead of virtual, now
This commit is contained in:
@@ -1051,7 +1051,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
SmmuSynchronizationBarrier();
|
||||
|
||||
/* Open references to the pages. */
|
||||
mm.Open(GetHeapVirtualAddress(phys_addr), DeviceLargePageSize / PageSize);
|
||||
mm.Open(phys_addr, DeviceLargePageSize / PageSize);
|
||||
|
||||
/* Advance. */
|
||||
phys_addr += DeviceLargePageSize;
|
||||
@@ -1112,7 +1112,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
SmmuSynchronizationBarrier();
|
||||
|
||||
/* Open references to the pages. */
|
||||
mm.Open(GetHeapVirtualAddress(phys_addr), (map_count * DevicePageSize) / PageSize);
|
||||
mm.Open(phys_addr, (map_count * DevicePageSize) / PageSize);
|
||||
|
||||
/* Advance. */
|
||||
phys_addr += map_count * DevicePageSize;
|
||||
@@ -1151,7 +1151,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
|
||||
/* Map the device page. */
|
||||
size_t mapped_size = 0;
|
||||
R_TRY(this->MapDevicePage(std::addressof(mapped_size), num_pt, max_pt, GetHeapPhysicalAddress(contig_range.address), contig_range.size, cur_addr, device_perm));
|
||||
R_TRY(this->MapDevicePage(std::addressof(mapped_size), num_pt, max_pt, contig_range.address, contig_range.size, cur_addr, device_perm));
|
||||
|
||||
/* Advance. */
|
||||
cur_addr += contig_range.size;
|
||||
@@ -1245,7 +1245,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
contig_count = contig_phys_addr != Null<KPhysicalAddress> ? 1 : 0;
|
||||
} else if (phys_addr == Null<KPhysicalAddress> || phys_addr != (contig_phys_addr + (contig_count * DevicePageSize))) {
|
||||
/* If we're no longer contiguous, close the range we've been building. */
|
||||
mm.Close(GetHeapVirtualAddress(contig_phys_addr), (contig_count * DevicePageSize) / PageSize);
|
||||
mm.Close(contig_phys_addr, (contig_count * DevicePageSize) / PageSize);
|
||||
|
||||
contig_phys_addr = phys_addr;
|
||||
contig_count = contig_phys_addr != Null<KPhysicalAddress> ? 1 : 0;
|
||||
@@ -1255,7 +1255,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
}
|
||||
|
||||
if (contig_count > 0) {
|
||||
mm.Close(GetHeapVirtualAddress(contig_phys_addr), (contig_count * DevicePageSize) / PageSize);
|
||||
mm.Close(contig_phys_addr, (contig_count * DevicePageSize) / PageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1294,7 +1294,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
SmmuSynchronizationBarrier();
|
||||
|
||||
/* Close references. */
|
||||
mm.Close(GetHeapVirtualAddress(phys_addr), DeviceLargePageSize / PageSize);
|
||||
mm.Close(phys_addr, DeviceLargePageSize / PageSize);
|
||||
|
||||
/* Advance. */
|
||||
address += DeviceLargePageSize;
|
||||
@@ -1320,7 +1320,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
/* Walk the directory. */
|
||||
KProcessAddress cur_process_address = process_address;
|
||||
size_t remaining_size = size;
|
||||
KPhysicalAddress cur_phys_address = GetHeapPhysicalAddress(contig_range.address);
|
||||
KPhysicalAddress cur_phys_address = contig_range.address;
|
||||
size_t remaining_in_range = contig_range.size;
|
||||
bool first = true;
|
||||
u32 first_attr = 0;
|
||||
@@ -1367,7 +1367,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
}
|
||||
range_open = true;
|
||||
|
||||
cur_phys_address = GetHeapPhysicalAddress(contig_range.address);
|
||||
cur_phys_address = contig_range.address;
|
||||
remaining_in_range = contig_range.size;
|
||||
}
|
||||
|
||||
@@ -1410,7 +1410,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
}
|
||||
range_open = true;
|
||||
|
||||
cur_phys_address = GetHeapPhysicalAddress(contig_range.address);
|
||||
cur_phys_address = contig_range.address;
|
||||
remaining_in_range = contig_range.size;
|
||||
}
|
||||
|
||||
|
||||
@@ -511,8 +511,10 @@ namespace ams::kern::board::nintendo::nx {
|
||||
MESOSPHERE_ABORT_UNLESS(Kernel::GetSystemResourceLimit().Reserve(ams::svc::LimitableResource_PhysicalMemoryMax, SecureAppletMemorySize));
|
||||
|
||||
constexpr auto SecureAppletAllocateOption = KMemoryManager::EncodeOption(KMemoryManager::Pool_System, KMemoryManager::Direction_FromFront);
|
||||
g_secure_applet_memory_address = Kernel::GetMemoryManager().AllocateAndOpenContinuous(SecureAppletMemorySize / PageSize, 1, SecureAppletAllocateOption);
|
||||
MESOSPHERE_ABORT_UNLESS(g_secure_applet_memory_address != Null<KVirtualAddress>);
|
||||
const KPhysicalAddress secure_applet_memory_phys_addr = Kernel::GetMemoryManager().AllocateAndOpenContinuous(SecureAppletMemorySize / PageSize, 1, SecureAppletAllocateOption);
|
||||
MESOSPHERE_ABORT_UNLESS(secure_applet_memory_phys_addr != Null<KPhysicalAddress>);
|
||||
|
||||
g_secure_applet_memory_address = KMemoryLayout::GetLinearVirtualAddress(secure_applet_memory_phys_addr);
|
||||
}
|
||||
|
||||
/* Initialize KTrace. */
|
||||
@@ -690,9 +692,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
MESOSPHERE_ASSERT(it != page_groups[i].end());
|
||||
MESOSPHERE_ASSERT(it->GetNumPages() == 1);
|
||||
|
||||
KPhysicalAddress phys_addr = page_table.GetHeapPhysicalAddress(it->GetAddress());
|
||||
|
||||
args->r[reg_id] = GetInteger(phys_addr) | (GetInteger(virt_addr) & (PageSize - 1));
|
||||
args->r[reg_id] = GetInteger(it->GetAddress()) | (GetInteger(virt_addr) & (PageSize - 1));
|
||||
} else {
|
||||
/* If we couldn't map, we should clear the address. */
|
||||
args->r[reg_id] = 0;
|
||||
@@ -729,25 +729,21 @@ namespace ams::kern::board::nintendo::nx {
|
||||
|
||||
/* Allocate the memory. */
|
||||
const size_t num_pages = size / PageSize;
|
||||
const KVirtualAddress vaddr = Kernel::GetMemoryManager().AllocateAndOpenContinuous(num_pages, alignment / PageSize, KMemoryManager::EncodeOption(static_cast<KMemoryManager::Pool>(pool), KMemoryManager::Direction_FromFront));
|
||||
R_UNLESS(vaddr != Null<KVirtualAddress>, svc::ResultOutOfMemory());
|
||||
const KPhysicalAddress paddr = Kernel::GetMemoryManager().AllocateAndOpenContinuous(num_pages, alignment / PageSize, KMemoryManager::EncodeOption(static_cast<KMemoryManager::Pool>(pool), KMemoryManager::Direction_FromFront));
|
||||
R_UNLESS(paddr != Null<KPhysicalAddress>, svc::ResultOutOfMemory());
|
||||
|
||||
/* Ensure we don't leak references to the memory on error. */
|
||||
auto mem_guard = SCOPE_GUARD { Kernel::GetMemoryManager().Close(vaddr, num_pages); };
|
||||
auto mem_guard = SCOPE_GUARD { Kernel::GetMemoryManager().Close(paddr, num_pages); };
|
||||
|
||||
/* If the memory isn't already secure, set it as secure. */
|
||||
if (pool != KMemoryManager::Pool_System) {
|
||||
/* Get the physical address. */
|
||||
const KPhysicalAddress paddr = KPageTable::GetHeapPhysicalAddress(vaddr);
|
||||
MESOSPHERE_ABORT_UNLESS(paddr != Null<KPhysicalAddress>);
|
||||
|
||||
/* Set the secure region. */
|
||||
R_UNLESS(SetSecureRegion(paddr, size), svc::ResultOutOfMemory());
|
||||
}
|
||||
|
||||
/* We succeeded. */
|
||||
mem_guard.Cancel();
|
||||
*out = vaddr;
|
||||
*out = KPageTable::GetHeapVirtualAddress(paddr);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -779,7 +775,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
}
|
||||
|
||||
/* Close the secure region's pages. */
|
||||
Kernel::GetMemoryManager().Close(address, size / PageSize);
|
||||
Kernel::GetMemoryManager().Close(KPageTable::GetHeapPhysicalAddress(address), size / PageSize);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user