In this occasion I was reading through the Paging chapter. And I found out there was one line I wasn't getting at all.
http://www.jamesmolloy.co.uk/tutorial_h ... aging.html
Code: Select all
When we allocate page tables and directories, they must be page-aligned. So we can build that in:
u32int kmalloc(u32int sz, int align)
{
if (align == 1 && (placement_address & 0xFFFFF000)) // If the address is not already page-aligned
{
// Align it.
placement_address &= 0xFFFFF000;
placement_address += 0x1000;
}
u32int tmp = placement_address;
placement_address += sz;
return tmp;
}
(align == 1 && (placement_address & 0xFFFFF000))
But why placement_address & 0xFFFFF000?
shouldn't it be:
(align == 1 && (placement_address & 0x00000FFF))
so if the placement address is not at the beginning of a 4k page, then we "and" placement_address with 0xFFFFF000 to get it to the beginning and then add 0x1000 to "reserve" the space in the NEXT page?
It may seem like something obvious. But I'm not getting it and I would like to know what is wrong with my logic