linux - Which is the address printed by printf() with a %p format in c? -


i'm having simple code follows:

#include<stdio.h>  int glob;  int main(void) {    int a;    printf("&a : %p \n", &a);    printf("glob : %p \n", &glob);    return 0; } 

output of above program is: first run:

&a : 0x7fff70de91ec glob : 0x6008f4 

second run :

&a : 0x7fff38c4c7ac glob : 0x6008f4 

i'm studying virtual & physical addresses. have following question:

  1. which printed address(physical/virtual) of variable "a"?
  2. if virtual then, how changes in each run of same program? understood compiler provides virtual address variables @ compile time?
  3. why address of global variable constant in each run of program?

in executed program on linux : 2.6.18-308.el5 x86_64 gnu/linux

compiled using : gcc version 4.1.2 20080704 (red hat 4.1.2-52)

addresses seen in program virtual , behaviour described op linux counter-measure avoid buffer overflow attacks.

just try, can disable with

sysctl -w kernel.randomize_va_space=0 

then run again program , watch.

the global 1 in space of memory can't harmful in hackish-wise point of view. that's because not randomized every time.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -