Make exec return an error if the loaded executable would use more memory than is currently available

This commit is contained in:
apio 2022-10-12 19:22:08 +02:00
parent 9cddf9485d
commit e37ff67da2

View File

@ -4,6 +4,7 @@
#include "errno.h"
#include "interrupts/Interrupts.h"
#include "memory/MemoryManager.h"
#include "memory/PMM.h"
#include "std/stdlib.h"
#include "std/string.h"
#include "sys/elf/ELFLoader.h"
@ -32,7 +33,8 @@ void sys_exec(Context* context, const char* pathname)
return;
}
if (ELFLoader::check_elf_image(program) < 0)
long memusage;
if ((memusage = ELFLoader::check_elf_image(program)) < 0)
{
context->rax = -ENOEXEC;
return;
@ -45,6 +47,13 @@ void sys_exec(Context* context, const char* pathname)
return;
}
if (memusage > PMM::get_free())
{
MemoryManager::release_pages((void*)allocated_stack, TASK_PAGES_IN_STACK);
context->rax = -ENOMEM;
return;
}
Interrupts::disable();
ASSERT(!Interrupts::are_enabled()); // This part is pretty sensitive.