summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/elf.c')
-rw-r--r--arch/x86_64/elf.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/arch/x86_64/elf.c b/arch/x86_64/elf.c
new file mode 100644
index 0000000..696b7a7
--- /dev/null
+++ b/arch/x86_64/elf.c
@@ -0,0 +1,27 @@
+#include "elf.h"
+#include <stddef.h>
+
+int
+elf64_ehdr_valid(Elf64_Ehdr *ehdr)
+{
+ if(ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
+ ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
+ ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
+ ehdr->e_ident[EI_MAG3] != ELFMAG3)
+ return 0;
+ if(ehdr->e_ident[EI_CLASS] != ELFCLASS64) return 0;
+ if(ehdr->e_ident[EI_DATA] != ELFDATA2LSB) return 0;
+ if(ehdr->e_type != ET_EXEC) return 0;
+ if(ehdr->e_machine != EM_X86_64) return 0;
+
+ return 1;
+}
+
+void*
+elf64_loadexec(Elf64_Ehdr *ehdr)
+{
+ if(!elf64_ehdr_valid(ehdr)) return NULL;
+
+ void *entry = (void*)ehdr->e_entry;
+ return entry;
+}