diff --git a/src/relf/relf.c b/src/relf/relf.c index 81d5386..b682613 100644 --- a/src/relf/relf.c +++ b/src/relf/relf.c @@ -73,6 +73,8 @@ relf_value_t relf_open(relf_t* relf, const char* path) TRACE("mmap failed errno %d %s\n", errno, strerror(errno)); return RELF_ERROR(RELF_MMAP_FAILED); } + + // now we need to parse segments and section headers return RELF_ERROR(RELF_OK); } diff --git a/src/relf/relf.h b/src/relf/relf.h index f232eed..2111cd4 100644 --- a/src/relf/relf.h +++ b/src/relf/relf.h @@ -15,7 +15,10 @@ typedef enum { typedef union { relf_error_t error; - uintptr_t value; + // yeah, we're going to always use 64bit value so + // we won't get any undefined behavior regardless + // host and target architectures + uint64_t value; } relf_value_t; // supply relf_value_t type here @@ -27,6 +30,38 @@ typedef enum { RELF_32BIT } relf_type_t; +// we're using our own structures so parsing +// logic wouldn't be cluttered with 32 and 64 bit branching + +// prefix convention +// f_ - file positioning aka file offsets +// v_ - virtual memory in runtime + +// ELF program segment +typedef struct { + uint32_t type; + uint32_t flags; + + // file offset and size + uint64_t f_offset; + uint64_t f_size; + + // address and size in virtual memory in runtime + uint64_t v_addr; + uint64_t v_size; +} relf_segment_t; + +// ELF section +typedef struct { + uint32_t type; + uint32_t flags; + + const char* name; + + uint64_t f_offset; + uint64_t f_size; +} relf_section_t; + // relf instance typedef struct { void* image;