Page 1 of 1
Are variables put in RAM?
Posted: Sat Sep 08, 2012 12:21 am
by CocaCola
Hello everybody.
I know about the "address space" and how not every address belongs to RAM.
I also know that GRUB can prepare a memory map to show what is RAM, and what isn't.
My question is: all the global variables, and the local variables, and the constants, will they be stored in RAM?
And if so, will following GRUB's memory map make me overwrite them?
Then how can I discern which area is safe to use and which isn't?
Re: Are variables put in RAM?
Posted: Sat Sep 08, 2012 12:43 am
by gravaera
Yo:
Your kernel executable image is "built" by a series of programs which assemble it into a file of organized data and code. A bootloader loads this file into memory and passes execution control to it. The file has information on your "variables" and their offsets within the kernel image.
For more information, consider writing some basic programs and analysing them using programs like objdump. You might also want to consider other hobbies, depending on how much time you really have to spend in this field
--Peace out,
gravaera
Re: Are variables put in RAM?
Posted: Sat Sep 08, 2012 2:26 am
by CocaCola
gravaera wrote:The file has information on your "variables" and their offsets within the kernel image.
Could you elaborate, please? (Or link to a relevant Wiki article.)
My main concern is that I can overwrite RAM that is used by variables.
gravaera wrote:For more information, consider writing some basic programs and analysing them using programs like objdump.
I'll try that, thanks.
Re: Are variables put in RAM?
Posted: Sat Sep 08, 2012 2:29 am
by JamesM
CocaCola wrote:gravaera wrote:The file has information on your "variables" and their offsets within the kernel image.
Could you elaborate, please? (Or link to a relevant Wiki article.)
My main concern is that I can overwrite RAM that is used by variables.
gravaera wrote:For more information, consider writing some basic programs and analysing them using programs like objdump.
I'll try that, thanks.
Hi,
You've exposed a gap in your knowledge at an alarmingly basic level. I suggest you try something more basic to get the hang of how a computer program actually works, before trying operating system development.
Cheers,
James
Re: Are variables put in RAM?
Posted: Sat Sep 08, 2012 3:53 am
by CocaCola
I've seen that objdump can show the sections of a program and their contents.
And that's useful. But it still doesn't answer my question: how can I be sure I don't overwrite memory in use?
When the kernel image is loaded onto memory, does the GRUB memory map mark it as "reserved"?
Re: Are variables put in RAM?
Posted: Sat Sep 08, 2012 6:25 am
by Brendan
Hi,
CocaCola wrote:When the kernel image is loaded onto memory, does the GRUB memory map mark it as "reserved"?
No. Sadly the memory map provided by GRUB only says what the firmware told GRUB, and doesn't include areas that GRUB has used for your kernel or extra modules or the multiboot information; and because of this it's a pain in the neck to avoid trashing important things during early initialisation code (especially if you comply with the multi-boot specification and don't make "GRUB specific" assumptions about where things like the multiboot information or extra modules may have been left).
The normal work-around for this is to reserve space in your ".bss" for anything you may need during early initialisation (space you can use safely before you've got your own physical memory management working).
Cheers,
Brendan
Re: Are variables put in RAM?
Posted: Sat Sep 08, 2012 11:01 am
by CocaCola