逻辑地址混乱

发布于 2024-08-14 03:25:57 字数 651 浏览 6 评论 0原文

我正在尝试对逻辑地址进行一些分析。下面的程序解释了 我的动机...

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请叫√我孤独 2024-08-21 03:25:57

您最好进一步了解二进制程序如何加载到操作系统中。二进制文件中的不同部分将被加载到不同的页面中。

尝试读取文件 /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.

放赐 2024-08-21 03:25:57

您需要记住两件事。一是您将拥有构成主程序的指令的地址,二是您将拥有正在运行的程序所需的堆栈空间。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文