define structures to abstract 32 and 64 bit differences in parsing
This commit is contained in:
parent
9e80bee9aa
commit
caf85718e7
2 changed files with 38 additions and 1 deletions
|
|
@ -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));
|
TRACE("mmap failed errno %d %s\n", errno, strerror(errno));
|
||||||
return RELF_ERROR(RELF_MMAP_FAILED);
|
return RELF_ERROR(RELF_MMAP_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now we need to parse segments and section headers
|
||||||
|
|
||||||
return RELF_ERROR(RELF_OK);
|
return RELF_ERROR(RELF_OK);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@ typedef enum {
|
||||||
typedef union {
|
typedef union {
|
||||||
relf_error_t error;
|
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;
|
} relf_value_t;
|
||||||
|
|
||||||
// supply relf_value_t type here
|
// supply relf_value_t type here
|
||||||
|
|
@ -27,6 +30,38 @@ typedef enum {
|
||||||
RELF_32BIT
|
RELF_32BIT
|
||||||
} relf_type_t;
|
} 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
|
// relf instance
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void* image;
|
void* image;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue