查找数据段的地址范围 [英] Finding the address range of the data segment
本文介绍了查找数据段的地址范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为一个编程练习,我正在用 C 编写一个标记和清除垃圾收集器.我希望扫描数据段(全局变量等)以获取指向已分配内存的指针,但我不知道如何获取该段的地址范围.我怎么能这样做?
As a programming exercise, I am writing a mark-and-sweep garbage collector in C. I wish to scan the data segment (globals, etc.) for pointers to allocated memory, but I don't know how to get the range of the addresses of this segment. How could I do this?
推荐答案
Linux(和其他 unix)的文本(程序代码)和数据边界:
The bounds for text (program code) and data for linux (and other unixes):
#include <stdio.h>
#include <stdlib.h>
/* these are in no header file, and on some
systems they have a _ prepended
These symbols have to be typed to keep the compiler happy
Also check out brk() and sbrk() for information
about heap */
extern char etext, edata, end;
int
main(int argc, char **argv)
{
printf("First address beyond:
");
printf(" program text segment(etext) %10p
", &etext);
printf(" initialized data segment(edata) %10p
", &edata);
printf(" uninitialized data segment (end) %10p
", &end);
return EXIT_SUCCESS;
}
这些符号的来源:符号 etext ,edata 在哪里和结束定义?
这篇关于查找数据段的地址范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文