Understanding James Molloy kmalloc
Posted: Wed Dec 14, 2011 1:31 pm
First post. I'll cut to the chase.
I've been reading and follow a combination of Bran's and James Molloy's tutorials for kernel development. I'm currently on James Molloy's tutorial for paging. I understand that cr3 needs a physical address to the page table. What I don't understand is how James Molloy's kmalloc accomplishes giving both a physical and virtual address.
A link to the tutorial is here.
The relevant code is here:
Unless I have complete lost it, both *phs and tmp should hold the same value. However, according to the tutorial, tmp is a virtual address and *phs is a physical address.
Can someone explain this to me?
I've been reading and follow a combination of Bran's and James Molloy's tutorials for kernel development. I'm currently on James Molloy's tutorial for paging. I understand that cr3 needs a physical address to the page table. What I don't understand is how James Molloy's kmalloc accomplishes giving both a physical and virtual address.
A link to the tutorial is here.
The relevant code is here:
Code: Select all
u32int kmalloc(u32int sz, int align, u32int *phys)
{
if (align == 1 && (placement_address & 0xFFFFF000)) // If the address is not already page-aligned
{
// Align it.
placement_address &= 0xFFFFF000;
placement_address += 0x1000;
}
if (phys)
{
*phys = placement_address;
}
u32int tmp = placement_address;
placement_address += sz;
return tmp;
}
Can someone explain this to me?