1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

Fix VMO leak in Process::exec().

Gotta make sure things get cleaned up before we yield-teleport in exec().
Also VMOs and regions are now viewable through /proc/mm and /proc/regions.
This commit is contained in:
Andreas Kling 2018-11-08 22:24:02 +01:00
parent cd1e7419f0
commit 7b96218389
4 changed files with 51 additions and 8 deletions

View file

@ -307,15 +307,11 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
return -ENOTIMPL;
}
{ // Put everything into a scope so things get cleaned up before we yield-teleport into the new executable.
auto vmo = VMObject::create_file_backed(descriptor->vnode(), descriptor->metadata().size);
vmo->set_name(descriptor->absolute_path());
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copyRef(), 0, "helper", true, false);
#if 0
auto elfData = descriptor->readEntireFile();
if (!elfData)
return -EIO; // FIXME: Get a more detailed error from VFS.
#endif
dword entry_eip = 0;
PageDirectory* old_page_directory = m_page_directory;
PageDirectory* new_page_directory = reinterpret_cast<PageDirectory*>(kmalloc_page_aligned(sizeof(PageDirectory)));
@ -324,6 +320,7 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
m_page_directory = new_page_directory;
MM.enter_process_paging_scope(*this);
// FIXME: Should we consider doing on-demand paging here? Is it actually useful?
bool success = region->page_in(*new_page_directory);
ASSERT(success);
@ -400,10 +397,11 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
#endif
set_state(Skip1SchedulerPass);
} // Ready to yield-teleport!
if (current == this) {
bool success = Scheduler::yield();
ASSERT(success);
ASSERT_NOT_REACHED();
}
return 0;