From: John Hodge Date: Fri, 16 Mar 2012 08:02:27 +0000 (+0800) Subject: Fixing KMod support X-Git-Tag: rel0.15~726 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2fcb3775f3afee7bfa9aa3cbb6aea3c6c3426e64;p=tpg%2Facess2.git Fixing KMod support - Combined user and kernel ELF relocation code - Enabled -ffreestanding for Kernel - NOTE: Possible race condition in kernel relocation --- diff --git a/KernelLand/Kernel/Makefile b/KernelLand/Kernel/Makefile index da0ecb72..81a29285 100644 --- a/KernelLand/Kernel/Makefile +++ b/KernelLand/Kernel/Makefile @@ -24,7 +24,7 @@ endif ASFLAGS += -D ARCHDIR_IS_$(ARCHDIR)=1 -D PLATFORM_is_$(PLATFORM)=1 CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\" CPPFLAGS += -D ARCH=$(ARCH) -D ARCHDIR=$(ARCHDIR) -D PLATFORM=\"$(PLATFORM)\" -D ARCHDIR_IS_$(ARCHDIR)=1 -D PLATFORM_is_$(PLATFORM)=1 -CPPFLAGS += -D KERNEL_VERSION=$(KERNEL_VERSION) +CPPFLAGS += -D KERNEL_VERSION=$(KERNEL_VERSION) -ffreestanding CFLAGS += -Wall -fno-stack-protector -Wstrict-prototypes -g CFLAGS += -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wuninitialized CFLAGS += -O3 diff --git a/KernelLand/Kernel/arch/x86/kpanic.c b/KernelLand/Kernel/arch/x86/kpanic.c index 3e2ccacc..bf18aa87 100644 --- a/KernelLand/Kernel/arch/x86/kpanic.c +++ b/KernelLand/Kernel/arch/x86/kpanic.c @@ -87,7 +87,7 @@ void KernelPanic_SetMode(void) if( giKP_Pos ) return ; // Restore VGA 0xB8000 text mode - #if 1 + #if 0 for( i = 0; i < NUM_REGVALUES; i++ ) { // Reset Flip-Flop @@ -153,4 +153,10 @@ void KernelPanic_PutChar(char Ch) giKP_Pos ++; break; } + #if 0 + { + char s[2] = {Ch,0}; + VT_int_PutString(gpVT_CurTerm, s); + } + #endif } diff --git a/KernelLand/Kernel/arch/x86/mm_virt.c b/KernelLand/Kernel/arch/x86/mm_virt.c index c17b57bd..e96b627d 100644 --- a/KernelLand/Kernel/arch/x86/mm_virt.c +++ b/KernelLand/Kernel/arch/x86/mm_virt.c @@ -441,7 +441,8 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr) //ENTER("xVAddr xPAddr", VAddr, PAddr); // Sanity check if( PAddr & 0xFFF || VAddr & 0xFFF ) { - Log_Warning("MM_Virt", "MM_Map - Physical or Virtual Addresses are not aligned"); + Log_Warning("MM_Virt", "MM_Map - Physical or Virtual Addresses are not aligned (0x%P and %p)", + PAddr, VAddr); //LEAVE('i', 0); return 0; } diff --git a/KernelLand/Kernel/bin/elf.c b/KernelLand/Kernel/bin/elf.c index 8f51290a..31178e34 100644 --- a/KernelLand/Kernel/bin/elf.c +++ b/KernelLand/Kernel/bin/elf.c @@ -5,7 +5,21 @@ #define DEBUG 0 #include #include -#include "elf.h" + +#define _COMMON_H +#define SysDebug(...) LOG(v) +#define DISABLE_ELF64 +void *GetSymbol(const char *Name, size_t *Size); +void *GetSymbol(const char *Name, size_t *Size) { Uint val; Binary_GetSymbol(Name, &val); if(Size)*Size=0; return (void*)val; }; +#define AddLoaded(a,b) do{}while(0) +#define LoadLibrary(a,b,c) 0 +#if __STDC_HOSTED__ +#warning "Hosted? why!" +#else +#warning "freestanding - outstanding!" +#endif + +#include "../../../Usermode/Libraries/ld-acess.so_src/elf.c" #define DEBUG_WARN 1 @@ -14,9 +28,7 @@ tBinary *Elf_Load(int fp); tBinary *Elf_Load64(int fp, Elf64_Ehdr *hdr); tBinary *Elf_Load32(int fp, Elf32_Ehdr *hdr); int Elf_Relocate(void *Base); - int Elf_Relocate32(void *Base); - int Elf_GetSymbol(void *Base, const char *Name, Uint *ret); - int Elf_Int_DoRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab, Uint base); + int Elf_GetSymbol(void *Base, const char *Name, Uint *Ret); Uint Elf_Int_HashString(const char *str); // === GLOBALS === @@ -283,361 +295,12 @@ tBinary *Elf_Load32(int FD, Elf32_Ehdr *Header) return ret; } -// --- ELF RELOCATION --- int Elf_Relocate(void *Base) { - Elf64_Ehdr *hdr = Base; - - switch( hdr->e_ident[EI_CLASS] ) - { - case ELFCLASS32: - return Elf_Relocate32(Base); - case ELFCLASS64: - return 0; - default: - return 1; - } -} - - -/** - * \brief Relocates a loaded ELF Executable - */ -int Elf_Relocate32(void *Base) -{ - Elf32_Ehdr *hdr = Base; - Elf32_Phdr *phtab; - int i, j; // Counters - char *libPath; - Uint iRealBase = -1; - Uint iBaseDiff; - int iSegmentCount; - int iSymCount = 0; - Elf32_Rel *rel = NULL; - Elf32_Rela *rela = NULL; - Uint32 *pltgot = NULL; - void *plt = NULL; - Uint32 *ptr; - int relSz=0, relEntSz=8; - int relaSz=0, relaEntSz=8; - int pltSz=0, pltType=0; - Elf32_Dyn *dynamicTab = NULL; // Dynamic Table Pointer - char *dynstrtab = NULL; // .dynamic String Table - Elf32_Sym *dynsymtab = NULL; - int bFailed = 0; - - ENTER("pBase", Base); - - // Parse Program Header to get Dynamic Table - phtab = (void *)( (tVAddr)Base + hdr->phoff ); - iSegmentCount = hdr->phentcount; - for(i = 0; i < iSegmentCount; i ++ ) - { - // Determine linked base address - if(phtab[i].Type == PT_LOAD && iRealBase > phtab[i].VAddr) - iRealBase = phtab[i].VAddr; - - // Find Dynamic Section - if(phtab[i].Type == PT_DYNAMIC) { - if(dynamicTab) { - Log_Warning("ELF", "Elf_Relocate - Multiple PT_DYNAMIC segments\n"); - continue; - } - dynamicTab = (void *) (tVAddr) phtab[i].VAddr; - j = i; // Save Dynamic Table ID - break; - } - } - - // Check if a PT_DYNAMIC segement was found - if(!dynamicTab) { - Log_Warning("ELF", "Elf_Relocate: No PT_DYNAMIC segment in image, returning\n"); - LEAVE('x', 0); - return 0; - } - - // Page Align real base - iRealBase &= ~0xFFF; - - // Adjust "Real" Base - iBaseDiff = (Uint)Base - iRealBase; - // Adjust Dynamic Table - dynamicTab = (void *) ((Uint)dynamicTab + iBaseDiff); - - // === Get Symbol table and String Table === - for( j = 0; dynamicTab[j].d_tag != DT_NULL; j++) - { - switch(dynamicTab[j].d_tag) - { - // --- Symbol Table --- - case DT_SYMTAB: - dynamicTab[j].d_val += iBaseDiff; - dynsymtab = (void*) (tVAddr) dynamicTab[j].d_val; - hdr->misc.SymTable = dynamicTab[j].d_val; // Saved in unused bytes of ident - break; - - // --- String Table --- - case DT_STRTAB: - dynamicTab[j].d_val += iBaseDiff; - dynstrtab = (void*) (tVAddr) dynamicTab[j].d_val; - break; - - // --- Hash Table -- - case DT_HASH: - dynamicTab[j].d_val += iBaseDiff; - iSymCount = ((Uint*)((tVAddr)dynamicTab[j].d_val))[1]; - hdr->misc.HashTable = dynamicTab[j].d_val; // Saved in unused bytes of ident - break; - } - } - - if( !dynsymtab && iSymCount > 0 ) { - Log_Warning("ELF", "Elf_Relocate: No Dynamic symbol table, but count >0"); - return 0; - } - - // Alter Symbols to true base - for(i = 0; i < iSymCount; i ++) - { - dynsymtab[i].value += iBaseDiff; - dynsymtab[i].nameOfs += (Uint)dynstrtab; - //LOG("Sym '%s' = 0x%x (relocated)\n", dynsymtab[i].name, dynsymtab[i].value); - } - - // === Add to loaded list (can be imported now) === - //Binary_AddLoaded( (Uint)Base ); - - // === Parse Relocation Data === - for( j = 0; dynamicTab[j].d_tag != DT_NULL; j++) - { - switch(dynamicTab[j].d_tag) - { - // --- Shared Library Name --- - case DT_SONAME: - LOG(".so Name '%s'\n", dynstrtab+dynamicTab[j].d_val); - break; - // --- Needed Library --- - case DT_NEEDED: - libPath = dynstrtab + dynamicTab[j].d_val; - Log_Notice("ELF", "%p - Required Library '%s' (Ignored in kernel mode)\n", Base, libPath); - break; - // --- PLT/GOT --- - case DT_PLTGOT: pltgot = (void*)(iBaseDiff+dynamicTab[j].d_val); break; - case DT_JMPREL: plt = (void*)(iBaseDiff+dynamicTab[j].d_val); break; - case DT_PLTREL: pltType = dynamicTab[j].d_val; break; - case DT_PLTRELSZ: pltSz = dynamicTab[j].d_val; break; - - // --- Relocation --- - case DT_REL: rel = (void*)(iBaseDiff + dynamicTab[j].d_val); break; - case DT_RELSZ: relSz = dynamicTab[j].d_val; break; - case DT_RELENT: relEntSz = dynamicTab[j].d_val; break; - - case DT_RELA: rela = (void*)(iBaseDiff + dynamicTab[j].d_val); break; - case DT_RELASZ: relaSz = dynamicTab[j].d_val; break; - case DT_RELAENT: relaEntSz = dynamicTab[j].d_val; break; - } - } - - // Parse Relocation Entries - if(rel && relSz) - { - j = relSz / relEntSz; - for( i = 0; i < j; i++ ) - { - ptr = (void*)(iBaseDiff + rel[i].r_offset); - if( !Elf_Int_DoRelocate(rel[i].r_info, ptr, *ptr, dynsymtab, (Uint)Base) ) { - bFailed = 1; - } - } - } - // Parse Relocation Entries - if(rela && relaSz) - { - j = relaSz / relaEntSz; - for( i = 0; i < j; i++ ) - { - ptr = (void*)(iBaseDiff + rela[i].r_offset); - if( !Elf_Int_DoRelocate(rela[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) { - bFailed = 1; - } - } - } - - // === Process PLT (Procedure Linkage Table) === - if(plt && pltSz) - { - if(pltType == DT_REL) - { - Elf32_Rel *pltRel = plt; - j = pltSz / sizeof(Elf32_Rel); - LOG("PLT Rel - plt = %p, pltSz = %i (%i ents)", plt, pltSz, j); - for(i = 0; i < j; i++) - { - ptr = (void*)(iBaseDiff + pltRel[i].r_offset); - if( !Elf_Int_DoRelocate(pltRel[i].r_info, ptr, *ptr, dynsymtab, (Uint)Base) ) { - bFailed = 1; - } - } - } - else - { - Elf32_Rela *pltRela = plt; - j = pltSz / sizeof(Elf32_Rela); - LOG("PLT RelA - plt = %p, pltSz = %i (%i ents)", plt, pltSz, j); - for(i=0;imisc.HashTable; - symtab = (void *) hdr->misc.SymTable; - - nbuckets = pBuckets[0]; - iSymCount = pBuckets[1]; - pBuckets = &pBuckets[2]; - pChains = &pBuckets[ nbuckets ]; - - // Get hash - iNameHash = Elf_Int_HashString(Name); - iNameHash %= nbuckets; - - // Check Bucket - i = pBuckets[ iNameHash ]; - if(symtab[i].shndx != SHN_UNDEF && strcmp(symtab[i].name, Name) == 0) { - if(ret) *ret = symtab[ i ].value; - return 1; - } - - // Walk Chain - while(pChains[i] != STN_UNDEF) - { - i = pChains[i]; - if(symtab[i].shndx != SHN_UNDEF && strcmp(symtab[ i ].name, Name) == 0) { - if(ret) *ret = symtab[ i ].value; - return 1; - } - } - return 0; + return ElfGetSymbol(Base, Name, (void**)ret, NULL); } -/** - * \fn Uint Elf_Int_HashString(char *str) - * \brief Hash a string in the ELF format - * \param str String to hash - * \return Hash value - */ -Uint Elf_Int_HashString(const char *str) -{ - Uint h = 0, g; - while(*str) - { - h = (h << 4) + *str++; - if( (g = h & 0xf0000000) ) - h ^= g >> 24; - h &= ~g; - } - return h; -} diff --git a/KernelLand/Kernel/binary.c b/KernelLand/Kernel/binary.c index 5213bf2d..e72de28b 100644 --- a/KernelLand/Kernel/binary.c +++ b/KernelLand/Kernel/binary.c @@ -406,7 +406,10 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo for( i = 0; i < Binary->NumSections; i ++ ) { tVAddr addr = Binary->LoadSections[i].Virtual - Binary->Base + base; - if( Binary_int_CheckMemFree( addr, Binary->LoadSections[i].MemSize ) ) + size_t size = Binary->LoadSections[i].MemSize; + if( addr + size > LoadMax ) + break; + if( Binary_int_CheckMemFree( addr, size ) ) break; } // If space was found, break @@ -425,13 +428,16 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo } // Map Executable In - fd = VFS_OpenInode(Binary->MountID, Binary->Inode, VFS_OPENFLAG_READ); + if( Binary->MountID ) + fd = VFS_OpenInode(Binary->MountID, Binary->Inode, VFS_OPENFLAG_READ); + else + fd = VFS_Open(Path, VFS_OPENFLAG_READ); for( i = 0; i < Binary->NumSections; i ++ ) { tBinarySection *sect = &Binary->LoadSections[i]; Uint protflags, mapflags; tVAddr addr = sect->Virtual - Binary->Base + base; - LOG("%i - %p to offset 0x%llx (%x)", i, addr, sect->Offset, sect->Flags); + LOG("%i - %p, 0x%x bytes from offset 0x%llx (%x)", i, addr, sect->FileSize, sect->Offset, sect->Flags); protflags = MMAP_PROT_READ; mapflags = MMAP_MAP_FIXED; @@ -508,7 +514,14 @@ tBinary *Binary_DoLoad(tMount MountID, tInode Inode, const char *Path) ENTER("iMountID XInode sPath", MountID, Inode, Path); // Open File - fp = VFS_OpenInode(MountID, Inode, VFS_OPENFLAG_READ); + if( MountID ) + { + fp = VFS_OpenInode(MountID, Inode, VFS_OPENFLAG_READ); + } + else + { + fp = VFS_Open(Path, VFS_OPENFLAG_READ); + } if(fp == -1) { LOG("Unable to load file, access denied"); LEAVE('n'); @@ -697,6 +710,7 @@ void *Binary_LoadKernel(const char *File) int fd = VFS_Open(File, VFS_OPENFLAG_READ); tFInfo info; if(fd == -1) { + LOG("Opening failed"); LEAVE('n'); return NULL; } @@ -704,6 +718,7 @@ void *Binary_LoadKernel(const char *File) mount_id = info.mount; inode = info.inode; VFS_Close(fd); + LOG("Mount %i, Inode %lli", mount_id, inode); } // Check if the binary has already been loaded @@ -714,6 +729,7 @@ void *Binary_LoadKernel(const char *File) pKBinary = pKBinary->Next ) { if(pKBinary->Info == pBinary) { + LOG("Already loaded"); LEAVE('p', pKBinary->Base); return pKBinary->Base; } @@ -728,6 +744,7 @@ void *Binary_LoadKernel(const char *File) return NULL; } + LOG("Loaded as %p", pBinary); // -------------- // Now pBinary is valid (either freshly loaded or only user mapped) // So, map it into kernel space @@ -736,19 +753,14 @@ void *Binary_LoadKernel(const char *File) // Reference Executable (Makes sure that it isn't unloaded) pBinary->ReferenceCount ++; - Binary_MapIn(pBinary, File, KLIB_LOWEST, KLIB_HIGHEST); - - // Relocate Library - if( !Binary_Relocate( (void*)base ) ) - { - Log_Warning("Binary", "Relocation of '%s' failed, unloading", File); - Binary_Unload( (void*)base ); - Binary_Dereference( pBinary ); + base = Binary_MapIn(pBinary, File, KLIB_LOWEST, KLIB_HIGHEST); + if( base == 0 ) { LEAVE('n'); return 0; } - - // Add to list (relocator must look at itself manually, not via Binary_GetSymbol) + + // Add to list + // TODO: Could this cause race conditions if a binary isn't fully loaded when used pKBinary = malloc(sizeof(*pKBinary)); pKBinary->Base = (void*)base; pKBinary->Info = pBinary; @@ -757,6 +769,16 @@ void *Binary_LoadKernel(const char *File) glLoadedKernelLibs = pKBinary; SHORTREL( &glKBinListLock ); + // Relocate Library + if( !Binary_Relocate( (void*)base ) ) + { + Log_Warning("Binary", "Relocation of '%s' failed, unloading", File); + Binary_Unload( (void*)base ); + Binary_Dereference( pBinary ); + LEAVE('n'); + return 0; + } + LEAVE('p', base); return (void*)base; } @@ -772,7 +794,7 @@ Uint Binary_Relocate(void *Base) Uint32 ident = *(Uint32*) Base; tBinaryType *bt = gRegBinTypes; - for(; bt; bt = bt->Next) + for( ; bt; bt = bt->Next) { if( (ident & bt->Mask) == (Uint)bt->Ident ) return bt->Relocate( (void*)Base); @@ -862,15 +884,23 @@ Uint Binary_FindSymbol(void *Base, const char *Name, Uint *Val) */ int Binary_int_CheckMemFree( tVAddr _start, size_t _len ) { + ENTER("p_start x_len", _start, _len); + _len += _start & (PAGE_SIZE-1); _len = (_len + PAGE_SIZE - 1) & ~(PAGE_SIZE-1); _start &= ~(PAGE_SIZE-1); + LOG("_start = %p, _len = 0x%x", _start, _len); for( ; _len > PAGE_SIZE; _len -= PAGE_SIZE, _start += PAGE_SIZE ) { - if( MM_GetPhysAddr(_start) != 0 ) + if( MM_GetPhysAddr(_start) != 0 ) { + LEAVE('i', 1); return 1; + } } - if( _len == PAGE_SIZE && MM_GetPhysAddr(_start) != 0 ) + if( _len == PAGE_SIZE && MM_GetPhysAddr(_start) != 0 ) { + LEAVE('i', 1); return 1; + } + LEAVE('i', 0); return 0; } diff --git a/KernelLand/Kernel/vfs/mmap.c b/KernelLand/Kernel/vfs/mmap.c index 9fe9282c..61288695 100644 --- a/KernelLand/Kernel/vfs/mmap.c +++ b/KernelLand/Kernel/vfs/mmap.c @@ -93,14 +93,13 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, if( !pb || pb->BaseOffset > pagenum ) { void *old_pb = pb; - pb = malloc( sizeof(tVFS_MMapPageBlock) ); + pb = calloc( 1, sizeof(tVFS_MMapPageBlock) ); if(!pb) { Mutex_Release( &h->Node->Lock ); LEAVE_RET('n', NULL); } pb->Next = old_pb; pb->BaseOffset = pagenum - pagenum % MMAP_PAGES_PER_BLOCK; - memset(pb->PhysAddrs, 0, sizeof(pb->PhysAddrs)); if(prev) prev->Next = pb; else @@ -194,7 +193,6 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, memset(pb->PhysAddrs, 0, sizeof(pb->PhysAddrs)); oldpb->Next = pb; } - pagenum = 0; } } diff --git a/Usermode/Libraries/ld-acess.so_src/elf.c b/Usermode/Libraries/ld-acess.so_src/elf.c index 995d5ea7..bbe45d62 100644 --- a/Usermode/Libraries/ld-acess.so_src/elf.c +++ b/Usermode/Libraries/ld-acess.so_src/elf.c @@ -18,9 +18,9 @@ # define DEBUGS(...) #endif -//#if BITS > 32 +#ifndef DISABLE_ELF64 # define SUPPORT_ELF64 -//#endif +#endif // === CONSTANTS === #if DEBUG @@ -33,6 +33,8 @@ void *ElfRelocate(void *Base, char **envp, const char *Filename); int ElfGetSymbol(void *Base, const char *Name, void **Ret, size_t *Size); void *Elf32Relocate(void *Base, char **envp, const char *Filename); int Elf32GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size); +void elf_doRelocate_386(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int type, int bRela, const char *Sym, intptr_t iBaseDiff); +void elf_doRelocate_arm(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int type, int bRela, const char *Sym, intptr_t iBaseDiff); #ifdef SUPPORT_ELF64 void *Elf64Relocate(void *Base, char **envp, const char *Filename); int Elf64GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size); @@ -199,6 +201,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) char *dynstrtab = NULL; // .dynamic String Table Elf32_Sym *dynsymtab; void (*do_relocate)(uint32_t t_info, uint32_t *ptr, Elf32_Addr addend, int Type, int bRela, const char *Sym, intptr_t iBaseDiff); + auto void _doRelocate(uint32_t r_info, uint32_t *ptr, int bRela, Elf32_Addr addend); DEBUGS("ElfRelocate: (Base=0x%x)", Base); @@ -206,7 +209,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) // Parse Program Header to get Dynamic Table - phtab = Base + hdr->phoff; + phtab = (void*)( (uintptr_t)Base + hdr->phoff ); iSegmentCount = hdr->phentcount; for(i=0;iphoff ); + phtab = (void*)( (uintptr_t)Base + hdr->phoff ); for( i = 0; i < hdr->phentcount; i ++ ) { if(phtab[i].Type == PT_LOAD && iBaseDiff > phtab[i].VAddr) @@ -466,6 +468,19 @@ int Elf32GetSymbol(void *Base, const char *Name, void **ret, size_t *Size) } } + if( !symtab ) { + SysDebug("ERRO - No DT_SYMTAB in %p", Base); + return 0; + } + if( !pBuckets ) { + SysDebug("ERRO - No DT_HASH in %p", Base); + return 0; + } + if( !dynstrtab ) { + SysDebug("ERRO - No DT_STRTAB in %p", Base); + return 0; + } + nbuckets = pBuckets[0]; // iSymCount = pBuckets[1]; pBuckets = &pBuckets[2]; @@ -478,7 +493,7 @@ int Elf32GetSymbol(void *Base, const char *Name, void **ret, size_t *Size) // Walk Chain i = pBuckets[ iNameHash ]; if(symtab[i].shndx != SHN_UNDEF && strcmp(dynstrtab + symtab[i].nameOfs, Name) == 0) { - *ret = (void*) (intptr_t) symtab[ i ].value + iBaseDiff; + *ret = (void*)( (uintptr_t) symtab[ i ].value + iBaseDiff ); if(Size) *Size = symtab[i].size; return 1; } @@ -487,7 +502,7 @@ int Elf32GetSymbol(void *Base, const char *Name, void **ret, size_t *Size) { i = pChains[i]; if(symtab[i].shndx != SHN_UNDEF && strcmp(dynstrtab + symtab[ i ].nameOfs, Name) == 0) { - *ret = (void*)(intptr_t)symtab[ i ].value + iBaseDiff; + *ret = (void*)( (uintptr_t)symtab[ i ].value + iBaseDiff ); if(Size) *Size = symtab[i].size; return 1; } @@ -745,7 +760,7 @@ int Elf64GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size) int j; // Locate the tables - phtab = (void*)( Base + hdr->e_phoff ); + phtab = (void*)( (intptr_t)Base + hdr->e_phoff ); for( i = 0; i < hdr->e_phnum; i ++ ) { if(phtab[i].p_type == PT_LOAD && iBaseDiff > phtab[i].p_vaddr) @@ -792,7 +807,7 @@ int Elf64GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size) // Walk Chain i = pBuckets[ iNameHash ]; if(symtab[i].st_shndx != SHN_UNDEF && strcmp(dynstrtab + symtab[i].st_name, Name) == 0) { - *Ret = (void*) (intptr_t) symtab[i].st_value + iBaseDiff; + *Ret = (void*)( (intptr_t)symtab[i].st_value + iBaseDiff ); if(Size) *Size = symtab[i].st_size; DEBUGS("%s = %p", Name, *Ret); return 1; @@ -802,7 +817,7 @@ int Elf64GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size) { i = pChains[i]; if(symtab[i].st_shndx != SHN_UNDEF && strcmp(dynstrtab + symtab[i].st_name, Name) == 0) { - *Ret = (void*)(intptr_t)symtab[i].st_value + iBaseDiff; + *Ret = (void*)((intptr_t)symtab[i].st_value + iBaseDiff); if(Size) *Size = symtab[i].st_size; DEBUGS("%s = %p", Name, *Ret); return 1; diff --git a/Usermode/Libraries/ld-acess.so_src/elf32.h b/Usermode/Libraries/ld-acess.so_src/elf32.h index 3018a895..2e9c1c4a 100644 --- a/Usermode/Libraries/ld-acess.so_src/elf32.h +++ b/Usermode/Libraries/ld-acess.so_src/elf32.h @@ -133,6 +133,10 @@ enum { PT_HIPROC = 0x7fffffff }; +#define PF_X 1 +#define PF_W 2 +#define PF_R 4 + struct sElf32_Phdr { Elf32_Word Type; Elf32_Off Offset;