Social Icons

Monday, July 14, 2014



The space where the kernel resides is called as the kernel space and the space. It's the area in the memory where the modules and the subsystems of the kernel resides.


User space is the area in the memory where the applications resides. Each application has its own memory space i.e its own memory space in the RAM.


We call the memory assigned to an address as an address space. There is a term called as the "process address space". Any region assigned to a program is called as the process address region. The particular process address region must contain or comprise of application code.
                                                 Lets get more specific.... What is there inside an .exe file??? When we say ./a.out we are asking the CPU to load the executable object files image into the memory and execute it. Inside the executable image we have functionality and the runtime code. The functionality is the compiled code which we have written in the .C file and runtime is appended into the object file by the Linker. Now tell me does this source file contains only the instruction??? It also contains the data along with the instructions. Data is nothing but the variable we use in our programs for various purposes. These variables can be inside the function or can be outside the function. The variables which are outside the function are called the Global Variables or we can say the Global data.
                                  So, this global data is to be allocated at the compile time. We have an address for each instruction. When the compiler translates the code into the binary instructions, each instruction it will assign an address. Similar to that for every global variable the compiler will assign an address. So, all global data will have a pre-assigned address offsets. Linker will also relocate them. 
                                        Linker decides where the data should be loaded. The Linker also decides where the code should be loaded. Lets think logically for a moment. Inside an executable if there are variable or the data along with the instructions. When the executable is loaded into the memory the data must be loaded into a region which is readable and writable because, there is always a possibility of the variable changing or the data in the variable changing when the program is executing. The code does not change through out the execution. We can summarize it like this........... The data must be loaded into a read/write region and the code must be loaded into a read-only region. The code will only be fetched by the CPU where as the data must be be able to be manipulated during the execution of the program.

                                       Hence for this purpose the memory allocated to the process which is called the process address space is divided into many regions. Each program is given when given an address space for execution of the program in the memory it will be divided into many regions. Each region has its own names. One region is called code and one region is called data. Apart from the above stated address regions there are more two regions. The below image will give you a better idea about the process address space.

In the above image whats referred as the Text segment is called the code region or the code segment and data segment is what we refer as the data region. If you have an idea of the microcontroller programming we will write the data in the data segment and the code in the code segment. The other two regions are called the Stack, Heap and the BSS segment. Each segment or the memory region in the process address space has its own attributes and permissions. 

In the next article we learn about each segments and its purpose.

No comments:

Post a Comment