diff --git a/src/bin/init/main.c b/src/bin/init/main.c index 2777caf..2f571b1 100644 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -39,6 +39,7 @@ mpiMessage_t myMsg; /* Create a mailbox for this task */ + if (mpiCreateMbox("init") != 0x0) { printf("Error: Error Creating Mail Box\n"); exit(-1); @@ -98,6 +99,9 @@ /*** $Log$ + Revision 1.13 2004/07/17 18:16:45 reddawg + Hmm + Revision 1.12 2004/06/28 23:12:59 reddawg file format now container:/path/to/file diff --git a/src/bin/ld/Makefile b/src/bin/ld/Makefile index fbb3395..b52be0a 100644 --- a/src/bin/ld/Makefile +++ b/src/bin/ld/Makefile @@ -23,7 +23,7 @@ # Link The Binary $(OUTPUT) : $(OBJS) $(CC) -nostdlib -shared -Wl,-soname,$(OUTPUT) -e _ld -o $(OUTPUT) $(OBJS) $(LIBRARIES) $(SUBS) - strip $(OUTPUT) +# strip $(OUTPUT) # Compile the source files .cpp.o: diff --git a/src/bin/ld/addlibrary.c b/src/bin/ld/addlibrary.c index e3c4487..b75f814 100644 --- a/src/bin/ld/addlibrary.c +++ b/src/bin/ld/addlibrary.c @@ -11,7 +11,10 @@ FILE *linkerFd = 0x0; ldLibrary *tmpLib = 0x0; - tmpLib = (ldLibrary *)malloc(sizeof(ldLibrary)); + if ((tmpLib = (ldLibrary *)malloc(sizeof(ldLibrary))) == 0x0) { + printf("malloc failed: tmpLib\n"); + exit(0x1); + } if (tmpLib->output == 0x0) { linkerFd = fopen(lib,"rb"); @@ -19,18 +22,27 @@ printf("Could not open library: %s\n",lib); exit(-1); } - tmpLib->output = (char *)malloc((linkerFd->size+0x4000)); + if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) { + printf("malloc failed: tmpLib->output\n"); + exit(0x1); + } sprintf(tmpLib->name,lib); } if (tmpLib->linkerHeader == 0x0) { fseek(linkerFd,0x0,0x0); - tmpLib->linkerHeader = (elfHeader *)malloc(sizeof(elfHeader)); + if ((tmpLib->linkerHeader = (elfHeader *)malloc(sizeof(elfHeader))) == 0x0) { + printf("malloc failed: tmpLib->linkerHeader\n"); + exit(0x1); + } fread(tmpLib->linkerHeader,sizeof(elfHeader),1,linkerFd); } if (tmpLib->linkerProgramHeader == 0x0) { - tmpLib->linkerProgramHeader = (elfProgramHeader *)malloc(sizeof(elfProgramHeader)*tmpLib->linkerHeader->ePhnum); + if ((tmpLib->linkerProgramHeader = (elfProgramHeader *)malloc(sizeof(elfProgramHeader)*tmpLib->linkerHeader->ePhnum)) == 0x0) { + printf("malloc failed: tmpLib->linkerProgramHeader\n"); + exit(0x1); + } fseek(linkerFd,tmpLib->linkerHeader->ePhoff,0); fread(tmpLib->linkerProgramHeader,sizeof(elfProgramHeader),tmpLib->linkerHeader->ePhnum,linkerFd); @@ -50,7 +62,10 @@ } if (tmpLib->linkerSectionHeader == 0x0) { - tmpLib->linkerSectionHeader = (elfSectionHeader *)malloc(sizeof(elfSectionHeader)*tmpLib->linkerHeader->eShnum); + if ((tmpLib->linkerSectionHeader = (elfSectionHeader *)malloc(sizeof(elfSectionHeader)*tmpLib->linkerHeader->eShnum)) == 0x0) { + printf("malloc failed: tmpLib->linkerSectionHeader\n"); + exit(0x1); + } fseek(linkerFd,tmpLib->linkerHeader->eShoff,0); fread(tmpLib->linkerSectionHeader,sizeof(elfSectionHeader),tmpLib->linkerHeader->eShnum,linkerFd); @@ -65,14 +80,20 @@ case 3: if (!strcmp((tmpLib->linkerShStr + tmpLib->linkerSectionHeader[i].shName),".dynstr")) { if (tmpLib->linkerDynStr == 0x0) { - tmpLib->linkerDynStr = (char *)malloc(tmpLib->linkerSectionHeader[i].shSize); + if ((tmpLib->linkerDynStr = (char *)malloc(tmpLib->linkerSectionHeader[i].shSize)) == 0x0) { + printf("malloc failed: tmpLib->linkerDynStr\n"); + exit(0x1); + } fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0); fread(tmpLib->linkerDynStr,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); } } break; case 9: - tmpLib->linkerElfRel = (elfPltInfo *)malloc(tmpLib->linkerSectionHeader[i].shSize); + if ((tmpLib->linkerElfRel = (elfPltInfo *)malloc(tmpLib->linkerSectionHeader[i].shSize)) == 0x0) { + printf("malloc failed: tmpLib->linkerElfRel\n"); + exit(0x1); + } fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0x0); fread(tmpLib->linkerElfRel,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); @@ -106,9 +127,10 @@ break; } } - } + } - libs->prev = tmpLib; + if (libs != 0x0) + libs->prev = tmpLib; tmpLib->prev = 0x0; tmpLib->next = libs; libs = tmpLib; diff --git a/src/bin/login/Makefile b/src/bin/login/Makefile index 205f68f..4e87ee3 100644 --- a/src/bin/login/Makefile +++ b/src/bin/login/Makefile @@ -25,7 +25,7 @@ # Link The Binary $(BINARY) : $(OBJS) $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) - strip $(BINARY) +# strip $(BINARY) # Compile the source files .cpp.o: diff --git a/src/bin/login/main.c b/src/bin/login/main.c index 6a5de0a..f466e01 100644 --- a/src/bin/login/main.c +++ b/src/bin/login/main.c @@ -63,11 +63,15 @@ char passWord[32]; char *data2 = 0x0; struct passwd *data = 0x0; + if ((getuid() != 0) && (getgid() != 0)) { printf("This Application Must Be Run As Root.\n"); exit(-1); } - data = (struct passwd *)malloc(4096); + if ((data = (struct passwd *)malloc(4096)) == 0x0) { + printf("Malloc Failed\n"); + exit(0x1); + } printf("Starting Login Daemon\n"); @@ -81,7 +85,10 @@ fread(data,4096,1,fd); fclose(fd); } - data2 = (char *)malloc(384); + if ((data2 = (char *)malloc(384)) == 0x0) { + printf("Malloc Failed\n"); + exit(0x1); + } login: printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)"); printf("\n\nLogin: "); @@ -92,7 +99,7 @@ if (0x0 == strcmp(userName,data[i].username)) { if (0x0 == strcmp(passWord,data[i].password)) { shellPid = fork(); - if (!shellPid) { + if (shellPid == 0x0) { if (setuid(data[i].uid) != 0x0) { printf("Set UID Failed\n"); } diff --git a/src/lib/libc_old/stdlib/malloc.c b/src/lib/libc_old/stdlib/malloc.c index 0e384a7..3e8c943 100644 --- a/src/lib/libc_old/stdlib/malloc.c +++ b/src/lib/libc_old/stdlib/malloc.c @@ -36,65 +36,58 @@ struct memDescriptor *next; //4 void *baseAddr; //4 uInt32 limit; //4 - uInt8 status; //1 - char reserved[11]; //11 }; + +#define MALLOC_ALIGN_SIZE 32 +#define MALLOC_ALIGN(size) (size + ((((size) % MALLOC_ALIGN_SIZE) == 0)? 0 : (MALLOC_ALIGN_SIZE - ((size) % MALLOC_ALIGN_SIZE)))) -static void insertFreeDesc(struct memDescriptor *freeDesc); +static int insertFreeDesc(struct memDescriptor *freeDesc); -static struct memDescriptor *kernDesc = 0x0; +static struct memDescriptor *usedKernDesc = 0x0; static struct memDescriptor *freeKernDesc = 0x0; static struct memDescriptor *emptyKernDesc = 0x0; -static int mallocLock = 0x0; +static void *getEmptyDesc() { + int i = 0x0; + struct memDescriptor *tmpDesc = 0x0; -void initMalloc() { - int i=0; - struct memDescriptor *tmpDesc1 = 0x0; - struct memDescriptor *tmpDesc2 = 0x0; - emptyKernDesc = (struct memDescriptor *)getPage(4); - tmpDesc1 = emptyKernDesc; - tmpDesc1->prev = 0x0; - tmpDesc1->status = 0x0; - tmpDesc1->limit = 0x0; - for (i=1;i<((4096/sizeof(struct memDescriptor))*4);i++) { - tmpDesc2 = &emptyKernDesc[i]; - tmpDesc2->prev = tmpDesc1; - tmpDesc1->next = tmpDesc2; - tmpDesc2->status = 0x0; - tmpDesc2->limit = 0x0; - tmpDesc1 = tmpDesc2; - } - tmpDesc1->next = 0x0; - //Return - return; - } - -/************************************************************************ - -Function: void *getEmptyDesc() -Description: Find An Empty Descriptor - -Notes: - -02/17/03 - Is This Efficient? - -************************************************************************/ -void *getEmptyDesc() { - struct memDescriptor *tmpDesc = emptyKernDesc; + tmpDesc = emptyKernDesc; + if (tmpDesc != 0x0) { emptyKernDesc = tmpDesc->next; - emptyKernDesc->prev = 0x0; + if (emptyKernDesc != 0x0) + emptyKernDesc->prev = 0x0; + + tmpDesc->next = 0x0; tmpDesc->prev = 0x0; return(tmpDesc); } - return(0x0); + + if ((emptyKernDesc = (struct memDescriptor *)getPage(4)) == 0x0) + + /* zero out the memory so we know there is no garbage */ + memset(emptyKernDesc,0x0,0x4000); + + emptyKernDesc[0].next = &emptyKernDesc[1]; + + for (i = 0x1;i < ((0x4000/sizeof(struct memDescriptor)));i++) { + emptyKernDesc[i].next = &emptyKernDesc[i+1]; + emptyKernDesc[i].prev = &emptyKernDesc[i-1]; + } + + tmpDesc = emptyKernDesc; + + emptyKernDesc = tmpDesc->next; + emptyKernDesc->prev = 0x0; + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + return(tmpDesc); } /************************************************************************ -Function: void *malloc(uInt32 len) +Function: void *kmalloc(uInt32 len) Description: Allocate Kernel Memory Notes: @@ -107,85 +100,85 @@ struct memDescriptor *tmpDesc2 = 0x0; char *buf = 0x0; int i = 0x0; - - if (mallocLock != 0x0) - while (1) asm("nop"); - - mallocLock = 1; - //If Kernel Descriptor Is NULL Initialize Malloc - if (emptyKernDesc == 0x0) { - initMalloc(); - } - len = (len + 15) & 0xFFFFFFF0; + + len = MALLOC_ALIGN(len); + if (len == 0x0) { return(0x0); } - for (tmpDesc1 = freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + for (tmpDesc1 = freeKernDesc;tmpDesc1 != 0x0;tmpDesc1=tmpDesc1->next) { if (tmpDesc1->limit >= len) { - tmpDesc1->status = 0x1; - if (tmpDesc1->prev != 0x0) { + if (tmpDesc1->prev != 0x0) tmpDesc1->prev->next = tmpDesc1->next; + if (tmpDesc1->next != 0x0) tmpDesc1->next->prev = tmpDesc1->prev; - } - else { + + if (tmpDesc1 == freeKernDesc) freeKernDesc = tmpDesc1->next; - freeKernDesc->prev = 0x0; - } + tmpDesc1->prev = 0x0; - tmpDesc1->next = kernDesc; - kernDesc->prev = tmpDesc1; - kernDesc = tmpDesc1; - if (tmpDesc1->limit > (len + 16)) { + tmpDesc1->next = usedKernDesc; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + if (tmpDesc1->limit > (len + 32)) { tmpDesc2 = getEmptyDesc(); tmpDesc2->limit = tmpDesc1->limit - len; tmpDesc1->limit = len; tmpDesc2->baseAddr = tmpDesc1->baseAddr + len; - tmpDesc2->status = 0x0; tmpDesc2->next = 0x0; tmpDesc2->prev = 0x0; + if (tmpDesc2->limit <= 0x0) + //printf("kmalloc-1 tmpDesc2: [%i:%i:%i]\n",tmpDesc2->limit,tmpDesc1->limit,len); insertFreeDesc(tmpDesc2); } - mallocLock = 0x0; buf = (char *)tmpDesc1->baseAddr; for (i=0;ilimit;i++) { (char)buf[i] = (char)0x0; } + + //printf("baseAddr1[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); return(tmpDesc1->baseAddr); } } tmpDesc1 = getEmptyDesc(); + //printf("no empty desc\n"); if (tmpDesc1 != 0x0) { - tmpDesc1->baseAddr = (struct memDescriptor *)getPage(((len + 4095)/4096)); + tmpDesc1->baseAddr = (struct memDescriptor *)getPage((len + 4095)/4096); tmpDesc1->limit = len; - tmpDesc1->status = 0x1; - tmpDesc1->next = kernDesc; + tmpDesc1->next = usedKernDesc; tmpDesc1->prev = 0x0; - kernDesc = tmpDesc1; - kernDesc->next->prev = tmpDesc1; - if ((len-4096) > 0) { + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + + if ((len%0x1000) > 0) { tmpDesc2 = getEmptyDesc(); - tmpDesc2->status = 0x0; tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; tmpDesc2->limit = ((len + 4095)/4096)*4096 - tmpDesc1->limit; tmpDesc2->prev = 0x0; tmpDesc2->next = 0x0; + if (tmpDesc2->limit <= 0x0) + printf("kmalloc-2 tmpDesc2: [%i]\n",tmpDesc2->limit); insertFreeDesc(tmpDesc2); } - mallocLock = 0x0; buf = (char *)tmpDesc1->baseAddr; for (i=0;ilimit;i++) { (char)buf[i] = (char)0x0; } + + //printf("baseAddr2[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); return(tmpDesc1->baseAddr); } //Return Null If Unable To Malloc - mallocLock = 0x0; + + //printf("baseAddr3[0x0]"); return(0x0); } /************************************************************************ -Function: void free(void *baseAddr) +Function: void kfree(void *baseAddr) Description: This Will Find The Descriptor And Free It Notes: @@ -194,47 +187,43 @@ ************************************************************************/ void free(void *baseAddr) { - uInt32 *data = 0x0; - long i = 0x0; struct memDescriptor *tmpDesc1 = 0x0; - struct memDescriptor *tmpDesc2 = 0x0; - while (mallocLock != 0x0) asm("nop"); - mallocLock = 1; - for (tmpDesc1=kernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + for (tmpDesc1 = usedKernDesc;tmpDesc1 != 0x0;tmpDesc1 = tmpDesc1->next) { if (tmpDesc1->baseAddr == baseAddr) { - tmpDesc1->status = 0x0; - if (tmpDesc1->prev != 0x0) { - tmpDesc2 = tmpDesc1->prev; - tmpDesc2->next = tmpDesc1->next; - } - if (tmpDesc1->next != 0x0) { - tmpDesc2 = tmpDesc1->next; - tmpDesc2->prev = tmpDesc1->prev; - } - if (kernDesc == tmpDesc1) { - kernDesc = tmpDesc1->next; - } + + if (usedKernDesc == tmpDesc1) + usedKernDesc = tmpDesc1->next; + + if (tmpDesc1->prev != 0x0) + tmpDesc1->prev->next = tmpDesc1->next; + + if (tmpDesc1->next != 0x0) + tmpDesc1->next->prev = tmpDesc1->prev; + + + tmpDesc1->next = 0x0; tmpDesc1->prev = 0x0; + + if (tmpDesc1->limit <= 0x0) + printf("kfree tmpDesc1: [%i]\n",tmpDesc1->limit); insertFreeDesc(tmpDesc1); - data = (uInt32 *)baseAddr; - for (i=0;i < (tmpDesc1->limit/4);i++) { - data[i] = 0x0; - } + //mergeMemBlocks(); - mallocLock = 0x0; + return; } } - mallocLock = 0x0; + printf("Kernel: Error Freeing Descriptor! [0x%X]\n",(uInt32)baseAddr); + return; } /************************************************************************ -Function: static void insertFreeDesc(struct memDescriptor *freeDesc) +Function: void insertFreeDesc(struct memDescriptor *freeDesc) Description: This Function Inserts A Free Descriptor On The List Which Is Kept In Size Order @@ -244,97 +233,60 @@ "[20:20:59] You should just insert it in order" ************************************************************************/ -static void insertFreeDesc(struct memDescriptor *freeDesc) { - struct memDescriptor *tmpDesc; - freeDesc->status = 0x0; +static int insertFreeDesc(struct memDescriptor *freeDesc) { + struct memDescriptor *tmpDesc = 0x0; + + if (freeDesc->limit <= 0x0) { + printf("Inserting Descriptor with no limit\n"); + while (1); + } + if (freeKernDesc != 0x0) { - for (tmpDesc=freeKernDesc;tmpDesc;tmpDesc=tmpDesc->next) { - if ((freeDesc->limit >= tmpDesc->limit) && (!tmpDesc->next)) { - tmpDesc->next = freeDesc; - freeDesc->prev = tmpDesc; - freeDesc->next = 0x0; - return; + /* + */ + freeDesc->next = freeKernDesc; + freeDesc->prev = 0x0; + freeKernDesc->prev = freeDesc; + freeKernDesc = freeDesc; + /* + */ + /* + for (tmpDesc = freeKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { + if (freeDesc->limit <= tmpDesc->limit) { + freeDesc->prev = tmpDesc->prev; + tmpDesc->prev = freeDesc; + freeDesc->next = tmpDesc; + + if (tmpDesc == freeKernDesc) + freeKernDesc = freeDesc; + return(0x0); } - else if ((freeDesc->limit >= tmpDesc->limit) && (freeDesc->limit <= tmpDesc->next->limit)) { - freeDesc->next = tmpDesc->next; - freeDesc->prev = tmpDesc; - tmpDesc->next->prev = freeDesc; - tmpDesc->next = freeDesc; - return; - } + if (tmpDesc->next == 0x0) { + tmpDesc->next = freeDesc; + freeDesc->prev = tmpDesc; + freeDesc->next = 0x0; + return(0x0); + } } + kpanic("didnt Insert\n"); + */ + return(0x0); } else { freeDesc->prev = 0x0; freeDesc->next = 0x0; freeKernDesc = freeDesc; - return; + return(0x0); } - //sysErr("Error With Freeing Blocks"); - return; - } -/************************************************************************ - -Function: void mergeMemBlocks() -Description: This Function Will Merge Free Blocks And Free Pages - -Notes: - -03/05/03 - We Have A Problem It Seems The First Block Is Limit 0x0 - -************************************************************************/ -void mergeMemBlocks() { - struct memDescriptor *tmpDesc1 = 0x0; - struct memDescriptor *tmpDesc2 = 0x0; - uInt32 baseAddr = 0x0; - - return; - - //Loop The Free Descriptors See If We Can Merge Them - for (tmpDesc1=freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { - /* - Compare The Base Addr With The Other Descriptors If You Find The One - That You Are Looking For Lets Merge Them - */ - if (tmpDesc1->limit != 0x0) { - baseAddr = (uInt32)tmpDesc1->baseAddr + (uInt32)tmpDesc1->limit; - for (tmpDesc2=freeKernDesc;tmpDesc2;tmpDesc2=tmpDesc2->next) { - if ((uInt32)tmpDesc2->baseAddr == baseAddr) { - tmpDesc1->limit += tmpDesc2->limit; - tmpDesc2->baseAddr = 0x0; - tmpDesc2->limit = 0x0; - tmpDesc2->status = 0x0; - if (tmpDesc2->prev) { - tmpDesc2->prev->next = tmpDesc2->next; - } - if (tmpDesc2->next) { - tmpDesc2->next->prev = tmpDesc2->prev; - } - tmpDesc2->prev = 0x0; - tmpDesc2->next = emptyKernDesc; - emptyKernDesc->prev = tmpDesc2; - emptyKernDesc = tmpDesc2; - if (tmpDesc1->prev) { - tmpDesc1->prev->next = tmpDesc1->next; - } - if (tmpDesc1->next) { - tmpDesc1->next->prev = tmpDesc1->prev; - } - tmpDesc1->prev = 0x0; - tmpDesc1->next = 0x0; - insertFreeDesc(tmpDesc1); - tmpDesc1 = freeKernDesc; - break; - } - } - } - } - return; + return(0x1); } /*** $Log$ + Revision 1.4 2004/06/17 14:18:41 reddawg + Fixed some potential problems + Revision 1.3 2004/05/22 02:32:41 reddawg Fixed a typo diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index 65b2c10..8ec31df 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -50,10 +50,10 @@ intFunctionPTR init_tasks[] = { vmm_init, + i8259_init, + idt_init, vitals_init, vfs_init, - i8259_init, - idt_init, sched_init, pit_init, atkbd_init, @@ -71,6 +71,9 @@ /*** $Log$ + Revision 1.22 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + Revision 1.21 2004/07/22 17:32:25 reddawg I broke it hopefully diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 37025e3..b17bdc5 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -88,6 +88,7 @@ kpanic("Error: Initializing System.\n"); } } + if (vfs_mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) { kprintf("Problem Mounting sys Mount Point\n"); } @@ -112,6 +113,9 @@ /*** $Log$ + Revision 1.63 2004/07/27 12:02:01 reddawg + chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much + Revision 1.62 2004/07/23 09:10:06 reddawg ubixfs: cleaned up some functions played with the caching a bit vfs: renamed a bunch of functions diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 6205506..65fb66e 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -296,7 +296,7 @@ tmpFd = fopen(file,"r"); _current->imageFd = tmpFd; - + kprintf("a"); /* If We Dont Find the File Return */ if (tmpFd == 0x0) { kprintf("Couldn't open file %s\n",file); @@ -359,7 +359,8 @@ Settings so it helps us in the future */ for (x=0;x<(programHeader[i].phMemsz+4095);x+=0x1000) { - vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x)); + if ((vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x))) == 0x0) + kpanic("vmmRemapPage failed: exec-2\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); @@ -378,12 +379,16 @@ } } - for (i=0;i<12;i++) { - if (elfDynamicS[i].dynVal == 0x3) { - tmp = (uInt32 *)elfDynamicS[i].dynPtr; - tmp[2] = (uInt32)ldAddr; - tmp[1] = (uInt32)tmpFd; - break; + if (elfDynamicS != 0x0) { + for (i=0;i<12;i++) { + if (elfDynamicS[i].dynVal == 0x3) { + tmp = (uInt32 *)elfDynamicS[i].dynPtr; + if (tmp == 0x0) + kpanic("tmp: NULL\n"); + tmp[2] = (uInt32)ldAddr; + tmp[1] = (uInt32)tmpFd; + break; + } } } @@ -405,6 +410,9 @@ /*** $Log$ + Revision 1.52 2004/07/27 07:27:50 reddawg + chg: I was fooled thought we failed but it was a casting issue + Revision 1.51 2004/07/27 07:25:09 reddawg chg: I should of made it print out stackAddr diff --git a/src/sys/kernel/file.c b/src/sys/kernel/file.c index fe11569..678b0b8 100644 --- a/src/sys/kernel/file.c +++ b/src/sys/kernel/file.c @@ -119,6 +119,7 @@ size_t fwrite(void *ptr,int size,int nmemb,fileDescriptor *fd) { fileDescriptor *tmpFd = 0x0; /* Search For File Descriptor */ + kprintf("HERE?\n"); for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { /* If Found Return Next Char */ if (tmpFd == fd) { @@ -178,7 +179,7 @@ //int size = stackPtr[1]; //userFileDescriptor *userFd = stackPtr[2]; //kprintf("Sys FWrite: [0x%X][0x%X][0x%X]\n",ptr,size,userFd); - if (userFd->fd == 0x0) { + if (userFd == 0x0) { kprintf(ptr); } else { @@ -204,7 +205,7 @@ fileDescriptor *tmpFd = 0x0; asm("sti"); tmpFd = userFd->fd; - if (userFd->fd == 0) { + if (userFd->fd == 0x0) { ptr[0] = (int) getch(); } else { @@ -268,6 +269,9 @@ /*** $Log$ + Revision 1.7 2004/07/05 23:06:32 reddawg + Fixens + Revision 1.6 2004/06/29 00:18:49 reddawg Sub Dirs diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index cea6b73..2ba031c 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -71,6 +71,7 @@ /* Set Up New Tasks Information */ newProcess->tss.eip = eip; sprintf(newProcess->oInfo.cwd,_current->oInfo.cwd); + newProcess->oInfo.vmStart = _current->oInfo.vmStart; newProcess->uid = _current->uid; newProcess->gid = _current->gid; newProcess->tss.back_link = 0x0; @@ -107,6 +108,9 @@ /*** $Log$ + Revision 1.15 2004/07/25 06:04:00 reddawg + Last of my fixes for the morning + Revision 1.14 2004/07/24 20:00:51 reddawg Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. diff --git a/src/sys/kernel/ld.c b/src/sys/kernel/ld.c index 01ae874..cceabfc 100644 --- a/src/sys/kernel/ld.c +++ b/src/sys/kernel/ld.c @@ -89,7 +89,8 @@ Settings so it helps us in the future */ for (x=0;x < ((programHeader[i].phMemsz)+4095);x += 0x1000) { - vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START)); + if ((vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START))) == 0x0) + kpanic("vmmRemapPage: ld\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); } /* Now Load Section To Memory */ @@ -161,6 +162,9 @@ /*** $Log$ + Revision 1.31 2004/07/22 19:32:42 reddawg + absolute path + Revision 1.30 2004/07/21 10:02:09 reddawg devfs: renamed functions device system: renamed functions diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index a83ec87..5d449e6 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -74,7 +74,10 @@ if (tmpDesc != 0x0) { emptyKernDesc = tmpDesc->next; - emptyKernDesc->prev = 0x0; + if (emptyKernDesc != 0x0) + emptyKernDesc->prev = 0x0; + + tmpDesc->next = 0x0; tmpDesc->prev = 0x0; spinUnlock(&emptyDescSpinLock); @@ -263,7 +266,8 @@ tmpDesc1->prev = 0x0; tmpDesc1->next = usedKernDesc; - usedKernDesc->prev = tmpDesc1; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; usedKernDesc = tmpDesc1; if (tmpDesc1->limit > (len + 32)) { tmpDesc2 = getEmptyDesc(); @@ -293,7 +297,8 @@ tmpDesc1->limit = len; tmpDesc1->next = usedKernDesc; tmpDesc1->prev = 0x0; - usedKernDesc->prev = tmpDesc1; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; usedKernDesc = tmpDesc1; if ((len%0x1000) > 0) { @@ -335,10 +340,16 @@ struct memDescriptor *tmpDesc1 = 0x0; spinLock(&mallocSpinLock); + assert(baseAddr); + assert(usedKernDesc); + for (tmpDesc1 = usedKernDesc;tmpDesc1 != 0x0;tmpDesc1 = tmpDesc1->next) { + if (tmpDesc1->baseAddr == baseAddr) { + if (usedKernDesc == tmpDesc1) + usedKernDesc = tmpDesc1->next; if (tmpDesc1->prev != 0x0) tmpDesc1->prev->next = tmpDesc1->next; @@ -346,11 +357,11 @@ if (tmpDesc1->next != 0x0) tmpDesc1->next->prev = tmpDesc1->prev; - if (usedKernDesc == tmpDesc1) - usedKernDesc = tmpDesc1->next; + tmpDesc1->next = 0x0; tmpDesc1->prev = 0x0; + if (tmpDesc1->limit <= 0x0) kprintf("kfree tmpDesc1: [%i]\n",tmpDesc1->limit); insertFreeDesc(tmpDesc1); @@ -367,6 +378,9 @@ /*** $Log$ + Revision 1.19 2004/07/26 19:15:49 reddawg + test code, fixes and the like + Revision 1.18 2004/07/26 16:52:45 reddawg here we go diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index 39180aa..e5b3975 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -65,6 +65,7 @@ struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; /* Set up default vector table for all possible 256 interrupts */ + for (i = 0x0; i < 256; i++) { setVector(intNull, i, dPresent + dInt + dDpl3); } @@ -72,9 +73,9 @@ /* Load the IDT into the system */ asm volatile( "cli \n" - "lidt (%0) \n" /* Load the IDT */ - "pushfl \n" /* Clear the NT flag */ - "andl $0xffffbfff,(%%esp) \n" + "lidt (%0) \n" /* Load the IDT */ + "pushfl \n" /* Clear the NT flag */ + "andl $0xffffbfff,(%%esp) \n" "popfl \n" "sti \n" : @@ -168,6 +169,7 @@ /* Null Intterupt Descriptor */ void intNull() { kprintf("Woot Invalid Interrupt[%i]\n",_current->id); + while (1); endTask(_current->id); schedYield(); } @@ -427,6 +429,9 @@ /*** $Log$ + Revision 1.21 2004/07/25 05:32:58 reddawg + fixed + Revision 1.20 2004/07/24 20:00:51 reddawg Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. diff --git a/src/sys/vmm/getfreepage.c b/src/sys/vmm/getfreepage.c index 5fdbca9..0626887 100644 --- a/src/sys/vmm/getfreepage.c +++ b/src/sys/vmm/getfreepage.c @@ -55,7 +55,8 @@ /* Loop Through The Page Table Find An UnAllocated Page */ if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { /* Map A Physical Page To The Virtual Page */ - vmmRemapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000))); + if ((vmmRemapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)))) == 0x0) + kpanic("vmmRemapPage: vmmGetFreePage\n"); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); /* Return The Address Of The Newly Allocate Page */ @@ -69,6 +70,9 @@ /*** $Log$ + Revision 1.3 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + Revision 1.2 2004/07/20 22:29:55 reddawg assert: remade assert diff --git a/src/sys/vmm/getfreevirtualpage.c b/src/sys/vmm/getfreevirtualpage.c index 0dfb4d3..02a99cd 100644 --- a/src/sys/vmm/getfreevirtualpage.c +++ b/src/sys/vmm/getfreevirtualpage.c @@ -1,36 +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. - - $Log$ - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.10 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - + 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$ @@ -63,6 +54,8 @@ pageDir = (uInt32 *) parentPageDirAddr; /* Lets Search For A Free Page */ + if (_current->oInfo.vmStart <= 0x100000) + kpanic("Invalid vmStart\n"); for (x = (_current->oInfo.vmStart / (1024 * 4096)); x < 1024; x++) { /* Set Page Table Address */ if ((pageDir[x] & pagePresent) != pagePresent) { @@ -96,7 +89,8 @@ } if (c != -1) { for (c = 0; c < count; c++) { - vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096))); + if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)))) == 0x0) + kpanic("vmmRemapPage: getFreeVirtualPage-1: [0x%X]\n",((x * (1024 * 4096)) + ((y + c) * 4096))); vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); } spinUnlock(&fvpSpinLock); @@ -109,7 +103,8 @@ * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) * ,pid); */ - vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096))); + if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)))) == 0x0) + kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); /* Return The Address Of The Newly Allocate Page */ @@ -125,6 +120,16 @@ } /*** + $Log$ + Revision 1.2 2004/07/24 23:21:25 reddawg + ok last of my commits for the night I'm going to bed + + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + + Revision 1.10 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + END ***/ diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index e308909..daeac0e 100644 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -202,7 +202,8 @@ vmmMemoryMap[i].status = memNotavail; vmmMemoryMap[i].pid = pid; freePages--; - systemVitals->freePages = freePages; + if (systemVitals) + systemVitals->freePages = freePages; spinUnlock(&vmmSpinLock); return (vmmMemoryMap[i].pageAddr); } @@ -331,6 +332,9 @@ /*** $Log$ + Revision 1.10 2004/07/26 19:15:49 reddawg + test code, fixes and the like + Revision 1.9 2004/07/24 23:04:44 reddawg Changes... mark let me know if you fault at pid 185 when you type stress diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index 6eb536c..23667ad 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -56,8 +56,10 @@ pageDir = (uInt32 *)parentPageDirAddr; - if (memAddr == 0x0) + if (memAddr == 0x0) { + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X]\n",memAddr,_current->tss.esp,_current->id,eip); kpanic("Error We Wrote To 0x0\n"); + } //Calculate The Page Directory Index pageDirectoryIndex = (memAddr >> 22); @@ -91,7 +93,9 @@ vmmUnmapPage((uInt32)dst,1); } else if (pageTable[pageTableIndex] != 0x0) { - kprintf("pageTable: [0x%X]\n",pageTable[pageTableIndex]); + kprintf("pageTable: [0x%X:0x%X:0x%X:0x%X]\n",pageTable[pageTableIndex],pageTableIndex,pageDirectoryIndex,eip); + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X] Non Mapped\n",memAddr,_current->tss.esp,_current->id,eip); + while (1); } else { spinUnlock(&pageFaultSpinLock); @@ -111,6 +115,9 @@ /*** $Log$ + Revision 1.8 2004/07/27 07:09:38 reddawg + Put in a test for 0x0 + Revision 1.7 2004/07/26 19:15:49 reddawg test code, fixes and the like diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index c5827bb..4a7f82f 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -1,4 +1,4 @@ -/***************************************************************************************** + /***************************************************************************************** Copyright (c) 2002-2004 The UbixOS Project All rights reserved. @@ -83,7 +83,7 @@ (uInt32) pageTable[i] = (uInt32) 0x0; } /* Map The First 1MB Of Memory To The Kernel VM Space */ - pageTable[0] = (uInt32) (0x0 | pagePresent | pageWrite | pageUser); + /* pageTable[0] = (uInt32) (0x0 | pagePresent | pageUser); */ for (i = 1; i < (pageEntries / 4); i++) { pageTable[i] = (uInt32) ((i * 0x1000) | pagePresent | pageWrite | pageUser); } @@ -173,7 +173,9 @@ */ pageDir = (uInt32 *) parentPageDirAddr; /* Check To See If Page Table Exists */ - assert(dest); + //assert(dest); + if (dest == 0x0) + return(0x0); /* Get Index Into The Page Directory */ destPageDirectoryIndex = (dest / 0x400000); @@ -248,7 +250,8 @@ } if (c != -1) { for (c = 0; c < count; c++) { - vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096))); + if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)))) == 0x0) + kpanic("vmmRemapPage failed: gfkp-1\n"); vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); } spinUnlock(&fkpSpinLock); @@ -261,7 +264,8 @@ * vmmRemapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*409 * 6)),pid); */ - vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096))); + if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)))) == 0x0) + kpanic("vmmRemapPage failed: gfkp-2\n"); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); /* Return The Address Of The Newly Allocate Page */ @@ -417,6 +421,9 @@ /*** $Log$ + Revision 1.14 2004/07/27 12:02:01 reddawg + chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much + Revision 1.13 2004/07/27 07:15:21 reddawg chg: made page 0x0 writeable should boot now