[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie doubts about GRUB memory allocation

From: Flávio Alberto
Subject: Newbie doubts about GRUB memory allocation
Date: Fri, 31 Jul 2020 02:43:04 -0300

Hello all,
I`m a newbie in grub code (reasonably experienced as user) and excuse-me if this isn´t the correct list to ask this question. 
I´m studying the GRUB allocation code because I want to write a module that finds the greatest (or a list of) free memory chunk on machine memory to write data on this/these found memory areas. During this proceeding I´m not allocating any memory to avoid change and corrupt GRUB memory management structures.

To do this I'm write a module using grub_machine_mmap_iterate() function to send to my callback the memory region and looking at the start of this region for a existence of a  grub_mm_region_t structure and iterating in first pointer structure field to find these free memory until find the next that points to first element.

My doubts are if the "first" pointer field points to a list of free areas or used areas, and if this area is free space can I write on these spaces respecting the sizes without destroying any GRUB data ? 

For example, doing a manual analysis using gdb + X86 guest QEMU with 768MB of RAM I noticed that in 0x100010 there's an area with  0x2fbaceb bytes, can I write on this space ? 
If I follow the next pointer of  grub_mm_header_t I'll find the others machine free memory area ?

(gdb) p/x *(grub_mm_region_t)0x100000
$14 = {first = 0x2fcbcf90, next = 0x0, pre_size = 0x0, size = 0x2fedfff0}
(gdb) p/x *(grub_mm_header_t)0x2fcbcf90
$15 = {next = 0x2fcb4ed0, size = 0x4, magic = 0x2d3c2808, padding = {0x0, 0x0, 0x0, 0x0}}
(gdb) p/x *(grub_mm_header_t)0x2fcb4ed0
$16 = {next = 0x100010, size = 0x801, magic = 0x2d3c2808, padding = {0x0, 0x0, 0x0, 0x0}}
(gdb) p/x *(grub_mm_header_t)0x100010
$17 = {next = 0x2ffda8d0, size = 0x2fbaceb, magic = 0x2d3c2808, padding = {0xf3, 0xa4, 0xbe, 0x25}}
(gdb) p/x *(grub_mm_header_t)0x2ffda8d0
$18 = {next = 0x2ffda750, size = 0x1b, magic = 0x2d3c2808, padding = {0x0, 0x0, 0x0, 0x0}}

Thanks in advance
Flavio Soares

reply via email to

[Prev in Thread] Current Thread [Next in Thread]