I can say for myself that I'm quite good at programming, but when writing an operating system you sometimes have to program in a different way than programming somewhere in the userspace where all the dirty work is done for you with libs and the operating system itself.
I've been coding my kmalloc() last night and I did some very ugly pointer casting mess, I think.
Only one example:
I've got the following global, static variable in my file which hold the current end of my heap, to see wether a the heap needs a new frame mapped into the address space or not:
Code: Select all
static uint8_t* kheap_current_end = (void*)KHEAP_START;
If I want to edit this on a specific location, I need to do such a cast:
Code: Select all
struct mem_info *newBlock = (struct mem_info *)(kheap_start);
Now I allocated some bytes, splitted up the linked list, created a new item for it and I want to know if I need to allocate a new frame and map it to the end of the heap to store the new linked list item.
I need to do such an ugly casting mess to check this:
Code: Select all
if((uint32_t)newBlock + sizeof(struct mem_info) > (uint32_t)kheap_current_end) expandKheap();
Is this really neccessary?