mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-05-28 15:34:26 +00:00
Fix elf interpreter
This commit is contained in:
parent
c20aae9504
commit
baacbbdbd7
5
.vscode/c_cpp_properties.json
vendored
5
.vscode/c_cpp_properties.json
vendored
@ -54,7 +54,10 @@
|
|||||||
{
|
{
|
||||||
"name": "Fennix x32 (Linux, GCC, debug)",
|
"name": "Fennix x32 (Linux, GCC, debug)",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/include/**"
|
"${workspaceFolder}/libc/include/**",
|
||||||
|
"${workspaceFolder}/out/system/include/**",
|
||||||
|
"${workspaceFolder}/libs/include/**",
|
||||||
|
"${workspaceFolder}/libs/include"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"__debug_vscode__",
|
"__debug_vscode__",
|
||||||
|
@ -20,26 +20,26 @@ int main(int argc, char *argv[], char *envp[])
|
|||||||
for (int i = 0; i < 14; i++)
|
for (int i = 0; i < 14; i++)
|
||||||
PutCharToKernelConsole("\nHello World!\n"[i]);
|
PutCharToKernelConsole("\nHello World!\n"[i]);
|
||||||
print("%p %p %p\n", (void *)(uint64_t)&argc, (void *)&argv, (void *)&envp);
|
print("%p %p %p\n", (void *)(uint64_t)&argc, (void *)&argv, (void *)&envp);
|
||||||
// print("I have %d arguments\n", argc);
|
print("I have %d arguments\n", argc);
|
||||||
// for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
// print("argv[%d] = (%p) %s\n", i, argv[i], argv[i]);
|
print("argv[%d] = (%p) %s\n", i, argv[i], argv[i]);
|
||||||
|
|
||||||
// int envc = 0;
|
int envc = 0;
|
||||||
// while (envp[envc] != NULL)
|
while (envp[envc] != NULL)
|
||||||
// envc++;
|
envc++;
|
||||||
|
|
||||||
// print("I have %d environment variables\n", envc);
|
print("I have %d environment variables\n", envc);
|
||||||
// for (int i = 0; i < envc; i++)
|
for (int i = 0; i < envc; i++)
|
||||||
// print("envp[%d] = (%p) %s\n", i, envp[i], envp[i]);
|
print("envp[%d] = (%p) %s\n", i, envp[i], envp[i]);
|
||||||
|
|
||||||
// Elf64_auxv_t *auxv;
|
Elf64_auxv_t *auxv;
|
||||||
// char **e = envp;
|
char **e = envp;
|
||||||
|
|
||||||
// while (*e++ != NULL)
|
while (*e++ != NULL)
|
||||||
// ;
|
;
|
||||||
|
|
||||||
// for (auxv = (Elf64_auxv_t *)e; auxv->a_type != AT_NULL; auxv++)
|
for (auxv = (Elf64_auxv_t *)e; auxv->a_type != AT_NULL; auxv++)
|
||||||
// print("auxv: %ld %#lx\n", auxv->a_type, auxv->a_un.a_val);
|
print("auxv: %ld %#lx\n", auxv->a_type, auxv->a_un.a_val);
|
||||||
|
|
||||||
File *test = FileOpen("/Test.txt", FILE_READ);
|
File *test = FileOpen("/Test.txt", FILE_READ);
|
||||||
if (test == NULL)
|
if (test == NULL)
|
||||||
|
@ -246,16 +246,16 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibAddressCollection *Info, long RelIndex))(
|
|||||||
if (Info)
|
if (Info)
|
||||||
{
|
{
|
||||||
struct LibAddressCollection *CurLib = Info;
|
struct LibAddressCollection *CurLib = Info;
|
||||||
PrintNL("_______");
|
// PrintNL("_______");
|
||||||
// The last entry is the null entry (Valid == false) which determines the end of the list.
|
// The last entry is the null entry (Valid == false) which determines the end of the list.
|
||||||
while (CurLib->Valid)
|
while (CurLib->Valid)
|
||||||
{
|
{
|
||||||
Print("-- ");
|
// Print("-- ");
|
||||||
Print(CurLib->Name);
|
// Print(CurLib->Name);
|
||||||
Print(" ");
|
// Print(" ");
|
||||||
ltoa(RelIndex, DbgBuff, 10);
|
// ltoa(RelIndex, DbgBuff, 10);
|
||||||
Print(DbgBuff);
|
// Print(DbgBuff);
|
||||||
PrintNL(" --");
|
// PrintNL(" --");
|
||||||
uintptr_t lib_BaseAddress = __UINTPTR_MAX__;
|
uintptr_t lib_BaseAddress = __UINTPTR_MAX__;
|
||||||
uintptr_t app_BaseAddress = __UINTPTR_MAX__;
|
uintptr_t app_BaseAddress = __UINTPTR_MAX__;
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibAddressCollection *Info, long RelIndex))(
|
|||||||
{
|
{
|
||||||
case R_X86_64_NONE:
|
case R_X86_64_NONE:
|
||||||
{
|
{
|
||||||
PrintNL("R_X86_64_NONE");
|
// PrintNL("R_X86_64_NONE");
|
||||||
if (*GOTEntry == 0)
|
if (*GOTEntry == 0)
|
||||||
{
|
{
|
||||||
PrintNL("GOTEntry is 0");
|
PrintNL("GOTEntry is 0");
|
||||||
@ -346,34 +346,34 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibAddressCollection *Info, long RelIndex))(
|
|||||||
}
|
}
|
||||||
case R_X86_64_JUMP_SLOT:
|
case R_X86_64_JUMP_SLOT:
|
||||||
{
|
{
|
||||||
PrintNL("R_X86_64_JUMP_SLOT");
|
// PrintNL("R_X86_64_JUMP_SLOT");
|
||||||
int SymIndex = ELF64_R_SYM(Rel->r_info);
|
int SymIndex = ELF64_R_SYM(Rel->r_info);
|
||||||
Elf64_Sym *Sym = _app_SymTab + SymIndex;
|
Elf64_Sym *Sym = _app_SymTab + SymIndex;
|
||||||
|
|
||||||
if (Sym->st_name)
|
if (Sym->st_name)
|
||||||
{
|
{
|
||||||
char *SymName = app_DynStr + Sym->st_name;
|
char *SymName = app_DynStr + Sym->st_name;
|
||||||
Print("SymName: ");
|
// Print("SymName: ");
|
||||||
PrintNL(SymName);
|
// PrintNL(SymName);
|
||||||
|
|
||||||
Elf64_Sym *LibSym = ELFLookupSymbol(CurLib->ElfFile, SymName);
|
Elf64_Sym *LibSym = ELFLookupSymbol(CurLib->ElfFile, SymName);
|
||||||
|
|
||||||
Print("LibSym: 0x");
|
// Print("LibSym: 0x");
|
||||||
ltoa((long)LibSym, DbgBuff, 16);
|
// ltoa((long)LibSym, DbgBuff, 16);
|
||||||
PrintNL(DbgBuff);
|
// PrintNL(DbgBuff);
|
||||||
|
|
||||||
if (LibSym)
|
if (LibSym)
|
||||||
{
|
{
|
||||||
*GOTEntry = (Elf64_Addr)(CurLib->MemoryImage + LibSym->st_value);
|
*GOTEntry = (Elf64_Addr)(CurLib->MemoryImage + LibSym->st_value);
|
||||||
|
|
||||||
ltoa(*GOTEntry, DbgBuff, 16);
|
// ltoa(*GOTEntry, DbgBuff, 16);
|
||||||
Print("*GOTEntry: 0x");
|
// Print("*GOTEntry: 0x");
|
||||||
PrintNL(DbgBuff);
|
// PrintNL(DbgBuff);
|
||||||
|
|
||||||
Lock = 0;
|
Lock = 0;
|
||||||
return (void (*)()) * GOTEntry;
|
return (void (*)()) * GOTEntry;
|
||||||
}
|
}
|
||||||
PrintNL("Not found in lib");
|
// PrintNL("Not found in lib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibAddressCollection *Info, long RelIndex))(
|
|||||||
}
|
}
|
||||||
|
|
||||||
RetryNextLib:
|
RetryNextLib:
|
||||||
PrintNL("Retrying next lib");
|
// PrintNL("Retrying next lib");
|
||||||
CurLib = CurLib->Next;
|
CurLib = CurLib->Next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,8 +508,8 @@ int ld_load(int argc, char *argv[], char *envp[])
|
|||||||
CurrentLibsForLazyResolver->Valid = true;
|
CurrentLibsForLazyResolver->Valid = true;
|
||||||
CurrentLibsForLazyResolver->ElfFile = (uintptr_t)lib_addr;
|
CurrentLibsForLazyResolver->ElfFile = (uintptr_t)lib_addr;
|
||||||
CurrentLibsForLazyResolver->MemoryImage = (uintptr_t)lib_mm_image;
|
CurrentLibsForLazyResolver->MemoryImage = (uintptr_t)lib_mm_image;
|
||||||
LibsForLazyResolver->ParentElfFile = (uintptr_t)IPCBuffer->ElfFile;
|
CurrentLibsForLazyResolver->ParentElfFile = (uintptr_t)IPCBuffer->ElfFile;
|
||||||
LibsForLazyResolver->ParentMemoryImage = (uintptr_t)IPCBuffer->MemoryImage;
|
CurrentLibsForLazyResolver->ParentMemoryImage = (uintptr_t)IPCBuffer->MemoryImage;
|
||||||
for (size_t j = 0; j < 32; j++)
|
for (size_t j = 0; j < 32; j++)
|
||||||
CurrentLibsForLazyResolver->Name[j] = IPCBuffer->Libraries[i].Name[j];
|
CurrentLibsForLazyResolver->Name[j] = IPCBuffer->Libraries[i].Name[j];
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
/* This function is a mess and needs to be cleaned up. */
|
/* This function is a mess and needs to be cleaned up. */
|
||||||
/*
|
|
||||||
bool ELFDynamicReallocation(void *ElfFile, void *MemoryImage)
|
bool ELFDynamicReallocation(void *ElfFile, void *MemoryImage)
|
||||||
{
|
{
|
||||||
debug("ELF dynamic reallocation for image at %#lx.", ElfFile);
|
debug("ELF dynamic reallocation for image at %#lx.", ElfFile);
|
||||||
@ -177,9 +176,7 @@ bool ELFDynamicReallocation(void *ElfFile, void *MemoryImage)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
ELFDynamicReallocation(ElfFile, MemoryImage);
|
ELFDynamicReallocation(ElfFile, MemoryImage);
|
||||||
|
|
||||||
@ -250,4 +247,4 @@ bool ELFDynamicReallocation(void *ElfFile, void *MemoryImage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ELFAddLazyResolverToGOT(ElfFile, MemoryImage, LibsForLazyResolver);
|
ELFAddLazyResolverToGOT(ElfFile, MemoryImage, LibsForLazyResolver);
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user