diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 0e85bb8..918187b 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -120,61 +120,106 @@ *****************************************************************************************/ void execFile(char *file,int argc,char **argv,int console) { - int i=0,x=0,eStart=0; - char *binarySpace = (char *)0x7C0000; - char *newLoc; - fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = (elfHeader *)0x7C0000; - elfProgramheader *programHeader; + int i = 0x0; + int x = 0x0; + uInt32 eStart = 0x0; + char *newLoc = 0x0; + char *linker = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramheader *programHeader = 0x0; /* Get A New Task For This Proccess */ _current = schedNewTask(); _current->gid = 0; _current->uid = 0; + /* Now We Must Create A Virtual Space For This Proccess To Run In */ _current->tss.cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); + /* To Better Load This Application We Will Switch Over To Its VM Space */ asm( "movl %0,%%eax \n" "movl %%eax,%%cr3 \n" : : "d" ((uInt32 *)(_current->tss.cr3)) ); + /* Lets Find The File */ tmpFd = fopen(file,"r"); + /* If We Dont Find the File Return */ if (!tmpFd) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); return; } - /* Now We Must Allocate Memory To Load The Binary Into */ - for (i=0;i<((tmpFd->size+4095)/4096);i++) { - vmmRemapPage(vmmFindFreePage(_current->id),(0x7C0000 + (0x1000 * i))); + if (tmpFd->perms == 0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; } - /* Load The Binary Into Memory Byte For Byte I Should Find A Faster Way */ - fread(binarySpace,tmpFd->size,1,tmpFd); - /* - for (i=0;feof(tmpFd) == 0;i++) { - binarySpace[i] = fgetc(tmpFd); + + /* Load ELF Header */ + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + fread(binaryHeader,sizeof(elfHeader),1,tmpFd); + + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; } - */ - /* Close The File */ - fclose(tmpFd); - /* Set programHeader To Point To Loaded Binary So We Can Gather Info */ - programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + programHeader = (elfProgramheader *)kmalloc(sizeof(elfProgramheader)*binaryHeader->ePhnum); + fseek(tmpFd,binaryHeader->ePhoff,0); + fread(programHeader,(sizeof(elfProgramheader)*binaryHeader->ePhnum),1,tmpFd); + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ for (i=0;iePhnum;i++) { - newLoc = (char *)programHeader[i].phVaddr; - /* - Allocate Memory Im Going To Have To Make This Load Memory With Corrent - Settings so it helps us in the future - */ - for (x=0;x<=((programHeader[i].phMemsz & 0xFFFFF000)+0x1000);x+=0x1000) { - vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x)); + if (programHeader[i].phType == 1) { + newLoc = (char *)programHeader[i].phVaddr; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x=0;x<=((programHeader[i].phMemsz & 0xFFFFF000)+4095);x+=4096) { + vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x)); + } + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); + /* Now Load Section To Memory */ + fseek(tmpFd,programHeader[i].phOffset,0); + fread(newLoc,programHeader[i].phFilesz,1,tmpFd); } - /* Now Copy The Binary To Its Correct Location */ - for (x=0;xoInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); /* Get The Starting Point */ @@ -258,6 +303,10 @@ ); */ + kfree(binaryHeader); + kfree(programHeader); + fclose(tmpFd); + /* Switch Back To The Kernels VM Space */ asm( "movl %0,%%eax \n" @@ -402,6 +451,9 @@ /*** $Log$ + Revision 1.7 2004/05/19 04:31:12 reddawg + Fixed some typedef problems in exec + Revision 1.6 2004/05/19 04:07:42 reddawg kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been