2006-09-07 16:12:30 +02:00
|
|
|
// Format of an ELF executable file
|
2006-08-29 21:06:37 +02:00
|
|
|
|
2024-06-15 16:55:06 +02:00
|
|
|
#define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian
|
2006-06-12 17:22:12 +02:00
|
|
|
|
2006-09-07 16:12:30 +02:00
|
|
|
// File header
|
2006-07-17 03:58:13 +02:00
|
|
|
struct elfhdr {
|
2024-06-15 16:55:06 +02:00
|
|
|
u32 magic; // must equal ELF_MAGIC
|
|
|
|
u8 elf[12];
|
2024-05-24 11:26:40 +02:00
|
|
|
u16 type;
|
|
|
|
u16 machine;
|
|
|
|
u32 version;
|
|
|
|
u64 entry;
|
|
|
|
u64 phoff;
|
|
|
|
u64 shoff;
|
|
|
|
u32 flags;
|
|
|
|
u16 ehsize;
|
|
|
|
u16 phentsize;
|
|
|
|
u16 phnum;
|
|
|
|
u16 shentsize;
|
|
|
|
u16 shnum;
|
|
|
|
u16 shstrndx;
|
2006-06-12 17:22:12 +02:00
|
|
|
};
|
|
|
|
|
2006-09-07 16:12:30 +02:00
|
|
|
// Program section header
|
2006-07-17 03:58:13 +02:00
|
|
|
struct proghdr {
|
2024-05-24 11:26:40 +02:00
|
|
|
u32 type;
|
|
|
|
u32 flags;
|
|
|
|
u64 off;
|
|
|
|
u64 vaddr;
|
|
|
|
u64 paddr;
|
|
|
|
u64 filesz;
|
|
|
|
u64 memsz;
|
|
|
|
u64 align;
|
2006-06-12 17:22:12 +02:00
|
|
|
};
|
|
|
|
|
2006-07-16 17:41:47 +02:00
|
|
|
// Values for Proghdr type
|
2024-06-15 16:55:06 +02:00
|
|
|
#define ELF_PROG_LOAD 1
|
2006-06-12 17:22:12 +02:00
|
|
|
|
2006-07-16 17:41:47 +02:00
|
|
|
// Flag bits for Proghdr flags
|
2024-06-15 16:55:06 +02:00
|
|
|
#define ELF_PROG_FLAG_EXEC 1
|
|
|
|
#define ELF_PROG_FLAG_WRITE 2
|
|
|
|
#define ELF_PROG_FLAG_READ 4
|