Merge branch 'master' of git://git.ucc.asn.au/tpg/acess2
[tpg/acess2.git] / AcessNative / ld-acess_src / binary.c
index 746fbb8..6235431 100644 (file)
@@ -1,12 +1,13 @@
 /*
  * AcessNative
  */
+#define DEBUG  1
 #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 {
@@ -20,7 +21,7 @@ typedef struct sBinary {
 // === IMPORTS ===
 extern void    *Elf_Load(int fd);
 extern uintptr_t       ElfRelocate(void *Base);
-extern int     ElfGetSymbol(void *Base, char *Name, uintptr_t *ret);
+extern int     ElfGetSymbol(void *Base, char *Name, uintptr_t *ret, size_t *size);
 extern int     ciNumBuiltinSymbols;
 extern tSym    caBuiltinSymbols[];
 
@@ -156,7 +157,7 @@ void *Binary_Load(const char *Filename, uintptr_t *EntryPoint)
                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 ) {
@@ -169,12 +170,12 @@ void *Binary_Load(const char *Filename, uintptr_t *EntryPoint)
        }
        
        #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
-       printf("fmt->Load(%p): %p\n", fd, ret);
+       printf("fmt->Load(0x%x): %p\n", fd, ret);
        #endif
        if( !ret ) {
                return NULL;
@@ -221,7 +222,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;
@@ -236,6 +237,7 @@ int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value)
        {
                if( strcmp(caBuiltinSymbols[i].Name, SymbolName) == 0 ) {
                        *Value = (uintptr_t)caBuiltinSymbols[i].Value;
+                       if(Size)        *Size = 0;
                        return 1;
                }
        }
@@ -245,11 +247,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->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");
-       
+       printf("--- ERROR: Unable to find symbol '%s'\n", SymbolName);
+
+       exit( -1 );
        return 0;
 }

UCC git Repository :: git.ucc.asn.au