Picking a kernel heap and user space heap

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.
Post Reply
zaptor
Posts: 10
Joined: Wed Aug 01, 2018 9:09 pm

Picking a kernel heap and user space heap

Post by zaptor »

I am writing an x86_64 kernel with grub2 as the bootloader. I have paging set up and a simple frame allocator which takes a virtual address and maps it to an available physical frame. I have identity mapped the kernel, the multiboot2 header, VGA address, etc. My question is, how do you choose a place for the kernel heap? e.g. I want a virtual address that starts the heap, such that I can allocate enough frames for the kernel's memory needs.

Currently, I've arbitrarily chosen 0xffff800000000000ull as the kernel heap start (growing down in increasing order) because it is guaranteed not to conflict with any of the identity mapped segments described above. However, the kernel heap needs to be preserved and mapped in the page table for child processes, so now I need to find a suitable virtual address for the children.

What is a sensible way to set up virtual addressing for a heap for both the kernel as well as user space threads/processes?

Another option I was thinking of was using 0xffff8* for all user code (stack, heap, etc) and 0x0000* for all kernel code. And then using 0x00007fffffffffff as the bottom of the kernel heap (growing upward i.e. to decreasing addresses).

Also, what is the best way of setting up page tables for child processes? I need to maintain the identity map of the kernel code, the VGA drivers, etc as well as the kernel heap. What is the easiest way of just cloning these parts of the page tables?
Post Reply