[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: why my program segmentation fault?



Star Liu 写道:
I wrote a program to copy the memory content of FFFF0000-FFFFFFFF to a
file, but it says "Segmentation fault", (i use AMD64 lenny, so the
address is long), how could i fix it? thanks!

#include <string.h>
#include <stdio.h>


void CopyMemoryToFile(char* FilePath, long StartAddress, long OffSet)
{
	FILE* Memory;
	Memory=fopen (FilePath, "w");
	if(Memory!=NULL)
	{
		void* Start;
		Start=StartAddress;
        fwrite(Start, 1, OffSet, Memory);
    }
	fclose(Memory);

}
int main (void)
{
	CopyMemoryToFile("~/cgi-bin_d/Memory",0xFFFF0000,0xFFFF);
	return 0;
}

行了行了,不用讲英文了,你上面说完我就知道你代码要出问题现在一看果然。 Linux引导到内核后就进入虚拟模式,这时候MMC接管了内存访问。你在访问内存的 时候是被映射了的(记不清是GDT,LDT还是什么了,好久前的东西啊..),这时候访问 0xFFFF0000只会报错。 另外,DOS下的内存转换算法是这样.段地址左移8位数学加偏移.你的地址也写错了, DOS下也通不过的.


Reply to: