diff --git a/kernel/src/sys/exec.cpp b/kernel/src/sys/exec.cpp index 5c242fbb..8d561dea 100644 --- a/kernel/src/sys/exec.cpp +++ b/kernel/src/sys/exec.cpp @@ -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.