#ifndef __LIBELFU_GENERIC_H__
#define __LIBELFU_GENERIC_H__
-#include <libelf/gelf.h>
+#include <gelf.h>
+
+
+#ifndef MIN
+ #define MIN(x, y) ((x) < (y) ? (x) : (y))
+#endif
+
+#ifndef MAX
+ #define MAX(x, y) ((x) > (y) ? (x) : (y))
+#endif
+
+#ifndef ROUNDUP
+ #define ROUNDUP(x, align) ((x) + ((align) - ((x) % (align))) % (align))
+#endif
+
#define OFFS_END(off, sz) ((off) + (sz))
-int elfu_gPhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr);
+#define SCNFILESIZE(shdr) ((shdr)->sh_type == SHT_NOBITS ? 0 : (shdr)->sh_size)
+
+
+
+#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))
-size_t elfu_gScnSizeFile(const GElf_Shdr *shdr);
#endif