From c01cd6b0f42fa4cd400c5d9493c8b7ec92e72c5b Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Wed, 5 Nov 2014 10:14:08 +0800 Subject: [PATCH] AcessNative - Fix compile errors from API changes (and from compiler upgrade) --- AcessNative/acesskernel_src/Makefile | 2 +- AcessNative/acesskernel_src/main.c | 1 + AcessNative/acesskernel_src/net_wrap.c | 1 + AcessNative/acesskernel_src/server.c | 1 + AcessNative/acesskernel_src/threads.c | 7 ++- AcessNative/acesskernel_src/threads_glue.c | 1 + AcessNative/acesskernel_src/vfs_handle.c | 12 ++-- AcessNative/ld-acess_src/binary.c | 4 +- AcessNative/ld-acess_src/common.h | 6 +- AcessNative/ld-acess_src/elf_load.c | 68 +++++++++++----------- AcessNative/ld-acess_src/memory.c | 1 + AcessNative/ld-acess_src/request.c | 1 + 12 files changed, 57 insertions(+), 48 deletions(-) diff --git a/AcessNative/acesskernel_src/Makefile b/AcessNative/acesskernel_src/Makefile index 9e8ce35f..d2a22c69 100644 --- a/AcessNative/acesskernel_src/Makefile +++ b/AcessNative/acesskernel_src/Makefile @@ -15,7 +15,7 @@ KERNEL_SRC = ../../KernelLand/Kernel/ LDACESS_SRC = ../../Usermode/Libraries/ld-acess.so_src/ # - Kernel objects (from KernelLand/Kernel) -KERNEL_OBJ := logging.o adt.o lib.o debug.o messages.o drvutil_disk.o drvutil_video.o +KERNEL_OBJ := logging.o adt.o lib.o debug.o messages.o drvutil_disk.o drvutil_video.o memfs_helpers.o KERNEL_OBJ += mutex.o semaphore.o rwlock.o workqueue.o events.o #KERNEL_OBJ += libc.o KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o diff --git a/AcessNative/acesskernel_src/main.c b/AcessNative/acesskernel_src/main.c index ead4f33d..9ef49c9b 100644 --- a/AcessNative/acesskernel_src/main.c +++ b/AcessNative/acesskernel_src/main.c @@ -13,6 +13,7 @@ #endif #include #include +#include #include "../../KernelLand/Kernel/include/logdebug.h" #define VALGRIND_CLIENT 0 diff --git a/AcessNative/acesskernel_src/net_wrap.c b/AcessNative/acesskernel_src/net_wrap.c index 730eda02..33a5cf91 100644 --- a/AcessNative/acesskernel_src/net_wrap.c +++ b/AcessNative/acesskernel_src/net_wrap.c @@ -8,6 +8,7 @@ #define DEBUG 1 #include #include +#include #include "../../KernelLand/Kernel/include/logdebug.h" #include "net_wrap.h" #include diff --git a/AcessNative/acesskernel_src/server.c b/AcessNative/acesskernel_src/server.c index f3826db7..8de8ad3a 100644 --- a/AcessNative/acesskernel_src/server.c +++ b/AcessNative/acesskernel_src/server.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #ifdef __WIN32__ diff --git a/AcessNative/acesskernel_src/threads.c b/AcessNative/acesskernel_src/threads.c index 86b8a892..74d85fc6 100644 --- a/AcessNative/acesskernel_src/threads.c +++ b/AcessNative/acesskernel_src/threads.c @@ -199,9 +199,10 @@ int Threads_SetGID(tGID NewGID) } int *Threads_GetErrno(void) { return &gpCurrentThread->_errno; } -char **Threads_GetCWD(void) { return &gpCurrentThread->Process->CWD; } -char **Threads_GetChroot(void) { return &gpCurrentThread->Process->Chroot; } -int *Threads_GetMaxFD(void) { return &gpCurrentThread->Process->MaxFD; }; +static tProcess *proc(tProcess *Proc) { return Proc ? Proc : gpCurrentThread->Process; } +char **Threads_GetCWD (tProcess *Proc) { return &proc(Proc)->CWD; } +char **Threads_GetChroot(tProcess *Proc) { return &proc(Proc)->Chroot; } +int *Threads_GetMaxFD (tProcess *Proc) { return &proc(Proc)->MaxFD; }; tTID Threads_WaitTID(int TID, int *Status) { diff --git a/AcessNative/acesskernel_src/threads_glue.c b/AcessNative/acesskernel_src/threads_glue.c index fa83980e..7c137804 100644 --- a/AcessNative/acesskernel_src/threads_glue.c +++ b/AcessNative/acesskernel_src/threads_glue.c @@ -20,6 +20,7 @@ typedef void **tShortSpinlock; #include #define NORETURN __attribute__((noreturn)) +#include #include // Kernel land, but uses standards #include diff --git a/AcessNative/acesskernel_src/vfs_handle.c b/AcessNative/acesskernel_src/vfs_handle.c index 6c3992f8..93b6a9d6 100644 --- a/AcessNative/acesskernel_src/vfs_handle.c +++ b/AcessNative/acesskernel_src/vfs_handle.c @@ -79,7 +79,7 @@ void VFS_CloneHandleList(int PID) ent = VFS_int_GetUserHandles(PID, 1); - maxhandles = *Threads_GetMaxFD(); + maxhandles = *Threads_GetMaxFD(NULL); memcpy(ent->Handles, cur->Handles, maxhandles*sizeof(tVFS_Handle)); // Reference all @@ -105,7 +105,7 @@ void VFS_CloneHandlesFromList(int PID, int nFD, int FDs[]) LOG("Copying %i FDs from %i", nFD, PID); - maxhandles = *Threads_GetMaxFD(); + maxhandles = *Threads_GetMaxFD(NULL); if( nFD > maxhandles ) nFD = maxhandles; for( int i = 0; i < nFD; i ++ ) @@ -156,7 +156,7 @@ tVFS_Handle *VFS_GetHandle(int FD) else { int pid = Threads_GetPID(); - int maxhandles = *Threads_GetMaxFD(); + int maxhandles = *Threads_GetMaxFD(NULL); tUserHandles *ent = VFS_int_GetUserHandles(pid, 0); if(!ent) { @@ -193,7 +193,7 @@ int VFS_SetHandle(int FD, tVFS_Node *Node, int Mode) else { tUserHandles *ent; int pid = Threads_GetPID(); - int maxhandles = *Threads_GetMaxFD(); + int maxhandles = *Threads_GetMaxFD(NULL); ent = VFS_int_GetUserHandles(pid, 0); if(!ent) { @@ -219,7 +219,7 @@ int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) if(bIsUser) { tUserHandles *ent; - int maxhandles = *Threads_GetMaxFD(); + int maxhandles = *Threads_GetMaxFD(NULL); // Find the PID's handle list ent = VFS_int_GetUserHandles(Threads_GetPID(), 1); // Get a handle @@ -254,7 +254,7 @@ void VFS_ClearHandles(int PID) tUserHandles *ent = VFS_int_GetUserHandles(PID, 0); if( !ent ) return; // Get a handle - int maxhandles = *Threads_GetMaxFD(); + int maxhandles = *Threads_GetMaxFD(NULL); for( int i = 0; i < maxhandles; i ++ ) { if(ent->Handles[i].Node) continue; diff --git a/AcessNative/ld-acess_src/binary.c b/AcessNative/ld-acess_src/binary.c index 59be8295..738c6e81 100644 --- a/AcessNative/ld-acess_src/binary.c +++ b/AcessNative/ld-acess_src/binary.c @@ -6,6 +6,7 @@ * - Provides binary loading and type abstraction */ #define DEBUG 0 +#define _POSIX_C_SOURCE 200809L // needed for strdup #include "common.h" #include #include @@ -228,7 +229,7 @@ void Binary_SetReadyToUse(void *Base) } } -int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size) +int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size, void *IgnoreBase) { int i; tBinary *bin; @@ -251,6 +252,7 @@ int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size) // Search list of loaded binaries for(bin = gLoadedBinaries; bin; bin = bin->Next) { + if( bin->Base == IgnoreBase ) continue ; 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, Size) ) diff --git a/AcessNative/ld-acess_src/common.h b/AcessNative/ld-acess_src/common.h index 9f67e9c6..0bdc40f2 100644 --- a/AcessNative/ld-acess_src/common.h +++ b/AcessNative/ld-acess_src/common.h @@ -8,16 +8,16 @@ #include #include -extern int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size); +extern int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size, void *IgnoreBase); extern void *Binary_LoadLibrary(const char *Path); extern void *Binary_Load(const char *Path, uintptr_t *EntryPoint); extern void Binary_SetReadyToUse(void *Base); // HACKS - So this can share the usermode elf.c -static inline int GetSymbol(const char *sym, void **val, size_t *sz) +static inline int GetSymbol(const char *sym, void **val, size_t *sz, void *IgnoreBase) { uintptr_t rv; - if( !Binary_GetSymbol(sym, &rv, sz) ) + if( !Binary_GetSymbol(sym, &rv, sz, IgnoreBase) ) return 0; *val = (void*)rv; return 1; diff --git a/AcessNative/ld-acess_src/elf_load.c b/AcessNative/ld-acess_src/elf_load.c index 19a8c13f..c5edc4a5 100644 --- a/AcessNative/ld-acess_src/elf_load.c +++ b/AcessNative/ld-acess_src/elf_load.c @@ -74,7 +74,7 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) ENTER("iFD", FD); // Check for a program header - if(hdr->phoff == 0) { + if(hdr->e_phoff == 0) { #if DEBUG_WARN Warning("ELF File does not contain a program header\n"); #endif @@ -83,25 +83,25 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) } // Read Program Header Table - phtab = malloc( sizeof(Elf32_Phdr) * hdr->phentcount ); + phtab = malloc( sizeof(Elf32_Phdr) * hdr->e_phnum ); if( !phtab ) { LEAVE('n'); return NULL; } - LOG("hdr.phoff = 0x%08x\n", hdr->phoff); - acess__SysSeek(FD, hdr->phoff, ACESS_SEEK_SET); - acess__SysRead(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount); + LOG("hdr.e_phoff = 0x%08x\n", hdr->e_phoff); + acess__SysSeek(FD, hdr->e_phoff, ACESS_SEEK_SET); + acess__SysRead(FD, phtab, sizeof(Elf32_Phdr) * hdr->e_phnum); // Count Pages iPageCount = 0; - LOG("hdr.phentcount = %i\n", hdr->phentcount); - for( i = 0; i < hdr->phentcount; i++ ) + LOG("hdr.e_phnum = %i\n", hdr->e_phnum); + for( i = 0; i < hdr->e_phnum; i++ ) { // Ignore Non-LOAD types - if(phtab[i].Type != PT_LOAD) + if(phtab[i].p_type != PT_LOAD) continue; - iPageCount += ((phtab[i].VAddr&0xFFF) + phtab[i].MemSize + 0xFFF) >> 12; - LOG("phtab[%i] = {VAddr:0x%x, MemSize:0x%x}\n", i, phtab[i].VAddr, phtab[i].MemSize); + iPageCount += ((phtab[i].p_vaddr&0xFFF) + phtab[i].p_memsz + 0xFFF) >> 12; + LOG("phtab[%i] = {p_vaddr:0x%x, p_memsz:0x%x}\n", i, phtab[i].p_vaddr, phtab[i].MemSize); } LOG("iPageCount = %i\n", iPageCount); @@ -117,14 +117,14 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) // Prescan for base and size max = 0; base = 0xFFFFFFFF; - for( i = 0; i < hdr->phentcount; i ++) + for( i = 0; i < hdr->e_phnum; i ++) { - if( phtab[i].Type != PT_LOAD ) + if( phtab[i].p_type != PT_LOAD ) continue; - if( phtab[i].VAddr < base ) - base = phtab[i].VAddr; - if( phtab[i].VAddr + phtab[i].MemSize > max ) - max = phtab[i].VAddr + phtab[i].MemSize; + if( phtab[i].p_vaddr < base ) + base = phtab[i].p_vaddr; + if( phtab[i].p_vaddr + phtab[i].p_memsz > max ) + max = phtab[i].p_vaddr + phtab[i].p_memsz; } LOG("base = %08x, max = %08x\n", base, max); @@ -138,39 +138,39 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) } // Load Pages - for( i = 0; i < hdr->phentcount; i++ ) + for( i = 0; i < hdr->e_phnum; i++ ) { // Get Interpreter Name - if( phtab[i].Type == PT_INTERP ) + if( phtab[i].p_type == PT_INTERP ) { char *tmp; //if(ret->Interpreter) continue; - tmp = malloc(phtab[i].FileSize); - acess__SysSeek(FD, phtab[i].Offset, ACESS_SEEK_SET); - acess__SysRead(FD, tmp, phtab[i].FileSize); + tmp = malloc(phtab[i].p_filesz); + acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET); + acess__SysRead(FD, tmp, phtab[i].p_filesz); //ret->Interpreter = Binary_RegInterp(tmp); LOG("Interpreter '%s'\n", tmp); free(tmp); continue; } // Ignore non-LOAD types - if(phtab[i].Type != PT_LOAD) continue; + if(phtab[i].p_type != PT_LOAD) continue; - LOG("phtab[%i] = PT_LOAD {Adj VAddr:0x%x, Offset:0x%x, FileSize:0x%x, MemSize:0x%x}\n", - i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize, phtab[i].MemSize); + LOG("phtab[%i] = PT_LOAD {Adj p_vaddr:0x%x, p_offset:0x%x, p_filesz:0x%x, p_memsz:0x%x}\n", + i, phtab[i].p_vaddr+baseDiff, phtab[i].p_offset, phtab[i].p_filesz, phtab[i].p_memsz); - addr = phtab[i].VAddr + baseDiff; + addr = phtab[i].p_vaddr + baseDiff; - if( AllocateMemory( addr, phtab[i].MemSize ) ) { + if( AllocateMemory( addr, phtab[i].p_memsz ) ) { fprintf(stderr, "Elf_Load: Unable to map memory at %x (0x%x bytes)\n", - addr, phtab[i].MemSize); + addr, phtab[i].p_memsz); free( phtab ); return NULL; } - acess__SysSeek(FD, phtab[i].Offset, ACESS_SEEK_SET); - acess__SysRead(FD, PTRMK(void, addr), phtab[i].FileSize); - memset( PTRMK(char, addr) + phtab[i].FileSize, 0, phtab[i].MemSize - phtab[i].FileSize ); + acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET); + acess__SysRead(FD, PTRMK(void, addr), phtab[i].p_filesz); + memset( PTRMK(char, addr) + phtab[i].p_filesz, 0, phtab[i].p_memsz - phtab[i].p_filesz ); } // Clean Up @@ -210,20 +210,20 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr) LEAVE('n'); return NULL; } - LOG("hdr.phoff = 0x%08llx\n", (long long)hdr->e_phoff); + LOG("hdr.e_phoff = 0x%08llx\n", (long long)hdr->e_phoff); acess__SysSeek(FD, hdr->e_phoff, ACESS_SEEK_SET); acess__SysRead(FD, phtab, sizeof(Elf64_Phdr) * hdr->e_phnum); // Count Pages iPageCount = 0; - LOG("hdr.phentcount = %i\n", hdr->e_phnum); + LOG("hdr.e_phnum = %i\n", hdr->e_phnum); for( i = 0; i < hdr->e_phnum; i++ ) { // Ignore Non-LOAD types if(phtab[i].p_type != PT_LOAD) continue; iPageCount += ((phtab[i].p_vaddr&0xFFF) + phtab[i].p_memsz + 0xFFF) >> 12; - LOG("phtab[%i] = {VAddr:0x%llx, MemSize:0x%llx}\n", + LOG("phtab[%i] = {p_vaddr:0x%llx, p_memsz:0x%llx}\n", i, (long long)phtab[i].p_vaddr, (long long)phtab[i].p_memsz); } @@ -280,7 +280,7 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr) // Ignore non-LOAD types if(phtab[i].p_type != PT_LOAD) continue; - LOG("phtab[%i] = PT_LOAD {Adj VAddr:0x%llx, Offset:0x%llx, FileSize:0x%llx, MemSize:0x%llx}\n", + LOG("phtab[%i] = PT_LOAD {Adj p_vaddr:0x%llx, p_offset:0x%llx, p_filesz:0x%llx, p_memsz:0x%llx}\n", i, (long long)phtab[i].p_vaddr+baseDiff, (long long)phtab[i].p_offset, (long long)phtab[i].p_filesz, (long long)phtab[i].p_memsz diff --git a/AcessNative/ld-acess_src/memory.c b/AcessNative/ld-acess_src/memory.c index c8166af4..99238a52 100644 --- a/AcessNative/ld-acess_src/memory.c +++ b/AcessNative/ld-acess_src/memory.c @@ -1,5 +1,6 @@ /* */ +#define _GNU_SOURCE // needed for MAP_ANONYMOUS to be avaliable #include "common.h" #include #include diff --git a/AcessNative/ld-acess_src/request.c b/AcessNative/ld-acess_src/request.c index fdf57485..c516a225 100644 --- a/AcessNative/ld-acess_src/request.c +++ b/AcessNative/ld-acess_src/request.c @@ -25,6 +25,7 @@ # include # include # include +# include #endif #include "request.h" #include "../syscalls.h" -- 2.20.1