-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathload.h
164 lines (155 loc) · 3.5 KB
/
load.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
///
/// \file load.h
/// \brief Functions to load executable
/// \defgroup load Executable Loader
/// \brief Parses and loads ELFs
/// @{
///
#ifndef UVL_LOAD
#define UVL_LOAD
#include "types.h"
/** \name ELF data types
* @{
*/
typedef void* Elf32_Addr;
typedef u32_t Elf32_Off;
typedef u32_t Elf32_Sword;
typedef u32_t Elf32_Word;
typedef u16_t Elf32_Half;
/** @}*/
/** \name ELF identification
* @{
*/
#define EI_NIDENT 16
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_PAD 7
#define ELFMAG0 0x7F
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFCLASS32 1
#define ELFDATA2LSB 1
/** @}*/
/** \name ELF object types
* @{
*/
#define ET_EXEC 0x0002
#define ET_SCE_EXEC 0xFE00
#define ET_SCE_RELEXEC 0xFE04
/** @}*/
/** \name ELF machine types
* @{
*/
#define EM_ARM 40
/** @}*/
/** \name ELF version
* @{
*/
#define EV_CURRENT 1
/** @}*/
/** \name ELF sh section type
* @{
*/
#define SHT_RELA 4
#define SHT_REL 9
/** @}*/
/** \name ELF ph section type
* @{
*/
#define PT_LOAD 1
#define PT_SCE_RELA 0x60000000
/** @}*/
/** \name ELF ph formats
* @{
*/
#define PF_X 1
#define PF_W 2
#define PF_R 4
/** @}*/
/** \name SCE identification
* @{
*/
#define MAGIC_LEN 4
#define SCEMAG0 'S'
#define SCEMAG1 'C'
#define SCEMAG2 'E'
#define SCEMAG3 0
/** @}*/
#define UVL_SEC_MODINFO ".sceModuleInfo.rodata" ///< Name of module information section
#define UVL_SEC_MIN_ALIGN 0x100000 ///< Alignment of each section
#define ATTR_MOD_INFO 0x8000 ///< module_exports_t attribute
/** \name ELF structures
* See the ELF specification for more information.
* @{
*/
typedef struct Elf32_Ehdr
{
u8_t 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;
} Elf32_Ehdr_t;
typedef struct Elf32_Shdr
{
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;
} Elf32_Shdr_t;
typedef struct Elf32_Phdr
{
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;
} Elf32_Phdr_t;
/** @}*/
/** \cond predefined-types
* @{
*/
typedef struct module_info module_info_t;
typedef struct uvl_loaded uvl_loaded_t;
/** @}*/
/** \name Functions to load code
* @{
*/
int uvl_load_file (const char *filename, void **data, PsvSSize *size);
int uvl_load_exe (const char *filename, void **entry, uvl_loaded_t *loaded);
int uvl_load_elf (void *data, void **entry, uvl_loaded_t *loaded);
/** @}*/
/** \name Helper functions
* @{
*/
int uvl_resolve_import_by_name(const char *name);
int uvl_elf_check_header (Elf32_Ehdr_t *hdr);
int uvl_elf_get_module_info (Elf32_Ehdr_t *elf_hdr, Elf32_Phdr_t *elf_phdrs, module_info_t **mod_info);
//int uvl_elf_free_memory (Elf32_Phdr_t *prog_hdrs, int count);
/** @}*/
#endif
/// @}