I found a bug in the wiki
Posted: Tue Feb 04, 2014 7:09 pm
Hi,
I was trying to write the heap (well, I was trying to port port liballoc), and I found this interesting article that explain how to find a number contiguos pages:
http://wiki.osdev.org/User:Kmcguire/Qui ... Free_Pages
It was an interesting read, but I found 2 issue with that code:
well, 2 of the 3 problem are in this part of the code:
let's assume that the actual address is not in a table, 1024 will be added to cfreepage, but next iteration the same address + 0x1 will not be in a table (ofcourse!) but then another 1024 will be added to cfreepage!!
I fixed it by adding 0x1000 (the size of a pagetable) to x when a balnk table is found... in that way:
Another problem is that if there isn't an valid pagetable in the search range, the function will not return a valid starting address..
I fixed it in that way:
Ok, what do you think about ? are those fixes valid and stables ?
Thank you very much
EDIT: I found another bug, when you try to find just 1 free page, it magically always find it (even if the given range is full of used pages)
I was trying to write the heap (well, I was trying to port port liballoc), and I found this interesting article that explain how to find a number contiguos pages:
http://wiki.osdev.org/User:Kmcguire/Qui ... Free_Pages
It was an interesting read, but I found 2 issue with that code:
Code: Select all
unsigned int vmm_findfree(unsigned int *vdir, unsigned int count, unsigned int index4mb, unsigned int icount4mb){
unsigned int *table;
unsigned int x;
unsigned int cfreepage = 0;
unsigned int opage = index4mb << 22;
for(x = index4mb; x < (index4mb+icount4mb) ; ++x){
if(vdir[x] != 0){
table = (unsigned int*)(vdir[x] & 0xFFFFF000);
for(y = 0; y < 1024; ++y){
if(table[y] != 0){
++cfreepage;
if(cfreepage >= count){
return opage;
}
}else{
// reset the count
cfreepage = 0;
// this should end up being the first page notice the (y+1) and currently y=y+0.
opage = (x << 22) + ((y+1) << 12);
}
}
}else{
// count completely blank tables
cfreepage += 1024;
}
}
return 0;
}
well, 2 of the 3 problem are in this part of the code:
Code: Select all
}else{
// count completely blank tables
cfreepage += 1024;
}
}
return 0;
}
I fixed it by adding 0x1000 (the size of a pagetable) to x when a balnk table is found... in that way:
Code: Select all
}else{
// count completely blank tables
cfreepage += 1024;
x+=0x1000;
}
}
return 0;
}
I fixed it in that way:
Code: Select all
}else{
// count completely blank tables
cfreepage += 1024;
x+=0x1000;
if(cfreepage >= count){
return opage;
}
Ok, what do you think about ? are those fixes valid and stables ?
Thank you very much
EDIT: I found another bug, when you try to find just 1 free page, it magically always find it (even if the given range is full of used pages)