From 6a6a9a2e94f14470f26c2e74767b5ebb48dd7df2 Mon Sep 17 00:00:00 2001 From: norly Date: Sat, 25 May 2013 00:45:39 +0100 Subject: [PATCH] Fix alignment error in mInsertSpaceBefore --- src/model/insert.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/model/insert.c b/src/model/insert.c index 312be26..b18aa8a 100644 --- a/src/model/insert.c +++ b/src/model/insert.c @@ -27,6 +27,11 @@ GElf_Xword elfu_mInsertSpaceBefore(ElfuElf *me, GElf_Off off, GElf_Xword size) assert(me); + /* Round up size to 4096 bytes to keep page alignment on x86 when + * remapping existing data to lower addresses. */ + size += (4096 - (size % 4096)) % 4096; + // TODO: Find alignment size by checking p_align in PHDRs + /* Move SHDRs and PHDRs */ if (me->ehdr.e_shoff >= off) { me->ehdr.e_shoff += size; -- 2.30.2