Relax restrictions on NOBITS sections
[centaur.git] / include / libelfu / generic.h
index c74981aa99eadc91481f1e00b188a64ca040bd7e..4e3239db2e33d618e2f62e2a68d4e7942fb24a14 100644 (file)
@@ -1,7 +1,13 @@
 #ifndef __LIBELFU_GENERIC_H__
 #define __LIBELFU_GENERIC_H__
 
-#include <libelf/gelf.h>
+#include <gelf.h>
+
+
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#define ROUNDUP(x, align) ((x) + ((align) - ((x) % (align))) % (align))
+
 
 #define OFFS_END(off, sz) ((off) + (sz))
 
 #define SCNFILESIZE(shdr) ((shdr)->sh_type == SHT_NOBITS ? 0 : (shdr)->sh_size)
 
 
-int elfu_gPhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr);
+
+#define PHDR_CONTAINS_SCN_IN_MEMORY(phdr, shdr) \
+  (((phdr)->p_vaddr) <= ((shdr)->sh_addr) \
+   && OFFS_END((shdr)->sh_addr, (shdr)->sh_size) <= OFFS_END((phdr)->p_vaddr, (phdr)->p_memsz))
+
+#define PHDR_CONTAINS_SCN_IN_FILE(phdr, shdr) \
+  (((phdr)->p_offset) <= ((shdr)->sh_offset) \
+   && OFFS_END((shdr)->sh_offset, SCNFILESIZE(shdr)) <= OFFS_END((phdr)->p_offset, (phdr)->p_filesz))
 
 
 #endif