diff --git a/src/sys/include/ubixos/ld.h b/src/sys/include/ubixos/ld.h index ef1cc04..a636d51 100644 --- a/src/sys/include/ubixos/ld.h +++ b/src/sys/include/ubixos/ld.h @@ -34,15 +34,15 @@ #define LD_START 0x500000 -void _ld(); -uInt32 ld(uInt32,uInt32); -uInt32 ldFindFunc(char *); uInt32 ldEnable(uInt32); #endif /*** $Log$ + Revision 1.7 2004/06/16 17:04:13 reddawg + ld.so: rest of the commit + Revision 1.4 2004/06/13 03:05:15 reddawg we now have a dynamic linker diff --git a/src/sys/kernel/ld.c b/src/sys/kernel/ld.c index a622a14..9e607ad 100644 --- a/src/sys/kernel/ld.c +++ b/src/sys/kernel/ld.c @@ -1,27 +1,27 @@ /***************************************************************************************** - Copyright (c) 2002 The UbixOS Project + Copyright (c) 2002-2004 The UbixOS Project All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are -permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this list of -conditions, the following disclaimer and the list of authors. Redistributions in binary -form must reproduce the above copyright notice, this list of conditions, the following -disclaimer and the list of authors in the documentation and/or other materials provided -with the distribution. Neither the name of the UbixOS Project nor the names of its -contributors may be used to endorse or promote products derived from this software -without specific prior written permission. + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Id$ @@ -155,183 +155,11 @@ return(i); } -void _ld(); -asm( - ".globl _ld \n" - "_ld: \n" - " call ld \n" - " pop %ecx \n" - " pop %ecx \n" - " push %eax \n" - " ret \n" - ); - -uInt32 ld(uInt32 got2,uInt32 entry) { - int i = 0x0; - int x = 0x0; - int rel = 0x0; - char *shStr = 0x0; - char *dynStr = 0x0; - fileDescriptor *tmpFd = (fileDescriptor *)got2; - elfSectionHeader *sectionHeader = 0x0; - elfDynSym *relSymTab = 0x0; - elfPltInfo *elfRel = 0x0; - elfHeader *binaryHeader = 0x0; - - if (binaryHeader == 0x0) { - fseek(tmpFd,0x0,0x0); - binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); - fread(binaryHeader,sizeof(elfHeader),1,tmpFd); - } - - if (sectionHeader == 0x0) { - sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); - fseek(tmpFd,binaryHeader->eShoff,0); - fread(sectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,tmpFd); - } - if (shStr == 0x0) { - shStr = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); - fseek(tmpFd,sectionHeader[binaryHeader->eShstrndx].shOffset,0); - fread(shStr,sectionHeader[binaryHeader->eShstrndx].shSize,1,tmpFd); - } - - for (i=0x0;ieShnum;i++) { - switch (sectionHeader[i].shType) { - case 3: - if (!kstrcmp((shStr + sectionHeader[i].shName),".dynstr")) { - if (dynStr == 0x0) { - dynStr = (char *)kmalloc(sectionHeader[i].shSize); - fseek(tmpFd,sectionHeader[i].shOffset,0); - fread(dynStr,sectionHeader[i].shSize,1,tmpFd); - } - } - break; - case 9: - rel = i; - break; - case 11: - if (relSymTab == 0x0) { - relSymTab = (elfDynSym *)kmalloc(sectionHeader[i].shSize); - fseek(tmpFd,sectionHeader[i].shOffset,0); - fread(relSymTab,sectionHeader[i].shSize,1,tmpFd); - } - break; - } - } - - if (elfRel == 0x0) { - fseek(tmpFd,sectionHeader[rel].shOffset,0x0); - elfRel = (elfPltInfo *)kmalloc(sectionHeader[rel].shSize); - fread(elfRel,sectionHeader[rel].shSize,1,tmpFd); - } - - i = (entry/sizeof(elfPltInfo)); - x = ELF32_R_SYM(elfRel[i].pltInfo); - i = ldFindFunc(dynStr + relSymTab[x].dynName); - - return(i); - } - -uInt32 ldFindFunc(char *func) { - int i = 0x0; - int x = 0x0; - int rel = 0x0; - int sym = 0x0; - uInt32 *funcPtr = 0x0; - uInt32 *reMap = 0x0; - char *shStr = 0x0; - char *dynStr = 0x0; - char *binary = 0x0; - char *output = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - elfSectionHeader *sectionHeader = 0x0; - elfPltInfo *elfRel = 0x0; - elfDynSym *relSymTab = 0x0; - fileDescriptor *tmpFd = 0x0; - - - //kprintf("Finding Function: [%s]\n",func); - - tmpFd = fopen("libc.so","rb"); - binary = (char *)kmalloc(tmpFd->size); - output = (char *)kmalloc((tmpFd->size+0x4000)); - fread(binary,tmpFd->size,1,tmpFd); - fclose(tmpFd); - - binaryHeader = (elfHeader *)binary; - programHeader = (elfProgramHeader *)(binary + binaryHeader->ePhoff); - sectionHeader = (elfSectionHeader *)(binary + binaryHeader->eShoff); - - shStr = (char *)(binary + sectionHeader[binaryHeader->eShstrndx].shOffset); - - for (i=0;iePhnum;i++) { - switch (programHeader[i].phType) { - case 1: - case 2: - kmemcpy((output+programHeader[i].phVaddr),(binary + programHeader[i].phOffset),programHeader[i].phFilesz); - break; - default: - kprintf("Unhandled Header\n"); - break; - } - } - - for (i=0x0;ieShnum;i++) { - switch (sectionHeader[i].shType) { - case 3: - if (!kstrcmp((shStr + sectionHeader[i].shName),".dynstr")) { - dynStr = (char *)(binary + sectionHeader[i].shOffset); - } - break; - case 9: - rel = i; - break; - case 11: - //kprintf("Dynamic Sym\n"); - relSymTab = (elfDynSym *)(binary + sectionHeader[i].shOffset); - sym = i; - break; - } - } - - elfRel = (elfPltInfo *)(binary + sectionHeader[rel].shOffset); - - for (i=0x0;i