OSDev.org
https://forum.osdev.org/

Picking a kernel heap and user space heap
https://forum.osdev.org/viewtopic.php?f=1&t=33106
Page 1 of 1

Author:  zaptor [ Tue Aug 07, 2018 12:42 am ]
Post subject:  Picking a kernel heap and user space heap

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?

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/