views:

70

answers:

2

Hi, I am trying to do some analysis with the logical address. The following program explains my motive ...

#include<stdio.h>

int main()
{
int x=10;
printf("The address of main is %p\n",&main);
printf("The address of x is %p\n",&x);

return 0;
}

When I run this program in my 32bit system it shows

The address of main is 0x80483b4
The address of x is 0xbfe3b1e0

size page_size
text    data     bss     dec     hex filename
 993     260       4    1257     4e9 page_size

getconf PAGESIZE
4096

I wish to relate the logical address to the page size.. I mean to say how this logical address creates (in terms of offset,page,data)

For this program size is 1257 bytes but i think whole page will get loaded (correct me if I am wrong) is there any way that I can be sure that whole page get loaded or only 1257bytes get loaded.

I hope my question is clear in case any discrepancy please let me know. Thanks

A: 

You'd better learn more about how a binary program is loaded into operating system. Different sections in binary will be loaded into different pages.

Try read file /proc/[proc-id]/maps, you will get more ideas about such problem.

Also learn the ELF format helps too.

arsane
A: 

There are two things that you need to keep in mind. One is that you'll have the address of the instructions that make up your main and second you'll have your stack space that is needed for the running program. The address of main will be in the instruction space and the address of x is actually on the stack.

m00nd4wg