Fix alignment error in mInsertSpaceBefore
authornorly <ny-git@enpas.org>
Fri, 24 May 2013 23:45:39 +0000 (00:45 +0100)
committernorly <ny-git@enpas.org>
Fri, 24 May 2013 23:45:39 +0000 (00:45 +0100)
src/model/insert.c

index 312be26c79393d2723e15a115feb37071d7206c7..b18aa8aed80ade86b52d5fb4a6df8274c142b646 100644 (file)
@@ -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;