【发布时间】:2014-01-08 01:15:41
【问题描述】:
所以我在虚拟机上使用 linux 0.11 内核,我需要编写一个程序来分析在该内核上运行的可执行文件。文件格式为 a.out。我想知道的是,操作系统如何决定在(虚拟?)内存中加载文件的位置?它是由所谓的“基地址”决定的吗?如果是这样,我怎么在 a.out 标头中找不到任何提及它的内容?
//where is base address?
struct exec {
unsigned long a_magic; /* Use macros N_MAGIC, etc for access */
unsigned a_text; /* length of text, in bytes */
unsigned a_data; /* length of data, in bytes */
unsigned a_bss; /* length of uninitialized data area for file, in bytes */
unsigned a_syms; /* length of symbol table data in file, in bytes */
unsigned a_entry; /* start address */
unsigned a_trsize; /* length of relocation info for text, in bytes */
unsigned a_drsize; /* length of relocation info for data, in bytes */
};
我尝试查找有关格式的文档,但我找到的唯一信息只是解释了这些字段中的每一个是什么,a_magic 可以具有哪些值等。
我需要知道它,因为程序需要在给定可执行文件中指令的内存地址时打印出文件和行号,并且调试符号仅将其地址作为偏移量(例如,相对于文本部分等)。
另外,出于好奇,我知道在 C 中,“(void*)0”是 NULL,您不能取消引用。那么如何获取内存地址 0 的内容呢?
如您所见,我对linux内核和操作系统的一般知识知之甚少,所以请从基础开始...
感谢您提供的任何帮助,谢谢。
【问题讨论】: