\r
void *Elf32Load(int FD, Elf32_Ehdr *hdr)\r
{\r
- Elf32_Phdr *phtab;\r
- int i;\r
- int iPageCount;\r
- uint32_t max, base;\r
- uint32_t addr;\r
- uint32_t baseDiff = 0;\r
- \r
ENTER("iFD", FD);\r
\r
// Check for a program header\r
}\r
\r
// Read Program Header Table\r
- phtab = malloc( sizeof(Elf32_Phdr) * hdr->e_phnum );\r
+ Elf32_Phdr* phtab = malloc( sizeof(Elf32_Phdr) * hdr->e_phnum );\r
if( !phtab ) {\r
LEAVE('n');\r
return NULL;\r
acess__SysRead(FD, phtab, sizeof(Elf32_Phdr) * hdr->e_phnum);\r
\r
// Count Pages\r
- iPageCount = 0;\r
+ unsigned int iPageCount = 0;\r
LOG("hdr.e_phnum = %i\n", hdr->e_phnum);\r
- for( i = 0; i < hdr->e_phnum; i++ )\r
+ for( unsigned int i = 0; i < hdr->e_phnum; i++ )\r
{\r
// Ignore Non-LOAD types\r
if(phtab[i].p_type != PT_LOAD)\r
//ret->Interpreter = NULL;\r
\r
// Prescan for base and size\r
- max = 0;\r
- base = 0xFFFFFFFF;\r
- for( i = 0; i < hdr->e_phnum; i ++)\r
+ uint32_t max = 0;\r
+ uint32_t base = UINT32_MAX;\r
+ for( unsigned int i = 0; i < hdr->e_phnum; i ++)\r
{\r
if( phtab[i].p_type != PT_LOAD )\r
continue;\r
\r
LOG("base = %08x, max = %08x\n", base, max);\r
\r
+ uint32_t baseDiff = 0;\r
if( base == 0 ) {\r
// Find a nice space (47 address bits allowed)\r
base = FindFreeRange( max, 47 );\r
}\r
\r
// Load Pages\r
- for( i = 0; i < hdr->e_phnum; i++ )\r
+ for( unsigned int i = 0; i < hdr->e_phnum; i++ )\r
{\r
// Get Interpreter Name\r
if( phtab[i].p_type == PT_INTERP )\r
LOG("phtab[%i] = PT_LOAD {Adj p_vaddr:0x%x, p_offset:0x%x, p_filesz:0x%x, p_memsz:0x%x}\n",\r
i, phtab[i].p_vaddr+baseDiff, phtab[i].p_offset, phtab[i].p_filesz, phtab[i].p_memsz);\r
\r
- addr = phtab[i].p_vaddr + baseDiff;\r
+ uint64_t addr = phtab[i].p_vaddr + baseDiff;\r
\r
if( AllocateMemory( addr, phtab[i].p_memsz ) ) {\r
- fprintf(stderr, "Elf_Load: Unable to map memory at %x (0x%x bytes)\n",\r
+ fprintf(stderr, "Elf_Load: Unable to map memory at 0x%"PRIx64" (0x%x bytes)\n",\r
addr, phtab[i].p_memsz);\r
free( phtab );\r
return NULL;\r
\r
void *Elf64Load(int FD, Elf64_Ehdr *hdr)\r
{\r
- Elf64_Phdr *phtab;\r
- int i;\r
- int iPageCount;\r
- uint64_t max, base;\r
- uint64_t addr;\r
- uint64_t baseDiff = 0;\r
- \r
ENTER("iFD", FD);\r
\r
if( sizeof(void*) == 4) {\r
}\r
\r
// Read Program Header Table\r
- phtab = malloc( sizeof(Elf64_Phdr) * hdr->e_phnum );\r
+ Elf64_Phdr* phtab = malloc( sizeof(Elf64_Phdr) * hdr->e_phnum );\r
if( !phtab ) {\r
LEAVE('n');\r
return NULL;\r
acess__SysRead(FD, phtab, sizeof(Elf64_Phdr) * hdr->e_phnum);\r
\r
// Count Pages\r
- iPageCount = 0;\r
+ unsigned int iPageCount = 0;\r
LOG("hdr.e_phnum = %i\n", hdr->e_phnum);\r
- for( i = 0; i < hdr->e_phnum; i++ )\r
+ for( unsigned int i = 0; i < hdr->e_phnum; i++ )\r
{\r
// Ignore Non-LOAD types\r
if(phtab[i].p_type != PT_LOAD)\r
//ret->Interpreter = NULL;\r
\r
// Prescan for base and size\r
- max = 0;\r
- base = 0xFFFFFFFF;\r
- for( i = 0; i < hdr->e_phnum; i ++)\r
+ uint64_t max = 0;\r
+ uint64_t base = UINT64_MAX;\r
+ for( unsigned int i = 0; i < hdr->e_phnum; i ++)\r
{\r
if( phtab[i].p_type != PT_LOAD )\r
continue;\r
\r
LOG("base = %08lx, max = %08lx\n", base, max);\r
\r
+ uint64_t baseDiff = 0;\r
if( base == 0 ) {\r
// Find a nice space (31 address bits allowed)\r
base = FindFreeRange( max, 31 );\r
LOG("new base = %08lx\n", base);\r
- if( base == 0 ) return NULL;\r
+ if( base == 0 )\r
+ goto _err;\r
baseDiff = base;\r
}\r
\r
// Load Pages\r
- for( i = 0; i < hdr->e_phnum; i++ )\r
+ for( unsigned int i = 0; i < hdr->e_phnum; i++ )\r
{\r
// Get Interpreter Name\r
if( phtab[i].p_type == PT_INTERP )\r
(long long)phtab[i].p_filesz, (long long)phtab[i].p_memsz\r
);\r
\r
- addr = phtab[i].p_vaddr + baseDiff;\r
+ uint64_t addr = phtab[i].p_vaddr + baseDiff;\r
\r
if( AllocateMemory( addr, phtab[i].p_memsz ) ) {\r
fprintf(stderr, "Elf_Load: Unable to map memory at %"PRIx64" (0x%"PRIx64" bytes)\n",\r
(uint64_t)addr, (uint64_t)phtab[i].p_memsz);\r
- free( phtab );\r
- return NULL;\r
+ goto _err;\r
}\r
\r
acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
// Return\r
LEAVE('p', base);\r
return PTRMK(void, base);\r
+_err:\r
+ free(phtab);\r
+ LEAVE('n');\r
+ return NULL;\r
}\r
\r