1. 實驗平臺
OS:ubuntu 10.10
gcc: 4.4.5
machine: i686
program: file.c
// file.c
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile = fopen ("myfile.txt","w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
}
return 0;
}
2. 程序空間
===============0x0
>>>>>>unknown
>>>>>>
>>>>>>
===============0x080481e0 (.text段開始)
......
=============== .data段開始
......
=============== .bss段開始
......
=============== 0x080d12c0 (main函數所在image的末端地址,也是.bss段的結束地址)
>>>>>>unknown
>>>>>>
>>>>>>
=============== 0x08986800 (heap開始)
......
=============== 0x08987800 (heap結束)
>>>>>>unknown
>>>>>>
>>>>>>
=============== 0xb5f88000 (文件使用緩衝區),差不多3G地址
......
=============== (文件使用緩衝區結束)
>>>>>>unknown
>>>>>>
>>>>>>
=============== 0xbf9f1000 (stack結束)
......
=============== 0xbffff3c0 (stack開始:滿足 2^31+2^30 - 0xbffff3c0 < 4k (頁大小) )
......
=============== 0xc0000000 = 2^31 + 2^30 (用戶程序空間開始,內核空間結束)
>>>>>>unknown
>>>>>>
>>>>>>
=============== 0xffffffff (內核空間開始)