Luna/kernel/src/thread/ELF.h

59 lines
1.8 KiB
C
Raw Normal View History

2022-12-23 12:09:21 +00:00
#pragma once
#include "fs/VFS.h"
#include "memory/UserVM.h"
2022-12-23 12:09:21 +00:00
#include <luna/Types.h>
#define ELFMAG "\177ELF"
#define SELFMAG 4
#define EI_CLASS 4 /* File class byte index */
#define ELFCLASS64 2 /* 64-bit objects */
#define EI_DATA 5 /* Data encoding byte index */
#define ELFDATA2LSB 1 /* 2's complement, little endian */
#define ET_EXEC 2 /* Executable file */
#define PT_LOAD 1 /* Loadable program segment */
#ifdef ARCH_X86_64
#define EM_MACH 62 /* AMD x86-64 architecture */
#else
#error "Unknown architecture."
#endif
typedef struct
{
u8 e_ident[16]; /* Magic number and other info */
u16 e_type; /* Object file type */
u16 e_machine; /* Architecture */
u32 e_version; /* Object file version */
u64 e_entry; /* Entry point virtual address */
u64 e_phoff; /* Program header table file offset */
u64 e_shoff; /* Section header table file offset */
u32 e_flags; /* Processor-specific flags */
u16 e_ehsize; /* ELF header size in bytes */
u16 e_phentsize; /* Program header table entry size */
u16 e_phnum; /* Program header table entry count */
u16 e_shentsize; /* Section header table entry size */
u16 e_shnum; /* Section header table entry count */
u16 e_shstrndx; /* Section header string table index */
} Elf64_Ehdr;
typedef struct
{
u32 p_type; /* Segment type */
u32 p_flags; /* Segment flags */
u64 p_offset; /* Segment file offset */
u64 p_vaddr; /* Segment virtual address */
u64 p_paddr; /* Segment physical address */
u64 p_filesz; /* Segment size in file */
u64 p_memsz; /* Segment size in memory */
u64 p_align; /* Segment alignment */
} Elf64_Phdr;
struct ELFData
{
u64 entry;
};
namespace ELFLoader
{
Result<ELFData> load(SharedPtr<VFS::Inode> inode, UserVM* vm);
2023-01-02 12:07:29 +00:00
};