git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
Usermode/ld-acess - Overhaul cleanup of ELF loader
[tpg/acess2.git]
/
KernelLand
/
Kernel
/
bin
/
elf.c
diff --git
a/KernelLand/Kernel/bin/elf.c
b/KernelLand/Kernel/bin/elf.c
index
7998d86
..
37172cf
100644
(file)
--- a/
KernelLand/Kernel/bin/elf.c
+++ b/
KernelLand/Kernel/bin/elf.c
@@
-205,15
+205,14
@@
tBinary *Elf_Load32(int FD, Elf32_Ehdr *Header)
{
\r
tBinary *ret;
\r
Elf32_Phdr *phtab;
\r
- int i, j;
\r
- int iLoadCount;
\r
+ int j;
\r
\r
ENTER("xFD", FD);
\r
\r
// Check architecture with current CPU
\r
// - TODO: Support kernel level emulation
\r
#if ARCH_IS_x86
\r
- if( Header->machine != EM_386 )
\r
+ if( Header->
e_
machine != EM_386 )
\r
{
\r
Log_Warning("ELF", "Unknown architecure on ELF-32");
\r
LEAVE_RET('n');
\r
@@
-222,7
+221,7
@@
tBinary *Elf_Load32(int FD, Elf32_Ehdr *Header)
#endif
\r
\r
// Check for a program header
\r
- if(Header->phoff == 0) {
\r
+ if(Header->
e_
phoff == 0) {
\r
#if DEBUG_WARN
\r
Log_Warning("ELF", "File does not contain a program header (phoff == 0)");
\r
#endif
\r
@@
-231,25
+230,25
@@
tBinary *Elf_Load32(int FD, Elf32_Ehdr *Header)
}
\r
\r
// Read Program Header Table
\r
- phtab = malloc( sizeof(Elf32_Phdr) * Header->
phentcount
);
\r
+ phtab = malloc( sizeof(Elf32_Phdr) * Header->
e_phnum
);
\r
if( !phtab ) {
\r
LEAVE('n');
\r
return NULL;
\r
}
\r
- LOG("hdr.phoff = 0x%08x", Header->phoff);
\r
- VFS_Seek(FD, Header->phoff, SEEK_SET);
\r
- VFS_Read(FD, sizeof(Elf32_Phdr)*Header->
phentcount
, phtab);
\r
+ LOG("hdr.phoff = 0x%08x", Header->
e_
phoff);
\r
+ VFS_Seek(FD, Header->
e_
phoff, SEEK_SET);
\r
+ VFS_Read(FD, sizeof(Elf32_Phdr)*Header->
e_phnum
, phtab);
\r
\r
// Count Pages
\r
- iLoadCount = 0;
\r
- LOG("Header->phentcount = %i", Header->
phentcount
);
\r
- for( i
= 0; i < Header->phentcount
; i++ )
\r
+
unsigned
iLoadCount = 0;
\r
+ LOG("Header->phentcount = %i", Header->
e_phnum
);
\r
+ for( i
nt i = 0; i < Header->e_phnum
; i++ )
\r
{
\r
// Ignore Non-LOAD types
\r
- if(phtab[i].
T
ype != PT_LOAD)
\r
+ if(phtab[i].
p_t
ype != PT_LOAD)
\r
continue;
\r
iLoadCount ++;
\r
- LOG("phtab[%i] = {VAddr:0x%x, MemSize:0x%x}", i, phtab[i].
VAddr, phtab[i].MemSize
);
\r
+ LOG("phtab[%i] = {VAddr:0x%x, MemSize:0x%x}", i, phtab[i].
p_vaddr, phtab[i].p_memsz
);
\r
}
\r
\r
LOG("iLoadCount = %i", iLoadCount);
\r
@@
-257,56
+256,55
@@
tBinary *Elf_Load32(int FD, Elf32_Ehdr *Header)
// Allocate Information Structure
\r
ret = malloc( sizeof(tBinary) + sizeof(tBinarySection)*iLoadCount );
\r
// Fill Info Struct
\r
- ret->Entry = Header->e
ntrypoint
;
\r
+ ret->Entry = Header->e
_entry
;
\r
ret->Base = -1; // Set Base to maximum value
\r
ret->NumSections = iLoadCount;
\r
ret->Interpreter = NULL;
\r
\r
// Load Pages
\r
j = 0;
\r
- for( i
= 0; i < Header->phentcount
; i++ )
\r
+ for( i
nt i = 0; i < Header->e_phnum
; i++ )
\r
{
\r
//LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type);
\r
LOG("phtab[%i] = {", i);
\r
- LOG(" .Type = 0x%08x",
phtab[i].T
ype);
\r
- LOG(" .Offset = 0x%08x", phtab[i].
O
ffset);
\r
- LOG(" .VAddr = 0x%08x",
phtab[i].VA
ddr);
\r
- LOG(" .PAddr = 0x%08x",
phtab[i].PA
ddr);
\r
- LOG(" .FileSize = 0x%08x", phtab[i].
FileSize
);
\r
- LOG(" .MemSize = 0x%08x", phtab[i].
MemSize
);
\r
- LOG(" .Flags = 0x%08x",
phtab[i].F
lags);
\r
- LOG(" .Align = 0x%08x",
phtab[i].A
lign);
\r
+ LOG(" .Type = 0x%08x",
phtab[i].p_t
ype);
\r
+ LOG(" .Offset = 0x%08x", phtab[i].
p_o
ffset);
\r
+ LOG(" .VAddr = 0x%08x",
phtab[i].p_va
ddr);
\r
+ LOG(" .PAddr = 0x%08x",
phtab[i].p_pa
ddr);
\r
+ LOG(" .FileSize = 0x%08x", phtab[i].
p_filesz
);
\r
+ LOG(" .MemSize = 0x%08x", phtab[i].
p_memsz
);
\r
+ LOG(" .Flags = 0x%08x",
phtab[i].p_f
lags);
\r
+ LOG(" .Align = 0x%08x",
phtab[i].p_a
lign);
\r
LOG(" }");
\r
// Get Interpreter Name
\r
- if( phtab[i].
T
ype == PT_INTERP )
\r
+ if( phtab[i].
p_t
ype == PT_INTERP )
\r
{
\r
- char *tmp;
\r
if(ret->Interpreter) continue;
\r
-
tmp = malloc(phtab[i].FileSize
);
\r
- VFS_Seek(FD, phtab[i].
O
ffset, 1);
\r
- VFS_Read(FD, phtab[i].
FileSize
, tmp);
\r
+
char* tmp = malloc(phtab[i].p_filesz
);
\r
+ VFS_Seek(FD, phtab[i].
p_o
ffset, 1);
\r
+ VFS_Read(FD, phtab[i].
p_filesz
, tmp);
\r
ret->Interpreter = Binary_RegInterp(tmp);
\r
LOG("Interpreter '%s'", tmp);
\r
free(tmp);
\r
continue;
\r
}
\r
// Ignore non-LOAD types
\r
- if(phtab[i].
Type != PT_LOAD)
continue;
\r
+ if(phtab[i].
p_type != PT_LOAD)
continue;
\r
\r
// Find Base
\r
- if(phtab[i].
VAddr < ret->Base) ret->Base = phtab[i].VA
ddr;
\r
+ if(phtab[i].
p_vaddr < ret->Base) ret->Base = phtab[i].p_va
ddr;
\r
\r
LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}",
\r
- i, phtab[i].
VAddr, phtab[i].Offset, phtab[i].FileSize
);
\r
+ i, phtab[i].
p_vaddr, phtab[i].p_offset, phtab[i].p_filesz
);
\r
\r
- ret->LoadSections[j].Offset
= phtab[i].O
ffset;
\r
- ret->LoadSections[j].FileSize = phtab[i].
FileSize
;
\r
- ret->LoadSections[j].Virtual
= phtab[i].VA
ddr;
\r
- ret->LoadSections[j].MemSize
= phtab[i].MemSize
;
\r
+ ret->LoadSections[j].Offset
= phtab[i].p_o
ffset;
\r
+ ret->LoadSections[j].FileSize = phtab[i].
p_filesz
;
\r
+ ret->LoadSections[j].Virtual
= phtab[i].p_va
ddr;
\r
+ ret->LoadSections[j].MemSize
= phtab[i].p_memsz
;
\r
ret->LoadSections[j].Flags = 0;
\r
- if( !(phtab[i].
F
lags & PF_W) )
\r
+ if( !(phtab[i].
p_f
lags & PF_W) )
\r
ret->LoadSections[j].Flags |= BIN_SECTFLAG_RO;
\r
- if( phtab[i].
F
lags & PF_X )
\r
+ if( phtab[i].
p_f
lags & PF_X )
\r
ret->LoadSections[j].Flags |= BIN_SECTFLAG_EXEC;
\r
j ++;
\r
}
\r
UCC
git Repository :: git.ucc.asn.au