Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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;
}
Accompanied with the description:
kmalloc will return a virtual address. But, we also (bear with me, you'll be glad we did later) need to get the physical address of the memory allocated.
quadrant wrote:It seems to me that the virtual address returned is the same as the physical address shared. So why make the distinction?
To be "perfect", a tutorial needs to be simple enough for beginners to learn from but also needs to be complex enough to cover all useful information. These requirements are mutually exclusive (it's impossible for a tutorial to be simple enough and complex enough at the same time) and therefore tutorials must be "bad" in some way; so almost all tutorials aim to be simple enough (and therefore deliberately fail to cover anything complex enough to be useful in practice).
The distinction is made because in a (more complex) real operating system the virtual address would be different to the physical address.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.