Add TODO on reserve

This commit is contained in:
Daniel R. 2024-07-10 19:41:03 +02:00
parent 7a83b74d3e
commit e531c77fe0
No known key found for this signature in database
GPG Key ID: B8ADC8F57BA18DBA
2 changed files with 8 additions and 5 deletions

View File

@ -84,9 +84,10 @@ void MemoryManager::Free(PAddr phys_addr, size_t size) {
}
int MemoryManager::Reserve(void** out_addr, VAddr virtual_addr, size_t size, MemoryMapFlags flags,
u64 alignment) {
u64 alignment) {
std::scoped_lock lk{mutex};
// TODO: Search for free space if virtual_addr is zero
virtual_addr = (virtual_addr == 0) ? impl.VirtualBase() : virtual_addr;
VAddr mapped_addr = alignment > 0 ? Common::AlignUp(virtual_addr, alignment) : virtual_addr;
@ -170,7 +171,7 @@ int MemoryManager::MapFile(void** out_addr, VAddr virtual_addr, size_t size, Mem
} else {
LOG_INFO(Kernel_Vmm, "Virtual addr {:#x} with size {:#x}", virtual_addr, size);
}
VAddr mapped_addr = 0;
const size_t size_aligned = Common::AlignUp(size, 16_KB);
@ -188,7 +189,8 @@ int MemoryManager::MapFile(void** out_addr, VAddr virtual_addr, size_t size, Mem
if (True(flags & MemoryMapFlags::Fixed)) {
const auto& vma = FindVMA(virtual_addr)->second;
const size_t remaining_size = vma.base + vma.size - virtual_addr;
ASSERT_MSG((vma.type == VMAType::Free || vma.type == VMAType::Reserved) && remaining_size >= size);
ASSERT_MSG((vma.type == VMAType::Free || vma.type == VMAType::Reserved) &&
remaining_size >= size);
mapped_addr = virtual_addr;
}
@ -338,7 +340,8 @@ VirtualMemoryArea& MemoryManager::AddMapping(VAddr virtual_addr, size_t size) {
ASSERT_MSG(vma_handle != vma_map.end(), "Virtual address not in vm_map");
const VirtualMemoryArea& vma = vma_handle->second;
ASSERT_MSG((vma.type == VMAType::Free || vma.type == VMAType::Reserved) && vma.base <= virtual_addr,
ASSERT_MSG((vma.type == VMAType::Free || vma.type == VMAType::Reserved) &&
vma.base <= virtual_addr,
"Adding a mapping to already mapped region");
const VAddr start_in_vma = virtual_addr - vma.base;

View File

@ -138,7 +138,7 @@ public:
void Free(PAddr phys_addr, size_t size);
int Reserve(void** out_addr, VAddr virtual_addr, size_t size, MemoryMapFlags flags,
u64 alignment = 0);
u64 alignment = 0);
int MapMemory(void** out_addr, VAddr virtual_addr, size_t size, MemoryProt prot,
MemoryMapFlags flags, VMAType type, std::string_view name = "",