elf: move struct definition to header
This commit is contained in:
parent
6a00aa4762
commit
60e71f6521
38
core/elf.c
38
core/elf.c
@ -18,35 +18,7 @@ uaddr_t loadElfProg(const char *prog, struct process * proc)
|
|||||||
int i;
|
int i;
|
||||||
uaddr_t lastUserAddr = 0;
|
uaddr_t lastUserAddr = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Typedefs, constants and structure definitions as given by the ELF
|
|
||||||
* standard specifications.
|
|
||||||
*/
|
|
||||||
typedef unsigned long Elf32_Addr;
|
|
||||||
typedef unsigned long Elf32_Word;
|
|
||||||
typedef unsigned short Elf32_Half;
|
|
||||||
typedef unsigned long Elf32_Off;
|
|
||||||
// typedef signed long Elf32_Sword;
|
|
||||||
|
|
||||||
/* Elf identification */
|
|
||||||
|
|
||||||
#define EI_NIDENT 16
|
|
||||||
typedef struct {
|
|
||||||
unsigned char e_ident[EI_NIDENT];
|
|
||||||
Elf32_Half e_type;
|
|
||||||
Elf32_Half e_machine;
|
|
||||||
Elf32_Word e_version;
|
|
||||||
Elf32_Addr e_entry;
|
|
||||||
Elf32_Off e_phoff;
|
|
||||||
Elf32_Off e_shoff;
|
|
||||||
Elf32_Word e_flags;
|
|
||||||
Elf32_Half e_ehsize;
|
|
||||||
Elf32_Half e_phentsize;
|
|
||||||
Elf32_Half e_phnum;
|
|
||||||
Elf32_Half e_shentsize;
|
|
||||||
Elf32_Half e_shnum;
|
|
||||||
Elf32_Half e_shstrndx;
|
|
||||||
} __attribute__((packed)) Elf32_Ehdr_t;
|
|
||||||
|
|
||||||
/* e_ident value */
|
/* e_ident value */
|
||||||
#define ELFMAG0 0x7f
|
#define ELFMAG0 0x7f
|
||||||
@ -97,16 +69,6 @@ uaddr_t loadElfProg(const char *prog, struct process * proc)
|
|||||||
#define EV_NONE 0 /* invalid version */
|
#define EV_NONE 0 /* invalid version */
|
||||||
#define EV_CURRENT 1 /* current version */
|
#define EV_CURRENT 1 /* current version */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Elf32_Word p_type;
|
|
||||||
Elf32_Off p_offset;
|
|
||||||
Elf32_Addr p_vaddr;
|
|
||||||
Elf32_Addr p_paddr;
|
|
||||||
Elf32_Word p_filesz;
|
|
||||||
Elf32_Word p_memsz;
|
|
||||||
Elf32_Word p_flags;
|
|
||||||
Elf32_Word p_align;
|
|
||||||
} __attribute__((packed)) Elf32_Phdr_t;
|
|
||||||
|
|
||||||
/* Reserved segment types p_type */
|
/* Reserved segment types p_type */
|
||||||
#define PT_NULL 0
|
#define PT_NULL 0
|
||||||
|
93
core/elf.h
93
core/elf.h
@ -3,4 +3,97 @@
|
|||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Typedefs, constants and structure definitions as given by the ELF
|
||||||
|
* standard specifications.
|
||||||
|
*/
|
||||||
|
typedef unsigned long Elf32_Addr;
|
||||||
|
typedef unsigned long Elf32_Word;
|
||||||
|
typedef unsigned short Elf32_Half;
|
||||||
|
typedef unsigned long Elf32_Off;
|
||||||
|
// typedef signed long Elf32_Sword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ELF 32-bit format related structures.
|
||||||
|
* See http://www.cs.cmu.edu/afs/cs/academic/class/15213-f00/docs/elf.pdf
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SHT_NULL 0
|
||||||
|
#define SHT_PROGBITS 1
|
||||||
|
#define SHT_SYMTAB 2
|
||||||
|
#define SHT_STRTAB 3
|
||||||
|
#define SHT_RELA 4
|
||||||
|
#define SHT_HASH 5
|
||||||
|
#define SHT_DYNAMIC 6
|
||||||
|
#define SHT_NOTE 7
|
||||||
|
#define SHT_NOBITS 8
|
||||||
|
#define SHT_REL 9
|
||||||
|
#define SHT_SHLIB 10
|
||||||
|
#define SHT_DYNSYM 11
|
||||||
|
#define SHT_LOPROC 0x70000000
|
||||||
|
#define SHT_HIPROC 0x7fffffff
|
||||||
|
#define SHT_LOUSER 0x80000000
|
||||||
|
#define SHT_HIUSER 0xffffffff
|
||||||
|
|
||||||
|
|
||||||
|
/** ELF Header **/
|
||||||
|
#define EI_NIDENT 16
|
||||||
|
typedef struct {
|
||||||
|
unsigned char e_ident[EI_NIDENT];
|
||||||
|
Elf32_Half e_type;
|
||||||
|
Elf32_Half e_machine;
|
||||||
|
Elf32_Word e_version;
|
||||||
|
Elf32_Addr e_entry;
|
||||||
|
Elf32_Off e_phoff;
|
||||||
|
Elf32_Off e_shoff;
|
||||||
|
Elf32_Word e_flags;
|
||||||
|
Elf32_Half e_ehsize;
|
||||||
|
Elf32_Half e_phentsize;
|
||||||
|
Elf32_Half e_phnum;
|
||||||
|
Elf32_Half e_shentsize;
|
||||||
|
Elf32_Half e_shnum;
|
||||||
|
Elf32_Half e_shstrndx;
|
||||||
|
} __attribute__((packed)) Elf32_Ehdr_t;
|
||||||
|
|
||||||
|
/** ELF Section header */
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word sh_name;
|
||||||
|
Elf32_Word sh_type;
|
||||||
|
Elf32_Word sh_flags;
|
||||||
|
Elf32_Addr sh_addr;
|
||||||
|
Elf32_Off sh_offset;
|
||||||
|
Elf32_Word sh_size;
|
||||||
|
Elf32_Word sh_link;
|
||||||
|
Elf32_Word sh_info;
|
||||||
|
Elf32_Word sh_addralign;
|
||||||
|
Elf32_Word sh_entsize;
|
||||||
|
} __attribute__((packed)) Elf32_Shdr_t;
|
||||||
|
|
||||||
|
/** ELF Symbol **/
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word st_name;
|
||||||
|
Elf32_Addr st_value;
|
||||||
|
Elf32_Word st_size;
|
||||||
|
unsigned char st_info;
|
||||||
|
unsigned char st_other;
|
||||||
|
Elf32_Half st_shndx;
|
||||||
|
} __attribute__((packed)) Elf32_Sym_t;
|
||||||
|
|
||||||
|
/** ELF Program header **/
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word p_type;
|
||||||
|
Elf32_Off p_offset;
|
||||||
|
Elf32_Addr p_vaddr;
|
||||||
|
Elf32_Addr p_paddr;
|
||||||
|
Elf32_Word p_filesz;
|
||||||
|
Elf32_Word p_memsz;
|
||||||
|
Elf32_Word p_flags;
|
||||||
|
Elf32_Word p_align;
|
||||||
|
} __attribute__((packed)) Elf32_Phdr_t;
|
||||||
|
|
||||||
|
#define ELF_SYM_TYPE(info) ((info) & 0xf)
|
||||||
|
#define ELF_SYM_TYPE_FUNC 0x2
|
||||||
|
|
||||||
|
|
||||||
uaddr_t loadElfProg(const char *prog, struct process *proc);
|
uaddr_t loadElfProg(const char *prog, struct process *proc);
|
||||||
|
Loading…
Reference in New Issue
Block a user