mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 01:22:37 -06:00
VMManager: remove all backing block related functions
The shared_ptr<vector> type backing memory is unused now, and is not expected to be used in the future
This commit is contained in:
parent
7f9873d7ec
commit
b6ab4e466b
4 changed files with 1 additions and 77 deletions
|
@ -28,10 +28,6 @@ bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
|
|||
type != next.type) {
|
||||
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) {
|
||||
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,
|
||||
u32 size, MemoryState state) {
|
||||
|
||||
|
@ -197,8 +171,6 @@ VMManager::VMAIter VMManager::Unmap(VMAIter vma_handle) {
|
|||
vma.permissions = VMAPermission::None;
|
||||
vma.meminfo_state = MemoryState::Free;
|
||||
|
||||
vma.backing_block = nullptr;
|
||||
vma.offset = 0;
|
||||
vma.backing_memory = nullptr;
|
||||
vma.paddr = 0;
|
||||
|
||||
|
@ -246,17 +218,6 @@ ResultCode VMManager::ReprotectRange(VAddr target, u32 size, VMAPermission new_p
|
|||
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 {
|
||||
for (const auto& p : vma_map) {
|
||||
const VirtualMemoryArea& vma = p.second;
|
||||
|
@ -355,9 +316,6 @@ VMManager::VMAIter VMManager::SplitVMA(VMAIter vma_handle, u32 offset_in_vma) {
|
|||
switch (new_vma.type) {
|
||||
case VMAType::Free:
|
||||
break;
|
||||
case VMAType::AllocatedMemoryBlock:
|
||||
new_vma.offset += offset_in_vma;
|
||||
break;
|
||||
case VMAType::BackingMemory:
|
||||
new_vma.backing_memory += offset_in_vma;
|
||||
break;
|
||||
|
@ -395,10 +353,6 @@ void VMManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) {
|
|||
case VMAType::Free:
|
||||
Memory::UnmapRegion(page_table, vma.base, vma.size);
|
||||
break;
|
||||
case VMAType::AllocatedMemoryBlock:
|
||||
Memory::MapMemoryRegion(page_table, vma.base, vma.size,
|
||||
vma.backing_block->data() + vma.offset);
|
||||
break;
|
||||
case VMAType::BackingMemory:
|
||||
Memory::MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory);
|
||||
break;
|
||||
|
|
|
@ -18,13 +18,10 @@ namespace Kernel {
|
|||
enum class VMAType : u8 {
|
||||
/// VMA represents an unmapped region of the address space.
|
||||
Free,
|
||||
/// VMA is backed by a ref-counted allocate memory block.
|
||||
AllocatedMemoryBlock,
|
||||
/// VMA is backed by a raw, unmanaged pointer.
|
||||
BackingMemory,
|
||||
/// VMA is mapped to MMIO registers at a fixed PAddr.
|
||||
MMIO,
|
||||
// TODO(yuriks): Implement MemoryAlias to support MAP/UNMAP
|
||||
};
|
||||
|
||||
/// Permissions for mapped memory blocks
|
||||
|
@ -72,12 +69,6 @@ struct VirtualMemoryArea {
|
|||
/// Tag returned by svcQueryMemory. Not otherwise used.
|
||||
MemoryState meminfo_state = MemoryState::Free;
|
||||
|
||||
// Settings for type = AllocatedMemoryBlock
|
||||
/// Memory block backing this VMA.
|
||||
std::shared_ptr<std::vector<u8>> backing_block = nullptr;
|
||||
/// Offset into the backing_memory the mapping starts from.
|
||||
std::size_t offset = 0;
|
||||
|
||||
// Settings for type = BackingMemory
|
||||
/// Pointer backing this VMA. It will not be destroyed or freed when the VMA is removed.
|
||||
u8* backing_memory = nullptr;
|
||||
|
@ -133,18 +124,6 @@ public:
|
|||
|
||||
// TODO(yuriks): Should these functions actually return the handle?
|
||||
|
||||
/**
|
||||
* Maps part of a ref-counted block of memory at a given address.
|
||||
*
|
||||
* @param target The guest address to start the mapping at.
|
||||
* @param block The block to be mapped.
|
||||
* @param offset Offset into `block` to map from.
|
||||
* @param size Size of the mapping.
|
||||
* @param state MemoryState tag to attach to the VMA.
|
||||
*/
|
||||
ResultVal<VMAHandle> MapMemoryBlock(VAddr target, std::shared_ptr<std::vector<u8>> block,
|
||||
std::size_t offset, u32 size, MemoryState state);
|
||||
|
||||
/**
|
||||
* Maps part of a ref-counted block of memory at the first free address after the given base.
|
||||
*
|
||||
|
@ -203,12 +182,6 @@ public:
|
|||
/// Changes the permissions of a range of addresses, splitting VMAs as necessary.
|
||||
ResultCode ReprotectRange(VAddr target, u32 size, VMAPermission new_perms);
|
||||
|
||||
/**
|
||||
* Scans all VMAs and updates the page table range of any that use the given vector as backing
|
||||
* memory. This should be called after any operation that causes reallocation of the vector.
|
||||
*/
|
||||
void RefreshMemoryBlockMappings(const std::vector<u8>* block);
|
||||
|
||||
/// Dumps the address space layout to the log, for debugging
|
||||
void LogLayout(Log::Level log_level) const;
|
||||
|
||||
|
|
|
@ -92,9 +92,6 @@ static u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) {
|
|||
|
||||
auto& vma = it->second;
|
||||
switch (vma.type) {
|
||||
case Kernel::VMAType::AllocatedMemoryBlock:
|
||||
direct_pointer = vma.backing_block->data() + vma.offset;
|
||||
break;
|
||||
case Kernel::VMAType::BackingMemory:
|
||||
direct_pointer = vma.backing_memory;
|
||||
break;
|
||||
|
|
|
@ -39,7 +39,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") {
|
|||
auto vma = manager->FindVMA(Memory::HEAP_VADDR);
|
||||
CHECK(vma != manager->vma_map.end());
|
||||
CHECK(vma->second.type == Kernel::VMAType::Free);
|
||||
CHECK(vma->second.backing_block == nullptr);
|
||||
CHECK(vma->second.backing_memory == nullptr);
|
||||
}
|
||||
|
||||
SECTION("changing memory permissions") {
|
||||
|
|
Loading…
Reference in a new issue