Use TRY in MMU.cpp
This commit is contained in:
parent
2c9329928c
commit
9d318d50aa
@ -196,10 +196,9 @@ namespace MMU
|
||||
auto& l4 = l4_entry(virt);
|
||||
if (!l4.present)
|
||||
{
|
||||
auto addr = MemoryManager::alloc_physical_page();
|
||||
if (addr.has_error()) return addr.release_error();
|
||||
u64 addr = TRY(MemoryManager::alloc_physical_page());
|
||||
l4.present = true;
|
||||
l4.set_address(addr.release_value());
|
||||
l4.set_address(addr);
|
||||
memset(l3_table(virt), 0, PAGE_SIZE);
|
||||
l4.ignore0 = l4.ignore1 = 0;
|
||||
}
|
||||
@ -209,10 +208,9 @@ namespace MMU
|
||||
auto& l3 = l3_entry(virt);
|
||||
if (!l3.present)
|
||||
{
|
||||
auto addr = MemoryManager::alloc_physical_page();
|
||||
if (addr.has_error()) return addr.release_error();
|
||||
u64 addr = TRY(MemoryManager::alloc_physical_page());
|
||||
l3.present = true;
|
||||
l3.set_address(addr.release_value());
|
||||
l3.set_address(addr);
|
||||
memset(l2_table(virt), 0, PAGE_SIZE);
|
||||
l3.ignore0 = l3.ignore1 = 0;
|
||||
}
|
||||
@ -224,10 +222,9 @@ namespace MMU
|
||||
auto& l2 = l2_entry(virt);
|
||||
if (!l2.present)
|
||||
{
|
||||
auto addr = MemoryManager::alloc_physical_page();
|
||||
if (addr.has_error()) return addr.release_error();
|
||||
u64 addr = TRY(MemoryManager::alloc_physical_page());
|
||||
l2.present = true;
|
||||
l2.set_address(addr.release_value());
|
||||
l2.set_address(addr);
|
||||
memset(l1_table(virt), 0, PAGE_SIZE);
|
||||
l2.ignore0 = l2.ignore1 = 0;
|
||||
}
|
||||
@ -251,9 +248,7 @@ namespace MMU
|
||||
|
||||
Result<void> remap(u64 virt, int flags)
|
||||
{
|
||||
auto rc = apply_cascading_flags(virt, flags);
|
||||
if (rc.has_error()) return rc.release_error();
|
||||
auto& l1 = *rc.release_value();
|
||||
auto& l1 = *TRY(apply_cascading_flags(virt, flags));
|
||||
if (!l1.present) return err;
|
||||
l1.read_write = (flags & Flags::ReadWrite);
|
||||
l1.user = (flags & Flags::User);
|
||||
@ -265,9 +260,7 @@ namespace MMU
|
||||
|
||||
Result<u64> unmap(u64 virt)
|
||||
{
|
||||
auto rc = find_entry(virt);
|
||||
if (rc.has_error()) return rc.release_error();
|
||||
auto& l1 = *rc.release_value();
|
||||
auto& l1 = *TRY(find_entry(virt));
|
||||
if (!l1.present) return err;
|
||||
u64 address = l1.get_address();
|
||||
memset(&l1, 0, sizeof(l1));
|
||||
@ -277,18 +270,14 @@ namespace MMU
|
||||
|
||||
Result<u64> get_physical(u64 virt)
|
||||
{
|
||||
auto rc = find_entry(virt);
|
||||
if (rc.has_error()) return rc.release_error();
|
||||
auto& l1 = *rc.release_value();
|
||||
auto& l1 = *TRY(find_entry(virt));
|
||||
if (!l1.present) return err;
|
||||
return l1.get_address();
|
||||
}
|
||||
|
||||
Result<int> get_flags(u64 virt)
|
||||
{
|
||||
auto rc = find_entry(virt);
|
||||
if (rc.has_error()) return rc.release_error();
|
||||
auto& l1 = *rc.release_value();
|
||||
auto& l1 = *TRY(find_entry(virt));
|
||||
if (!l1.present) return err;
|
||||
return arch_flags_to_mmu(l1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user