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
Kernel - Added a per-thread timer object to reduce malloc use
[tpg/acess2.git]
/
AcessNative
/
ld-acess_src
/
binary.c
diff --git
a/AcessNative/ld-acess_src/binary.c
b/AcessNative/ld-acess_src/binary.c
index
6439fb9
..
d04ac6d
100644
(file)
--- a/
AcessNative/ld-acess_src/binary.c
+++ b/
AcessNative/ld-acess_src/binary.c
@@
-1,12
+1,17
@@
/*
/*
- * AcessNative
+ * AcessNative Dynamic Linker
+ * - By John Hodge (thePowersGang)
+ *
+ * binary.c
+ * - Provides binary loading and type abstraction
*/
*/
+#define DEBUG 0
#include "common.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#define LIBRARY_PATH "$$$$../Usermode/Output/
i386
/Libs"
+#define LIBRARY_PATH "$$$$../Usermode/Output/
x86_64
/Libs"
// === TYPES ===
typedef struct sBinary {
// === TYPES ===
typedef struct sBinary {
@@
-19,10
+24,11
@@
typedef struct sBinary {
// === IMPORTS ===
extern void *Elf_Load(int fd);
// === IMPORTS ===
extern void *Elf_Load(int fd);
-extern uintptr_t Elf
_
Relocate(void *Base);
-extern int Elf
_GetSymbol(void *Base, char *Name, uintptr_t *ret
);
+extern uintptr_t ElfRelocate(void *Base);
+extern int Elf
GetSymbol(void *Base, char *Name, uintptr_t *ret, size_t *size
);
extern int ciNumBuiltinSymbols;
extern tSym caBuiltinSymbols[];
extern int ciNumBuiltinSymbols;
extern tSym caBuiltinSymbols[];
+extern char **gEnvP;
// === PROTOTYPES ===
void Binary_AddToList(const char *Filename, void *Base, tBinFmt *Format);
// === PROTOTYPES ===
void Binary_AddToList(const char *Filename, void *Base, tBinFmt *Format);
@@
-33,8
+39,8
@@
tBinFmt gElf_FormatDef = {
// .Magic = "\x7F""ELF",
.Name = "ELF32",
.Load = Elf_Load,
// .Magic = "\x7F""ELF",
.Name = "ELF32",
.Load = Elf_Load,
- .Relocate = Elf
_
Relocate,
- .GetSymbol = Elf
_
GetSymbol
+ .Relocate = ElfRelocate,
+ .GetSymbol = ElfGetSymbol
};
tBinary *gLoadedBinaries;
};
tBinary *gLoadedBinaries;
@@
-96,7
+102,7
@@
void *Binary_LoadLibrary(const char *Name)
{
char *path;
void *ret;
{
char *path;
void *ret;
- int (*entry)(int,char*[],char**) = NULL;
+ int (*entry)(
void *,
int,char*[],char**) = NULL;
// Find File
path = Binary_LocateLibrary(Name);
// Find File
path = Binary_LocateLibrary(Name);
@@
-108,6
+114,8
@@
void *Binary_LoadLibrary(const char *Name)
}
ret = Binary_Load(path, (uintptr_t*)&entry);
}
ret = Binary_Load(path, (uintptr_t*)&entry);
+ if( ret != (void*)-1 )
+ Debug("LOADED '%s' to %p (Entry=%p)", path, ret, entry);
free(path);
#if DEBUG
free(path);
#if DEBUG
@@
-118,7
+126,7
@@
void *Binary_LoadLibrary(const char *Name)
#if DEBUG
printf("Calling '%s' entry point %p\n", Name, entry);
#endif
#if DEBUG
printf("Calling '%s' entry point %p\n", Name, entry);
#endif
- entry(
0, argv, NULL
);
+ entry(
ret, 0, argv, gEnvP
);
}
return ret;
}
return ret;
@@
-155,7
+163,7
@@
void *Binary_Load(const char *Filename, uintptr_t *EntryPoint)
return NULL;
}
return NULL;
}
- acess_read(fd,
4, &dword
);
+ acess_read(fd,
&dword, 4
);
acess_seek(fd, 0, ACESS_SEEK_SET);
if( memcmp(&dword, "\x7F""ELF", 4) == 0 ) {
acess_seek(fd, 0, ACESS_SEEK_SET);
if( memcmp(&dword, "\x7F""ELF", 4) == 0 ) {
@@
-168,12
+176,12
@@
void *Binary_Load(const char *Filename, uintptr_t *EntryPoint)
}
#if DEBUG
}
#if DEBUG
- printf("fmt->Load(
%i
)...\n", fd);
+ printf("fmt->Load(
0x%x
)...\n", fd);
#endif
ret = fmt->Load(fd);
acess_close(fd);
#if DEBUG
#endif
ret = fmt->Load(fd);
acess_close(fd);
#if DEBUG
- printf("fmt->Load(
%p
): %p\n", fd, ret);
+ printf("fmt->Load(
0x%x
): %p\n", fd, ret);
#endif
if( !ret ) {
return NULL;
#endif
if( !ret ) {
return NULL;
@@
-220,7
+228,7
@@
void Binary_SetReadyToUse(void *Base)
}
}
}
}
-int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value)
+int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value
, size_t *Size
)
{
int i;
tBinary *bin;
{
int i;
tBinary *bin;
@@
-235,6
+243,7
@@
int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value)
{
if( strcmp(caBuiltinSymbols[i].Name, SymbolName) == 0 ) {
*Value = (uintptr_t)caBuiltinSymbols[i].Value;
{
if( strcmp(caBuiltinSymbols[i].Name, SymbolName) == 0 ) {
*Value = (uintptr_t)caBuiltinSymbols[i].Value;
+ if(Size) *Size = 0;
return 1;
}
}
return 1;
}
}
@@
-244,11
+253,13
@@
int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value)
{
if( !bin->Ready ) continue;
//printf(" Binary_GetSymbol: bin = %p{%p, %s}\n", bin, bin->Base, bin->Path);
{
if( !bin->Ready ) continue;
//printf(" Binary_GetSymbol: bin = %p{%p, %s}\n", bin, bin->Base, bin->Path);
- if( bin->Format->GetSymbol(bin->Base, (char*)SymbolName, Value) )
+ if( bin->Format->GetSymbol(bin->Base, (char*)SymbolName, Value
, Size
) )
return 1;
}
//printf("Binary_GetSymbol: RETURN 0, not found\n");
return 1;
}
//printf("Binary_GetSymbol: RETURN 0, not found\n");
-
+ printf("--- ERROR: Unable to find symbol '%s'\n", SymbolName);
+
+ exit( -1 );
return 0;
}
return 0;
}
UCC
git Repository :: git.ucc.asn.au