kernel.cpp 整体结构
kernel.cpp内部依赖关系图:
kernel.cpp 一部分方法的详细实现代码
-
Error Kernel::heap(Address base, Size size)
方法
为kernel创建堆空间用来实现动态空间(通过new()和delete()方法),所以必须在任何对象被调用前调用;Error Kernel::heap(Address base, Size size)
{
Allocator *bubble, *pool;
Size meta = sizeof(BubbleAllocator) + sizeof(PoolAllocator);
// Clear the heap first
MemoryBlock::set((void *) base, 0, size);
// Setup the dynamic memory heap
bubble = new (base) BubbleAllocator(base + meta, size - meta);
pool = new (base + sizeof(BubbleAllocator)) PoolAllocator();
pool->setParent(bubble);
// Set default allocator
Allocator::setDefault(pool);
return 0;
}
其中涉及代码:
BubbleAllocator::BubbleAllocator(Address start, Size size)
{
m_start = (u8 *) start;
m_current = (u8 *) start;
m_size = size;
}