Hi guys.
I'm trying to figure out the following for each variable In a program:
1. the runtime stack, including the stack base and the direction of stack growth;
2. the dynamic data area (the heap);
3. the static data area, including the initialized and uninitialized data segments (objects with fixed addresses);
4. the text area (the program instructions).
based on the address I get for a UNIX system.
I realize for every different OS it will have a different addressing scheme.
Here is an example, from the following program:
Code:
#include <stdio.h> /* for printf() */
#include <stdlib.h> /* for malloc(), putenv(), setenv() */
#include <string.h> /* for strlen() */
#include <math.h> /* for sqrt() */
#include "pr4.h" /* for macros show...() */
/*----------------------------------------------------------------------*/
/* These should be at various locations in the address space. */
int global_var_1, global_var_2;
// etc.
/*----------------------------------------------------------------------*/
int main(int argc, char *argv[], char *envp[])
{
/* local and global variables */
int local_main_var_1, local_main_var_2;
// etc.
show_int(global_var_1);
show_int(global_var_2);
show_int(local_main_var_1);
show_int(local_main_var_2);
// etc.
return 0;
}
It will output the following:
Code:
demo.sun.32.sorted
00000000ffbffa70 ( 4) local_main_var_1 0
00000000ffbffa6c ( 4) local_main_var_2 -4195516
0000000000020f84 ( 4) global_var_2 0
0000000000020f80 ( 4) global_var_1 0
demo.sun.64.sorted
ffffffff7ffff930 ( 4) local_main_var_1 0
ffffffff7ffff92c ( 4) local_main_var_2 2147482328
0000000100100e68 ( 4) global_var_2 0
0000000100100e64 ( 4) global_var_1 0
Now this is the output from a 64 bit UNIX system and a 32 bit unix system.
As you can see, the local variables that are stored on the stack, both start with:
ffffffff7ffff on the 64 bit system
and on the 32 bit system all the local variables start with a:
ffbffa
I also ran this on a different computer (32 bit) and got the following for local variables:
Code:
00000000ffbff9c0 ( 4) local_main_var_1 0
00000000ffbff9bc ( 4) local_main_var_2 -4195680
So you can see the local variables are starting with ff
And all the global varaibles are starting with numbers, such as 10 or 20
Can I simply match the address to a certain pattern, like if the address starts with a letter "f" then mark that the address is in the stack area, if the address starts with a number (0 through 9) then mark that varaible that it must be in the static area (for global).
It is possible to figure out, I'm just not sure where to even start with this...here is basically what I'm trying to achieve:
Code:
Runtime stack, bottom (stack grows downward)
ffffffff7ffff930 ( 4) local_main_var_1 0
ffffffff7ffff92c ( 4) local_main_var_2 2147482328
Runtime stack, top
Static data area
0000000100100e68 ( 4) global_var_2 0
0000000100100e64 ( 4) global_var_1 0
You can see, its figuring out that global variables, are in the static area, and that the local variables are in the runtime stack, and that also the stack is growing downwards.
So just from the given information what would you recommend I analyze?
Again this is only for a Solaris Unix system, nothing else matters.
Thanks any help would be great.