RAM i.e. Random Access Memory, its main work is to store information and provide them when asked for, by the device. RAM is volatile memory and its contents are lost when we switch of computer. The weird part about storage on RAM is that a program in RAM is stored in six main sections; namely
- text section
- data section
- bss section
- heap section
- stack section
- Environment section
It’s not so difficult to understand what each of these section do, each of them have been primarily assigned work.
=> .text section :- This section holds the binary text file of the executive. Any file that you store on your computer, even a notepad file is also stored as a binary file on your hard disk.
=> .data section :- This section deals with variable assigned values in the program of the executive. e.g In C language you might be defining global variable’s. like int a=10; etc.
This section store’s only those value’s which are initialized. The size of this section is fixed during runtime.
=> .bss Section :- The below stack section (.bss) is used to store global noninitialized variables such as:
The size of this section is fixed at runtime.
=> Heap Section :- The heap section is used to store dynamically allocated variables and grows from the lower-addressed memory to the higher-addressed memory. The allocation of memory is controlled through the malloc() and free() functions. For example, to declare an integrands have the memory allocated at runtime, you would use something like:
int i = malloc (sizeof (int));
=> Stack Section :- The stack section is used to keep track of function calls (recursively) and grows from the higher-addressed memory to the lower-addressed memory on most systems. As we will see, the fact that the stack grows in this manner allows the subject of buffer overflows to exist. Local variables exist in the stack section.
=> Environment Section :- The environment/arguments section is used to store a copy of system-level variables that may be required by the process during runtime. For example, among other things, the path, shell name, and hostname are made available to the running process. This section is writable, allowing its use in format string and buffer overflow exploits. Additionally, the command-line arguments are stored in this area. The sections of memory reside in the order presented.
As shown in the image above, the first section is text followed by data, bss, heap, stack, Environment.
Now here heap section and stack section could be of any size, they mostly depend on the data used.The total size of Heap and Stack section is fixed based on the declarations and initializations made in the program of the executive. The size of both vary and they adjust themselves during runtime