All of lore.kernel.org
 help / color / mirror / Atom feed
* Newbie doubts about GRUB memory allocation
@ 2020-07-31  5:43 Flávio Alberto
  0 siblings, 0 replies; only message in thread
From: Flávio Alberto @ 2020-07-31  5:43 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]

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}}
(gdb)

Thanks in advance
Flavio Soares

[-- Attachment #2: Type: text/html, Size: 2216 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-31  5:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31  5:43 Newbie doubts about GRUB memory allocation Flávio Alberto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.