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
Merge branch 'master' of git://ted.mutabah.net/acess2
[tpg/acess2.git]
/
Usermode
/
Libraries
/
ld-acess.so_src
/
main.c
diff --git
a/Usermode/Libraries/ld-acess.so_src/main.c
b/Usermode/Libraries/ld-acess.so_src/main.c
index
dfb1b61
..
40c603e
100644
(file)
--- a/
Usermode/Libraries/ld-acess.so_src/main.c
+++ b/
Usermode/Libraries/ld-acess.so_src/main.c
@@
-3,17
+3,17
@@
By thePowersGang
\r
*/
\r
#include <stdint.h>
\r
By thePowersGang
\r
*/
\r
#include <stdint.h>
\r
+#include <stddef.h>
\r
#include "common.h"
\r
\r
// === PROTOTYPES ===
\r
#include "common.h"
\r
\r
// === PROTOTYPES ===
\r
-void *DoRelocate(void *base, char **envp, char *Filename);
\r
+void *DoRelocate(void *base, char **envp, c
onst c
har *Filename);
\r
int CallUser(void *Entry, void *SP);
\r
int CallUser(void *Entry, void *SP);
\r
-void *ElfRelocate(void *Base, char *envp[], char *Filename);
\r
-void *PE_Relocate(void *Base, char *envp[], char *Filename);
\r
\r
// === Imports ===
\r
\r
// === Imports ===
\r
-extern void gLinkedBase;
\r
-extern tLoadedLib gLoadedLibraries[];
\r
+extern char gLinkedBase[];
\r
+char **gEnvP;
\r
+extern int memcmp(const void *m1, const void *m2, size_t size);
\r
\r
// === CODE ===
\r
/**
\r
\r
// === CODE ===
\r
/**
\r
@@
-21,10
+21,12
@@
extern tLoadedLib gLoadedLibraries[];
\brief Library entry point
\r
\note This is the entrypoint for the library
\r
*/
\r
\brief Library entry point
\r
\note This is the entrypoint for the library
\r
*/
\r
-
int SoMain(void *base, void *arg1
)
\r
+
void *SoMain(void *base, int argc, char **argv, char **envp
)
\r
{
\r
void *ret;
\r
\r
{
\r
void *ret;
\r
\r
+ gEnvP = envp;
\r
+
\r
// - Assume that the file pointer will be less than 4096
\r
if((intptr_t)base < 0x1000) {
\r
SysDebug("ld-acess - SoMain: Passed file pointer %i\n", base);
\r
// - Assume that the file pointer will be less than 4096
\r
if((intptr_t)base < 0x1000) {
\r
SysDebug("ld-acess - SoMain: Passed file pointer %i\n", base);
\r
@@
-38,10
+40,6
@@
int SoMain(void *base, void *arg1)
for(;;);
\r
}
\r
\r
for(;;);
\r
}
\r
\r
- gLoadedLibraries[0].Base = &gLinkedBase;
\r
- // 'libld-acess.so' because that is what applications link against
\r
- gLoadedLibraries[0].Name = "/Acess/Libs/libld-acess.so";
\r
-
\r
// Otherwise do relocations
\r
//ret = DoRelocate( base, envp, "Executable" );
\r
ret = DoRelocate( base, NULL, "Executable" );
\r
// Otherwise do relocations
\r
//ret = DoRelocate( base, envp, "Executable" );
\r
ret = DoRelocate( base, NULL, "Executable" );
\r
@@
-50,28
+48,29
@@
int SoMain(void *base, void *arg1)
_exit(-1);
\r
for(;;);
\r
}
\r
_exit(-1);
\r
for(;;);
\r
}
\r
-
\r
- // And call user
\r
- //SysDebug("Calling User at 0x%x\n", ret);
\r
- CallUser( ret, &arg1 );
\r
-
\r
- return 0;
\r
+
\r
+ SysDebug("ld-acess - SoMain: ret = %p", ret);
\r
+ return ret;
\r
}
\r
\r
/**
\r
\fn int DoRelocate(void *base, char **envp)
\r
\brief Relocates an in-memory image
\r
*/
\r
}
\r
\r
/**
\r
\fn int DoRelocate(void *base, char **envp)
\r
\brief Relocates an in-memory image
\r
*/
\r
-void *DoRelocate(void *base, char **envp, char *Filename)
\r
+void *DoRelocate(void *base, char **envp, c
onst c
har *Filename)
\r
{
\r
{
\r
+ uint8_t *hdr = base;
\r
// Load Executable
\r
// Load Executable
\r
- if(*(Uint32*)base == (0x7F|('E'<<8)|('L'<<16)|('F'<<24)))
\r
+ if(memcmp(base, "\x7F""ELF", 4) == 0)
\r
+ return ElfRelocate(base, envp, Filename);
\r
+ if(hdr[0] == 0x7F && hdr[1] == 'E' && hdr[2] == 'L' && hdr[3] == 'F')
\r
return ElfRelocate(base, envp, Filename);
\r
return ElfRelocate(base, envp, Filename);
\r
- if(*(Uint16*)base == ('M'|('Z'<<8)))
\r
+
\r
+ if(hdr[0] == 'M' && hdr[1] == 'Z')
\r
return PE_Relocate(base, envp, Filename);
\r
\r
SysDebug("ld-acess - DoRelocate: Unkown file format '0x%x 0x%x 0x%x 0x%x'\n",
\r
return PE_Relocate(base, envp, Filename);
\r
\r
SysDebug("ld-acess - DoRelocate: Unkown file format '0x%x 0x%x 0x%x 0x%x'\n",
\r
-
*(Uint8*)(base), *(Uint8*)(base+1), *(Uint8*)(base+2), *(Uint8*)(base+3)
);
\r
+
hdr[0], hdr[1], hdr[2], hdr[3]
);
\r
SysDebug("ld-acess - DoRelocate: File '%s'\n", Filename);
\r
_exit(-1);
\r
for(;;);
\r
SysDebug("ld-acess - DoRelocate: File '%s'\n", Filename);
\r
_exit(-1);
\r
for(;;);
\r
@@
-97,3
+96,13
@@
int CallUser(void *entry, void *sp)
#endif
\r
for(;;);
\r
}
\r
#endif
\r
for(;;);
\r
}
\r
+
\r
+void exit(int val)
\r
+{
\r
+ _exit(val);
\r
+}
\r
+
\r
+void abort(void)
\r
+{
\r
+ _exit(-4);
\r
+}
\r
UCC
git Repository :: git.ucc.asn.au