Results 1 to 4 of 4
I'm a Computer Science undergraduate student, and as part of my final year project I need to write a program that is able to access its own virtual memory map. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-17-2005 #1Just Joined!
- Join Date
- Apr 2005
- Posts
- 21
A Process Viewing Its Own /proc/<PID>/map Information
I'm a Computer Science undergraduate student, and as part of my final year project I need to write a program that is able to access its own virtual memory map. I'll need to know which region is the heap, which region is the stack etc. Thanks in advance!
- 02-07-2006 #2Just Joined!
- Join Date
- Apr 2005
- Location
- Romania
- Posts
- 42
#include <string.h>
extern int etext, edata, end;
int main()
{
printf("etext address ": %x \n", &etext);
printf("edata address": %x \n", &edata);
printf("end address": %x \n", &end);
return 0;
}
-----------
etext - text segment
edata - initialized data
end - uninitialized data
Memory allocation routines (new, malloc, calloc) make use of the system calls brk and sbrk to extend the size of the data segment.
-----------
Gathering Information from /proc
# cat /proc/<PID>/maps | cut -f1 -d' '
- 02-16-2006 #3Just Joined!
- Join Date
- Jan 2006
- Location
- India
- Posts
- 52
Hi cbogdan,
It's interesting. Will you please explain me or suggest me where are those variables ( etext, edata etc...) are defined?
I guess they are defined in the C library.
And also how did these variables get the process's virtual addresses. I mean who will assign the virtual addresses to these variables,
Thanks in advance..
rajesh
- 02-16-2006 #4Just Joined!
- Join Date
- Apr 2005
- Location
- Romania
- Posts
- 42
Hi rajeshk
The virtual addresses associated with each process segment can be obtained by referencing the external variables etext, edata, and end. The addresses of etext, edata and end correspond to the first valid address above the text, initialized data, and uninitialized data segments.
From END's man page: "In ANSI C the symbols end, edata, and etext are elements of the space of names reserved for the user. Thus, by default these symbols are not defined by the loader. If, however, a reference to end, edata, or etext is unsatisfied during the link, it will be defined by the loader."


Reply With Quote
