When we execute an elf (executable and linkable format) file which is stored in secondary storage, it is brought into the main memory (RAM) by an OS component called Loader. When a program comes into memory, it expands to 64 GB of logical addresses. This expanded region of memory is called Process Context or Virtual Address Space.
OS maintains all information about Process Context into Task Structure. Task structure is a kernel data type and is called “struct task struct” which contains meta data of the process like PID of a process, PPID of a process, state of the process, name of the process, program counter, *mm and *active_mm, etc.
*mm and*active_mm are pointers to the beginning (i.e. starting address) of Process Context.
The process context region is divided into four segments as:
Stack Segment: It is used to store local data i.e., local variables or local temporary variables.
Stack segment constitute a stack which stores the entry of the main function when execution of the main function begins. The main function stores a list of data associated with it and stores in a special data type called “stack frame”. All the local/temporary variables used inside the main function are listed in a stack frame. Every function has its own stack frame.
Libraries segment: It consists of:
Static libraries: These are links to library routines. These routines are loaded into memory at runtime.
Dynamic libraries: These are just links to library routines. These routines are not loaded at runtime. When needed, then these routines will be loaded, executed and then released.
Shared libraries: These are the libraries that are shared among many processes. So, a shared space is created into memory, it is shared with all executing processes in memory.
The shared libraries section contains links to that shared space of memory and further to the needed library.
Data segment: It is used to store global variables, register variables, volatile variables, constants, qualifiers, macros and pre-processor directives.
The data segment includes:
Heap section: It is used to allocate space for dynamically allocated memory. It will expand in accordance with the allocated memory.
Uninitialized data section: It is used for variables of any type but in global space and not initialized with values.
Initialized data section: It is used for variables of any type but in global space and initialized with a value.
Code segment: This segment contains compile code which would be in elf (executable and linkable format).
It looks like you're new here. If you want to get involved, click one of these buttons!