2 AcessOS 1 - Dynamic Loader
\r
8 // === PROTOTYPES ===
\r
9 void *DoRelocate(void *base, char **envp, const char *Filename);
\r
10 int CallUser(void *Entry, void *SP);
\r
11 void *ElfRelocate(void *Base, char **envp, const char *Filename);
\r
12 void *PE_Relocate(void *Base, char **envp, const char *Filename);
\r
15 extern void gLinkedBase;
\r
16 extern tLoadedLib gLoadedLibraries[];
\r
20 \fn int SoMain(Uint base, int argc, char *argv[], char **envp)
\r
21 \brief Library entry point
\r
22 \note This is the entrypoint for the library
\r
24 void *SoMain(void *base)
\r
28 // - Assume that the file pointer will be less than 4096
\r
29 if((intptr_t)base < 0x1000) {
\r
30 SysDebug("ld-acess - SoMain: Passed file pointer %i\n", base);
\r
34 // Check if we are being called directly
\r
35 if(base == &gLinkedBase) {
\r
36 SysDebug("ld-acess should not be directly called\n");
\r
41 gLoadedLibraries[0].Base = &gLinkedBase;
\r
42 // 'libld-acess.so' because that is what applications link against
\r
43 gLoadedLibraries[0].Name = "/Acess/Libs/libld-acess.so";
\r
45 // Otherwise do relocations
\r
46 //ret = DoRelocate( base, envp, "Executable" );
\r
47 ret = DoRelocate( base, NULL, "Executable" );
\r
49 SysDebug("ld-acess - SoMain: Relocate failed, base=0x%x\n", base);
\r
54 SysDebug("ld-acess - SoMain: ret = %p", ret);
\r
59 \fn int DoRelocate(void *base, char **envp)
\r
60 \brief Relocates an in-memory image
\r
62 void *DoRelocate(void *base, char **envp, const char *Filename)
\r
66 if(memcmp(base, "\x7F""ELF", 4) == 0)
\r
67 return ElfRelocate(base, envp, Filename);
\r
68 if(hdr[0] == 0x7F && hdr[1] == 'E' && hdr[2] == 'L' && hdr[3] == 'F')
\r
69 return ElfRelocate(base, envp, Filename);
\r
71 if(hdr[0] == 'M' && hdr[1] == 'Z')
\r
72 return PE_Relocate(base, envp, Filename);
\r
74 SysDebug("ld-acess - DoRelocate: Unkown file format '0x%x 0x%x 0x%x 0x%x'\n",
\r
75 hdr[0], hdr[1], hdr[2], hdr[3] );
\r
76 SysDebug("ld-acess - DoRelocate: File '%s'\n", Filename);
\r
82 \fn int CallUser(Uint entry, Uint sp)
\r
84 int CallUser(void *entry, void *sp)
\r
86 #if ARCHDIR_IS_x86_64
\r
87 ((void **)sp)[-1] = 0; // Clear return address
\r
88 __asm__ __volatile__ (
\r
89 "mov %%rax, %%rsp;\n\t"
\r
91 : : "a"(sp), "c"(entry));
\r
92 #elif ARCHDIR_IS_x86
\r
93 ((void **)sp)[-1] = 0; // Clear return address
\r
94 __asm__ __volatile__ (
\r
95 "mov %%eax, %%esp;\n\t"
\r
97 : : "a"(sp), "c"(entry));
\r