|
|
@ -28,10 +28,6 @@ bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
|
|
|
|
type != next.type) {
|
|
|
|
type != next.type) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == VMAType::AllocatedMemoryBlock &&
|
|
|
|
|
|
|
|
(backing_block != next.backing_block || offset + size != next.offset)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == VMAType::BackingMemory && backing_memory + size != next.backing_memory) {
|
|
|
|
if (type == VMAType::BackingMemory && backing_memory + size != next.backing_memory) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -71,28 +67,6 @@ VMManager::VMAHandle VMManager::FindVMA(VAddr target) const {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
|
|
|
|
|
|
|
|
std::shared_ptr<std::vector<u8>> block,
|
|
|
|
|
|
|
|
std::size_t offset, u32 size,
|
|
|
|
|
|
|
|
MemoryState state) {
|
|
|
|
|
|
|
|
ASSERT(block != nullptr);
|
|
|
|
|
|
|
|
ASSERT(offset + size <= block->size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This is the appropriately sized VMA that will turn into our allocation.
|
|
|
|
|
|
|
|
CASCADE_RESULT(VMAIter vma_handle, CarveVMA(target, size));
|
|
|
|
|
|
|
|
VirtualMemoryArea& final_vma = vma_handle->second;
|
|
|
|
|
|
|
|
ASSERT(final_vma.size == size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final_vma.type = VMAType::AllocatedMemoryBlock;
|
|
|
|
|
|
|
|
final_vma.permissions = VMAPermission::ReadWrite;
|
|
|
|
|
|
|
|
final_vma.meminfo_state = state;
|
|
|
|
|
|
|
|
final_vma.backing_block = block;
|
|
|
|
|
|
|
|
final_vma.offset = offset;
|
|
|
|
|
|
|
|
UpdatePageTableForVMA(final_vma);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return MakeResult<VMAHandle>(MergeAdjacent(vma_handle));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResultVal<VAddr> VMManager::MapBackingMemoryToBase(VAddr base, u32 region_size, u8* memory,
|
|
|
|
ResultVal<VAddr> VMManager::MapBackingMemoryToBase(VAddr base, u32 region_size, u8* memory,
|
|
|
|
u32 size, MemoryState state) {
|
|
|
|
u32 size, MemoryState state) {
|
|
|
|
|
|
|
|
|
|
|
@ -197,8 +171,6 @@ VMManager::VMAIter VMManager::Unmap(VMAIter vma_handle) {
|
|
|
|
vma.permissions = VMAPermission::None;
|
|
|
|
vma.permissions = VMAPermission::None;
|
|
|
|
vma.meminfo_state = MemoryState::Free;
|
|
|
|
vma.meminfo_state = MemoryState::Free;
|
|
|
|
|
|
|
|
|
|
|
|
vma.backing_block = nullptr;
|
|
|
|
|
|
|
|
vma.offset = 0;
|
|
|
|
|
|
|
|
vma.backing_memory = nullptr;
|
|
|
|
vma.backing_memory = nullptr;
|
|
|
|
vma.paddr = 0;
|
|
|
|
vma.paddr = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -246,17 +218,6 @@ ResultCode VMManager::ReprotectRange(VAddr target, u32 size, VMAPermission new_p
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VMManager::RefreshMemoryBlockMappings(const std::vector<u8>* block) {
|
|
|
|
|
|
|
|
// If this ever proves to have a noticeable performance impact, allow users of the function to
|
|
|
|
|
|
|
|
// specify a specific range of addresses to limit the scan to.
|
|
|
|
|
|
|
|
for (const auto& p : vma_map) {
|
|
|
|
|
|
|
|
const VirtualMemoryArea& vma = p.second;
|
|
|
|
|
|
|
|
if (block == vma.backing_block.get()) {
|
|
|
|
|
|
|
|
UpdatePageTableForVMA(vma);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VMManager::LogLayout(Log::Level log_level) const {
|
|
|
|
void VMManager::LogLayout(Log::Level log_level) const {
|
|
|
|
for (const auto& p : vma_map) {
|
|
|
|
for (const auto& p : vma_map) {
|
|
|
|
const VirtualMemoryArea& vma = p.second;
|
|
|
|
const VirtualMemoryArea& vma = p.second;
|
|
|
@ -355,9 +316,6 @@ VMManager::VMAIter VMManager::SplitVMA(VMAIter vma_handle, u32 offset_in_vma) {
|
|
|
|
switch (new_vma.type) {
|
|
|
|
switch (new_vma.type) {
|
|
|
|
case VMAType::Free:
|
|
|
|
case VMAType::Free:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case VMAType::AllocatedMemoryBlock:
|
|
|
|
|
|
|
|
new_vma.offset += offset_in_vma;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VMAType::BackingMemory:
|
|
|
|
case VMAType::BackingMemory:
|
|
|
|
new_vma.backing_memory += offset_in_vma;
|
|
|
|
new_vma.backing_memory += offset_in_vma;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -395,10 +353,6 @@ void VMManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) {
|
|
|
|
case VMAType::Free:
|
|
|
|
case VMAType::Free:
|
|
|
|
Memory::UnmapRegion(page_table, vma.base, vma.size);
|
|
|
|
Memory::UnmapRegion(page_table, vma.base, vma.size);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case VMAType::AllocatedMemoryBlock:
|
|
|
|
|
|
|
|
Memory::MapMemoryRegion(page_table, vma.base, vma.size,
|
|
|
|
|
|
|
|
vma.backing_block->data() + vma.offset);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VMAType::BackingMemory:
|
|
|
|
case VMAType::BackingMemory:
|
|
|
|
Memory::MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory);
|
|
|
|
Memory::MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|