More scope guards!!
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-08 15:01:04 +01:00
parent 1d5d1daa57
commit 779fda307a
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 4 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include <luna/Alignment.h> #include <luna/Alignment.h>
#include <luna/LinkedList.h> #include <luna/LinkedList.h>
#include <luna/SafeArithmetic.h> #include <luna/SafeArithmetic.h>
#include <luna/ScopeGuard.h>
#include <luna/String.h> #include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
@ -36,7 +37,9 @@ static DoublyLinkedList<HeapBlock> heap;
static Result<HeapBlock*> allocate_pages(usize count) static Result<HeapBlock*> allocate_pages(usize count)
{ {
u64 virt = TRY(KernelVM::alloc_several_pages(count)); u64 virt = TRY(KernelVM::alloc_several_pages(count));
auto vm_guard = make_scope_guard([&] { KernelVM::free_several_pages(virt, count).value(); });
void* const ptr = (void*)TRY(MemoryManager::alloc_at(virt, count, MMU::ReadWrite | MMU::NoExecute)); void* const ptr = (void*)TRY(MemoryManager::alloc_at(virt, count, MMU::ReadWrite | MMU::NoExecute));
vm_guard.deactivate();
return (HeapBlock*)ptr; return (HeapBlock*)ptr;
} }

View File

@ -51,7 +51,7 @@ namespace Scheduler
auto thread_guard = make_scope_guard([&] { delete thread; }); auto thread_guard = make_scope_guard([&] { delete thread; });
u64 thread_stack_vm = TRY(KernelVM::alloc_several_pages(4)); u64 thread_stack_vm = TRY(KernelVM::alloc_several_pages(4));
auto vm_guard = make_scope_guard([&] { KernelVM::free_several_pages(thread_stack_vm, 4); }); auto vm_guard = make_scope_guard([&] { KernelVM::free_several_pages(thread_stack_vm, 4).value(); });
TRY(MemoryManager::alloc_at(thread_stack_vm, 4, MMU::NoExecute | MMU::ReadWrite)); TRY(MemoryManager::alloc_at(thread_stack_vm, 4, MMU::NoExecute | MMU::ReadWrite));