From 06af9f31878b233534e5412e5434878f63b54d1a Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 29 Sep 2023 02:05:12 +0300 Subject: [PATCH] LibELF: Optimize LoadableELF::clone() memory usage We only clone mapped pages that have been marked as writeble. Read/execute only pages will be exactly as in the file itself and can be demand paged also :D --- LibELF/LibELF/LoadableELF.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LibELF/LibELF/LoadableELF.cpp b/LibELF/LibELF/LoadableELF.cpp index d25860bd..106c3142 100644 --- a/LibELF/LibELF/LoadableELF.cpp +++ b/LibELF/LibELF/LoadableELF.cpp @@ -252,6 +252,9 @@ namespace LibELF break; case PT_LOAD: { + if (!(program_header.p_flags & LibELF::PF_W)) + continue; + PageTable::flags_t flags = PageTable::Flags::UserSupervisor | PageTable::Flags::Present; if (program_header.p_flags & LibELF::PF_W) flags |= PageTable::Flags::ReadWrite;