Is this reliable way to detect unused memory by kernel?
Posted: Wed Sep 05, 2018 12:41 pm
I started writing kernel based on Bare Bones tutorial, and currently I am planning how to write basic kernel memory allocator.
In order to write allocator first I must found out which memory regions are free to use.
I am using memory map provided by GRUB to get available memory regions.
Also it is possible that GRUB marks some regions as free, but those same regions overlap with .data, .bss, etc. sections.
My idea was to put symbol at end of the SECTIONS command, to which I will refer in C code, to find out first address not used by kernel.
All memory regions reported by GRUB which are declared as "available" and which are located after all sections should be free?
Researching I found out several basic kernels do this, but is this guaranteed to work.
Also in linker script provided in Bare Bones tutorial at the end of SECTIONS command there is a comment:
In order to write allocator first I must found out which memory regions are free to use.
I am using memory map provided by GRUB to get available memory regions.
Also it is possible that GRUB marks some regions as free, but those same regions overlap with .data, .bss, etc. sections.
My idea was to put symbol at end of the SECTIONS command, to which I will refer in C code, to find out first address not used by kernel.
All memory regions reported by GRUB which are declared as "available" and which are located after all sections should be free?
Researching I found out several basic kernels do this, but is this guaranteed to work.
Also in linker script provided in Bare Bones tutorial at the end of SECTIONS command there is a comment:
So are these sections placed before my symbol, or what?/* The compiler may produce other sections, by default it will put them in
a segment with the same name. Simply add stuff here as needed. */