X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Fld-acess.so_src%2Fmain.c;fp=Usermode%2FLibraries%2Fld-acess.so_src%2Fmain.c;h=dfb1b6158e02d876d76ac8b6b28e6373db482fb6;hb=3d6a345b39afa454f0f33fc8d48b96229971e6ed;hp=85fbc74da90540f8f13825c33ac130b869f5944c;hpb=89690cfe3d3ff74ffd5f3e7bf4c2140b7f894c1f;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/ld-acess.so_src/main.c b/Usermode/Libraries/ld-acess.so_src/main.c index 85fbc74d..dfb1b615 100644 --- a/Usermode/Libraries/ld-acess.so_src/main.c +++ b/Usermode/Libraries/ld-acess.so_src/main.c @@ -2,13 +2,14 @@ AcessOS 1 - Dynamic Loader By thePowersGang */ +#include #include "common.h" // === PROTOTYPES === - int DoRelocate( Uint base, char **envp, char *Filename ); - int CallUser(Uint entry, Uint SP); - int ElfRelocate(void *Base, char *envp[], char *Filename); - int PE_Relocate(void *Base, char *envp[], char *Filename); +void *DoRelocate(void *base, char **envp, char *Filename); + int CallUser(void *Entry, void *SP); +void *ElfRelocate(void *Base, char *envp[], char *Filename); +void *PE_Relocate(void *Base, char *envp[], char *Filename); // === Imports === extern void gLinkedBase; @@ -20,24 +21,25 @@ extern tLoadedLib gLoadedLibraries[]; \brief Library entry point \note This is the entrypoint for the library */ -int SoMain(Uint base, int arg1) +int SoMain(void *base, void *arg1) { - int ret; + void *ret; // - Assume that the file pointer will be less than 4096 - if(base < 0x1000) { + if((intptr_t)base < 0x1000) { SysDebug("ld-acess - SoMain: Passed file pointer %i\n", base); _exit(-1); for(;;); } // Check if we are being called directly - if(base == (Uint)&gLinkedBase) { + if(base == &gLinkedBase) { SysDebug("ld-acess should not be directly called\n"); _exit(1); for(;;); } - gLoadedLibraries[0].Base = (Uint)&gLinkedBase; + gLoadedLibraries[0].Base = &gLinkedBase; + // 'libld-acess.so' because that is what applications link against gLoadedLibraries[0].Name = "/Acess/Libs/libld-acess.so"; // Otherwise do relocations @@ -51,22 +53,22 @@ int SoMain(Uint base, int arg1) // And call user //SysDebug("Calling User at 0x%x\n", ret); - CallUser( ret, (Uint)&arg1 ); + CallUser( ret, &arg1 ); return 0; } /** - \fn int DoRelocate(Uint base, char **envp) + \fn int DoRelocate(void *base, char **envp) \brief Relocates an in-memory image */ -int DoRelocate( Uint base, char **envp, char *Filename ) +void *DoRelocate(void *base, char **envp, char *Filename) { // Load Executable - if(*(Uint*)base == (0x7F|('E'<<8)|('L'<<16)|('F'<<24))) - return ElfRelocate((void*)base, envp, Filename); + if(*(Uint32*)base == (0x7F|('E'<<8)|('L'<<16)|('F'<<24))) + return ElfRelocate(base, envp, Filename); if(*(Uint16*)base == ('M'|('Z'<<8))) - return PE_Relocate((void*)base, envp, Filename); + return PE_Relocate(base, envp, Filename); SysDebug("ld-acess - DoRelocate: Unkown file format '0x%x 0x%x 0x%x 0x%x'\n", *(Uint8*)(base), *(Uint8*)(base+1), *(Uint8*)(base+2), *(Uint8*)(base+3) ); @@ -78,13 +80,20 @@ int DoRelocate( Uint base, char **envp, char *Filename ) /** \fn int CallUser(Uint entry, Uint sp) */ -int CallUser(Uint entry, Uint sp) +int CallUser(void *entry, void *sp) { - //SysDebug("CallUser: (entry=0x%x, sp=0x%x)", entry, sp); - *(Uint*)(sp-4) = 0; // Clear return address + #if ARCHDIR_IS_x86_64 + ((void **)sp)[-1] = 0; // Clear return address + __asm__ __volatile__ ( + "mov %%rax, %%rsp;\n\t" + "jmp *%%rcx" + : : "a"(sp), "c"(entry)); + #elif ARCHDIR_IS_x86 + ((void **)sp)[-1] = 0; // Clear return address __asm__ __volatile__ ( "mov %%eax, %%esp;\n\t" "jmp *%%ecx" : : "a"(sp), "c"(entry)); + #endif for(;;); }