diff --git a/lab8/inc/allocator.c b/lab8/inc/allocator.c index c9802d4fe..cc85d8ff4 100644 --- a/lab8/inc/allocator.c +++ b/lab8/inc/allocator.c @@ -1,5 +1,6 @@ #include "allocator.h" #include "mmio.h" +#include "error.h" #define debug 0 #if debug #include "uart.h" @@ -25,6 +26,8 @@ int listInsert(List* l,int v){ } int listGet(List* l,int i){ + if((l->beg<=l->end&&(ibeg||i>=l->end))|| + (l->beg>l->end&&(i>=l->end||ibeg)))ERROR("index out of bound!"); int ret=l->data[i]; l->data[i]=l->data[l->beg]; l->beg=(l->beg+1)%(F_NUM+1); @@ -92,6 +95,11 @@ void reclaimFrame(int i){ int p=i; int level=__lg(p); while(frame_table[p^1]>=0){ + //beg will be moved in listGet(), + //so it need to update its bucket position + int beg_id=lists[level].data[lists[level].beg]; + frame_table[beg_id]=frame_table[p^1]; + listGet(&lists[level],frame_table[p^1]); frame_table[p^1]=-1; @@ -129,6 +137,7 @@ int findFrame(int tar_size){ int end=lists[i].end; if(cur_size>=F_SIZE&&cur_size>=tar_size&&beg!=end){ int ret=listGet(&lists[i],beg); + if(frame_table[ret]==-1)ERROR("the frame is being used!"); frame_table[ret]=-1; ret=getFrame(ret,tar_size,cur_size); diff --git a/lab8/inc/thread.c b/lab8/inc/thread.c index 28d07d5f4..dbe5b9882 100644 --- a/lab8/inc/thread.c +++ b/lab8/inc/thread.c @@ -294,7 +294,7 @@ void exit(){ sys_close(i); } } - if(cur->page_table)removePT(cur->page_table,0); + if(cur->page_table!=0)removePT(cur->page_table,0); cur->status|=TASKEXIT; threadSchedule(); @@ -379,7 +379,11 @@ void threadTest(){ threadCreate(foo); idle(); + + //no task anymore ffree((unsigned long)cur); + rq.beg=rq.end=0; + task_cnter=0; } void foo1(){ diff --git a/lab8/makefile b/lab8/makefile index a8b568a12..5360b158b 100644 --- a/lab8/makefile +++ b/lab8/makefile @@ -23,7 +23,7 @@ start.o:start.S run: make all - qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial stdio -drive if=sd,file=./archive/sdcard/sfn_nctuos.img,format=raw #-d int + qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial stdio -drive if=sd,file=./archive/sdcard/sfn_nctuos.img,format=raw #-d in_asm #qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial pty -initrd ./archive/initramfs.cpio #qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial pty -initrd ./archive/initramfs.cpio -d int