Merge branch 'master' of git://ted.mutabah.net/acess2
[tpg/acess2.git] / AcessNative / ld-acess_src / elf_load.c
index 909c24a..19a8c13 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdio.h>\r
 #include <string.h>\r
 #include <unistd.h>\r
+#include <inttypes.h>  // PRIx64\r
 #include "common.h"\r
 #include "elf32.h"\r
 #include "elf64.h"\r
@@ -41,7 +42,7 @@ void *Elf_Load(int FD)
        Elf64_Ehdr      hdr;\r
        \r
        // Read ELF Header\r
-       acess_read(FD, &hdr, sizeof(hdr));\r
+       acess__SysRead(FD, &hdr, sizeof(hdr));\r
        \r
        // Check the file type\r
        if(hdr.e_ident[0] != 0x7F || hdr.e_ident[1] != 'E' || hdr.e_ident[2] != 'L' || hdr.e_ident[3] != 'F') {\r
@@ -88,8 +89,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr)
                return NULL;\r
        }\r
        LOG("hdr.phoff = 0x%08x\n", hdr->phoff);\r
-       acess_seek(FD, hdr->phoff, ACESS_SEEK_SET);\r
-       acess_read(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount);\r
+       acess__SysSeek(FD, hdr->phoff, ACESS_SEEK_SET);\r
+       acess__SysRead(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount);\r
        \r
        // Count Pages\r
        iPageCount = 0;\r
@@ -145,8 +146,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr)
                        char *tmp;\r
                        //if(ret->Interpreter)  continue;\r
                        tmp = malloc(phtab[i].FileSize);\r
-                       acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
-                       acess_read(FD, tmp, phtab[i].FileSize);\r
+                       acess__SysSeek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
+                       acess__SysRead(FD, tmp, phtab[i].FileSize);\r
                        //ret->Interpreter = Binary_RegInterp(tmp);\r
                        LOG("Interpreter '%s'\n", tmp);\r
                        free(tmp);\r
@@ -167,8 +168,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr)
                        return NULL;\r
                }\r
                \r
-               acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
-               acess_read(FD, PTRMK(void, addr), phtab[i].FileSize);\r
+               acess__SysSeek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
+               acess__SysRead(FD, PTRMK(void, addr), phtab[i].FileSize);\r
                memset( PTRMK(char, addr) + phtab[i].FileSize, 0, phtab[i].MemSize - phtab[i].FileSize );\r
        }\r
        \r
@@ -210,8 +211,8 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr)
                return NULL;\r
        }\r
        LOG("hdr.phoff = 0x%08llx\n", (long long)hdr->e_phoff);\r
-       acess_seek(FD, hdr->e_phoff, ACESS_SEEK_SET);\r
-       acess_read(FD, phtab, sizeof(Elf64_Phdr) * hdr->e_phnum);\r
+       acess__SysSeek(FD, hdr->e_phoff, ACESS_SEEK_SET);\r
+       acess__SysRead(FD, phtab, sizeof(Elf64_Phdr) * hdr->e_phnum);\r
        \r
        // Count Pages\r
        iPageCount = 0;\r
@@ -269,8 +270,8 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr)
                        //if(ret->Interpreter)  continue;\r
                        tmp = malloc(phtab[i].p_filesz+1);\r
                        tmp[ phtab[i].p_filesz ] = 0;\r
-                       acess_seek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
-                       acess_read(FD, tmp, phtab[i].p_filesz);\r
+                       acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
+                       acess__SysRead(FD, tmp, phtab[i].p_filesz);\r
                        //ret->Interpreter = Binary_RegInterp(tmp);\r
                        LOG("Interpreter '%s'\n", tmp);\r
                        free(tmp);\r
@@ -288,14 +289,14 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr)
                addr = phtab[i].p_vaddr + baseDiff;\r
 \r
                if( AllocateMemory( addr, phtab[i].p_memsz ) ) {\r
-                       fprintf(stderr, "Elf_Load: Unable to map memory at %llx (0x%llx bytes)\n",\r
-                               (long long)addr, (long long)phtab[i].p_memsz);\r
+                       fprintf(stderr, "Elf_Load: Unable to map memory at %"PRIx64" (0x%"PRIx64" bytes)\n",\r
+                               (uint64_t)addr, (uint64_t)phtab[i].p_memsz);\r
                        free( phtab );\r
                        return NULL;\r
                }\r
                \r
-               acess_seek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
-               acess_read(FD, PTRMK(void, addr), phtab[i].p_filesz);\r
+               acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
+               acess__SysRead(FD, PTRMK(void, addr), phtab[i].p_filesz);\r
                memset( PTRMK(char, addr) + phtab[i].p_filesz, 0, phtab[i].p_memsz - phtab[i].p_filesz );\r
        }\r
        \r

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