逻辑地址混乱
我正在尝试对逻辑地址进行一些分析。下面的程序解释了 我的动机...
#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;
}
当我在 32 位系统中运行这个程序时,它表明
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
我希望将逻辑地址与页面大小相关联。 我的意思是说这个逻辑地址是如何创建的(就偏移量、页面、数据而言)
对于这个程序大小是 1257 字节,但我认为整个页面将被加载(如果我错了,请纠正我)有什么办法我可以确保加载整个页面或仅加载 1257 字节 加载。
我希望我的问题很清楚,如有任何差异,请告诉我。谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好进一步了解二进制程序如何加载到操作系统中。二进制文件中的不同部分将被加载到不同的页面中。
尝试读取文件 /proc/[proc-id]/maps,您将获得有关此类问题的更多想法。
另外学习 ELF 格式也有帮助。
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.
您需要记住两件事。一是您将拥有构成主程序的指令的地址,二是您将拥有正在运行的程序所需的堆栈空间。 main 的地址位于指令空间中,而 x 的地址实际上位于堆栈中。
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.