linux整个内存布局,关于Linux进程内存布局的问题

我正在谈论Intel 32位平台。 Linux内核版本2.6.31-14。关于Linux进程内存布局的问题

#include

#include

int init_global_var = 10; /* Initialized global variable */

int global_var; /* Uninitialized global variable */

static int init_static_var = 20; /* Initialized static variable in global scope */

static int static_var; /* Uninitialized static variable in global scope */

int main(int argc, char **argv, char **envp)

{

static int init_static_local_var = 30; /* Initialized static local variable */

static int static_local_var; /* Uninitialized static local variable */

int init_local_var = 40; /* Initialized local variable */

int local_var; /* Uninitialized local variable */

char *dynamic_var = (char*)malloc(100); /* Dynamic variable */

printf("Address of initialized global variable: %p\n", &init_global_var);

printf("Address of uninitialized global variable: %p\n", &global_var);

printf("Address of initialized static variable in global scope: %p\n", &init_static_var);

printf("Address of uninitialized static variable in global scope: %p\n", &static_var);

printf("Address of initialized static variable in local scope: %p\n", &init_static_local_var);

printf("Address of uninitialized static variable in local scope: %p\n", &static_local_var);

printf("Address of initialized local variable: %p\n", &init_local_var);

printf("Address of uninitialized local variable: %p\n", &local_var);

printf("Address of function (code): %p\n", &main);

printf("Address of dynamic variable: %p\n", dynamic_var);

printf("Address of environment variable: %p\n", &envp[0]);

char* p=0x0;

printf("%s\n",p);

exit(0);

}

输出:

[email protected] ~> ./a.out

Address of initialized global variable: 0x804a020

Address of uninitialized global variable: 0x804a03c

Address of initialized static variable in global scope: 0x804a024

Address of uninitialized static variable in global scope: 0x804a034

Address of initialized static variable in local scope: 0x804a028

Address of uninitialized static variable in local scope: 0x804a038

Address of initialized local variable: 0xbfc11cbc

Address of uninitialized local variable: 0xbfc11cb8

Address of function (code): 0x8048484

Address of dynamic variable: 0x8223008

Address of environment variable: 0xbfc11d7c

fish: Job 1, “./a.out” terminated by signal SIGSEGV (Address boundary error)

在上面的代码中,我有以下混淆。 为什么代码位于0x8048484而不是虚拟内存的开始附近,比如0x00000400?据我所知,布局应该是这样的:

内存不足.............................. .......... HighMemory

Text Data BSS Heap.....................Stack Env

因此,文本应不会说谎到目前为止下来的记忆。它应该接近较低的内存,不是吗?

2011-07-06

pflz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值